|
Pierre-Yves Chibon |
62f012 |
# -*- coding: utf-8 -*-
|
|
Pierre-Yves Chibon |
62f012 |
|
|
Pierre-Yves Chibon |
62f012 |
"""
|
|
Pierre-Yves Chibon |
62f012 |
(c) 2015 - Copyright Red Hat Inc
|
|
Pierre-Yves Chibon |
62f012 |
|
|
Pierre-Yves Chibon |
62f012 |
Authors:
|
|
Pierre-Yves Chibon |
62f012 |
Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
|
|
Pierre-Yves Chibon |
62f012 |
|
|
Pierre-Yves Chibon |
62f012 |
"""
|
|
Pierre-Yves Chibon |
62f012 |
|
|
Pierre-Yves Chibon |
62f012 |
__requires__ = ['SQLAlchemy >= 0.8']
|
|
Pierre-Yves Chibon |
62f012 |
import pkg_resources
|
|
Pierre-Yves Chibon |
62f012 |
|
|
Pierre-Yves Chibon |
62f012 |
import unittest
|
|
Pierre-Yves Chibon |
62f012 |
import shutil
|
|
Pierre-Yves Chibon |
62f012 |
import sys
|
|
Pierre-Yves Chibon |
62f012 |
import os
|
|
Pierre-Yves Chibon |
62f012 |
|
|
Pierre-Yves Chibon |
62f012 |
import json
|
|
Pierre-Yves Chibon |
62f012 |
from mock import patch
|
|
Pierre-Yves Chibon |
62f012 |
|
|
Pierre-Yves Chibon |
62f012 |
sys.path.insert(0, os.path.join(os.path.dirname(
|
|
Pierre-Yves Chibon |
62f012 |
os.path.abspath(__file__)), '..'))
|
|
Pierre-Yves Chibon |
62f012 |
|
|
Pierre-Yves Chibon |
62f012 |
import progit.lib
|
|
Pierre-Yves Chibon |
62f012 |
import tests
|
|
Pierre-Yves Chibon |
62f012 |
|
|
Pierre-Yves Chibon |
62f012 |
|
|
Pierre-Yves Chibon |
62f012 |
class ProgitFlaskApitests(tests.Modeltests):
|
|
Pierre-Yves Chibon |
62f012 |
""" Tests for flask API of progit """
|
|
Pierre-Yves Chibon |
62f012 |
|
|
Pierre-Yves Chibon |
62f012 |
def setUp(self):
|
|
Pierre-Yves Chibon |
62f012 |
""" Set up the environnment, ran before every tests. """
|
|
Pierre-Yves Chibon |
62f012 |
super(ProgitFlaskApitests, self).setUp()
|
|
Pierre-Yves Chibon |
62f012 |
|
|
Pierre-Yves Chibon |
62f012 |
progit.APP.config['TESTING'] = True
|
|
Pierre-Yves Chibon |
62f012 |
progit.SESSION = self.session
|
|
Pierre-Yves Chibon |
62f012 |
progit.api.SESSION = self.session
|
|
Pierre-Yves Chibon |
62f012 |
self.app = progit.APP.test_client()
|
|
Pierre-Yves Chibon |
62f012 |
|
|
Pierre-Yves Chibon |
62f012 |
def test_api_version(self):
|
|
Pierre-Yves Chibon |
62f012 |
""" Test the api_version function. """
|
|
Pierre-Yves Chibon |
62f012 |
|
|
Pierre-Yves Chibon |
62f012 |
output = self.app.get('/api/0/version')
|
|
Pierre-Yves Chibon |
62f012 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
62f012 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
62f012 |
self.assertEqual(data['version'], progit.__api_version__)
|
|
Pierre-Yves Chibon |
62f012 |
self.assertEqual(data.keys(), ['version'])
|
|
Pierre-Yves Chibon |
62f012 |
|
|
Pierre-Yves Chibon |
63ba9d |
def test_api_users(self):
|
|
Pierre-Yves Chibon |
63ba9d |
""" Test the api_users function. """
|
|
Pierre-Yves Chibon |
63ba9d |
|
|
Pierre-Yves Chibon |
63ba9d |
output = self.app.get('/api/0/users')
|
|
Pierre-Yves Chibon |
63ba9d |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
63ba9d |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
63ba9d |
self.assertEqual(data['users'], ['pingou', 'foo'])
|
|
Pierre-Yves Chibon |
63ba9d |
self.assertEqual(data.keys(), ['users'])
|
|
Pierre-Yves Chibon |
63ba9d |
|
|
Pierre-Yves Chibon |
63ba9d |
output = self.app.get('/api/0/users?pattern=p')
|
|
Pierre-Yves Chibon |
63ba9d |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
63ba9d |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
63ba9d |
self.assertEqual(data['users'], ['pingou'])
|
|
Pierre-Yves Chibon |
63ba9d |
self.assertEqual(data.keys(), ['users'])
|
|
Pierre-Yves Chibon |
63ba9d |
|
|
Pierre-Yves Chibon |
62f012 |
|
|
Pierre-Yves Chibon |
62f012 |
if __name__ == '__main__':
|
|
Pierre-Yves Chibon |
62f012 |
SUITE = unittest.TestLoader().loadTestsFromTestCase(ProgitFlaskApitests)
|
|
Pierre-Yves Chibon |
62f012 |
unittest.TextTestRunner(verbosity=2).run(SUITE)
|