def test_should_set_requests_module(self, m): """ HTTP Client should set to requests property. """ import requests from qiita.client import Client dummy_response(m, 'data/rate_limit.json') client = Client(requests=requests) result = client.rate_limit() self.assertEqual(result.keys(), ['limit', 'remaining'])
class TestCient(TestCase): @patch('qiita.client.requests.post') def setUp(self, m): from qiita.client import Client dummy_response(m, 'data/auth.json') self.params = settings() self.client = Client(**self.params) @patch('qiita.client.requests.get') def test_rate_limit(self, m): """ Client should get rate limit. """ dummy_response(m, 'data/rate_limit.json') result = self.client.rate_limit() self.assertEqual(result.keys(), ['limit', 'remaining']) @patch('qiita.client.requests.get') def test_init_options(self, m): """ Client should set options. """ dummy_response(m, 'data/rate_limit.json') client = self.client self.assertEqual(client.url_name, self.params['url_name']) self.assertEqual(client.password, self.params['password']) @patch('qiita.client.requests.post') def test_get_token(self, m): """ login should return token. """ dummy_response(m, 'data/auth.json') result = self.client.login() self.assertTrue('token' in result) @patch('qiita.client.requests.post') def test_get_token_to_options(self, m): """ login should set token to token property. """ dummy_response(m, 'data/auth.json') result = self.client.login() self.assertEqual(self.client.token, result['token']) @patch('qiita.client.requests.get') def test_should_set_requests_module(self, m): """ HTTP Client should set to requests property. """ import requests from qiita.client import Client dummy_response(m, 'data/rate_limit.json') client = Client(requests=requests) result = client.rate_limit() self.assertEqual(result.keys(), ['limit', 'remaining']) def test_login_automatically(self): """ Client should get token when url_name and password set. """ self.assertTrue(self.client.token is not None) @patch('qiita.client.requests.post') @patch('qiita.client.requests.get') def test_token_exists(self, m_get, m_post): """ Client should authorize when only token set. """ from qiita.items import Items dummy_response(m_post, 'data/auth.json') client = Items(**self.params) token = client.token client = Items(token=token) dummy_response(m_get, 'data/search_item.json') params = {'stocked': 'true'} items = client.search_items(query='vim', params=params) self.assertTrue('body' in items[0])