diff options
author | thuva4 <tharma.thuva@gmail.com> | 2018-04-17 10:30:27 +0530 |
---|---|---|
committer | thuva4 <tharma.thuva@gmail.com> | 2018-04-26 18:33:20 +0530 |
commit | 69d2a9ff8c3c581595599298ecb759b51df616ef (patch) | |
tree | 317f2e940c4f45af12304a95f428a142085e2f39 /testapi/testapi-client/testapiclient/tests/unit/test_app.py | |
parent | c77cf76cbf31e65aa599f71f33d59abc267b4e50 (diff) |
Add tests to check clientmanager auth function
JIRA: RELENG-379
Change-Id: Ia1b36cabc1b0750f5a9dab8509c1c9b868889e7a
Signed-off-by: thuva4 <tharma.thuva@gmail.com>
Diffstat (limited to 'testapi/testapi-client/testapiclient/tests/unit/test_app.py')
-rw-r--r-- | testapi/testapi-client/testapiclient/tests/unit/test_app.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/testapi/testapi-client/testapiclient/tests/unit/test_app.py b/testapi/testapi-client/testapiclient/tests/unit/test_app.py new file mode 100644 index 0000000..c20b27f --- /dev/null +++ b/testapi/testapi-client/testapiclient/tests/unit/test_app.py @@ -0,0 +1,50 @@ +import urllib + +from mock import mock + +from testapiclient import main +from testapiclient.tests.unit import utils +from testapiclient.tests.unit import fakes + + +class MainTest(utils.TestCommand): + def setUp(self): + super(MainTest, self).setUp() + self.app = main.TestAPIClient() + self.cas_sever = '{}{}{}'.format( + self.env_variables['testapi_cas_auth_url'], + urllib.quote(self.env_variables['testapi_url']), + self.env_variables['testapi_cas_signin_return']) + self.headers = { + 'Content-type': 'application/json', + 'Accept': 'text/plain'} + + def test_auth_success(self): + self.post_mock.return_value = fakes.FakeResponse( + data={'text': "success"}) + self.app.run( + ['-u', 'user', '-p', 'pass', 'pod', 'create', + '{"name": "asfad"}']) + self.post_mock.assert_called_with( + 'http://localhost:8000/api/v1/pods', + data='{"name": "asfad"}', + headers=self.headers) + + def test_auth_failure(self): + self.post_mock.return_value = fakes.FakeResponse( + data={'text': "login"}) + self.app.run( + ['-u', 'user', '-p', 'pass', 'pod', 'create', + '{"name": "asfad"}']) + self.post_mock.assert_called_once_with( + self.cas_sever, + {'pass': 'pass', 'name': 'user', 'form_id': 'user_login'} + ) + + def test_auth_not_called(self): + self.auth_post = mock.patch( + 'testapiclient.utils.clientmanager.ClientManager.auth').start() + self.app.run(['pod', 'get']) + self.auth_post.assert_not_called() + self.get_mock.assert_called_once_with( + 'http://localhost:8000/api/v1/pods', headers=self.headers) |