예제 #1
0
class TestAuthClient(TestCase):
    def setUp(self):
        self.client = AuthClient(host='localhost',
                                 http_port=8000,
                                 ws_port=1337,
                                 version='v1',
                                 token=faker.uuid4(),
                                 reraise=True)

    @httpretty.activate
    def test_get_user(self):
        user = UserConfig('user', '*****@*****.**').to_dict()
        httpretty.register_uri(httpretty.GET,
                               AuthClient._build_url(self.client.base_url,
                                                     AuthClient.ENDPOINT),
                               body=json.dumps(user),
                               content_type='application/json',
                               status=200)

        user_result = self.client.get_user()
        assert user == user_result.to_dict()

    @httpretty.activate
    def test_login(self):
        token = uuid.uuid4().hex
        httpretty.register_uri(httpretty.POST,
                               AuthClient._build_url(self.client.base_url,
                                                     AuthClient.ENDPOINT,
                                                     'token'),
                               body=json.dumps({'token': token}),
                               content_type='application/json',
                               status=200)

        credentials = CredentialsConfig('user', 'password')
        assert token == self.client.login(credentials=credentials)
예제 #2
0
 def setUp(self):
     self.client = AuthClient(host='localhost',
                              http_port=8000,
                              ws_port=1337,
                              version='v1',
                              token=faker.uuid4(),
                              reraise=True)
예제 #3
0
    def test_get_user(self):
        user = UserConfig('user', '*****@*****.**').to_dict()
        httpretty.register_uri(httpretty.GET,
                               AuthClient._build_url(self.client.base_url,
                                                     AuthClient.ENDPOINT),
                               body=json.dumps(user),
                               content_type='application/json',
                               status=200)

        user_result = self.client.get_user()
        assert user == user_result.to_dict()
예제 #4
0
    def test_login(self):
        token = uuid.uuid4().hex
        httpretty.register_uri(httpretty.POST,
                               AuthClient._build_url(self.client.base_url,
                                                     AuthClient.ENDPOINT,
                                                     'token'),
                               body=json.dumps({'token': token}),
                               content_type='application/json',
                               status=200)

        credentials = CredentialsConfig('user', 'password')
        assert token == self.client.login(credentials=credentials)
예제 #5
0
 def auth(self):
     return AuthClient(**self.params)