def test_public_item(self, m): """ Items should get item without login. """ from qiita.items import Items dummy_response(m, 'data/public_items.json') client = Items() items = client.item('3288bf96ddc14bcef31c') self.assertTrue('body' in items)
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])
def test_shortcut(self): """ qiita should import Client, Items, Tags, Users. """ from qiita import Client, Items, Tags, Users self.assertTrue(isinstance(Client(), Client)) self.assertTrue(isinstance(Items(), Items)) self.assertTrue(isinstance(Tags(), Tags)) self.assertTrue(isinstance(Users(), Users))
def setUp(self, m): from qiita.items import Items dummy_response(m, 'data/auth.json') self.params = settings() self.items = Items(**self.params) self.params = { 'title': u'Qiita Python library test.', 'body': u'I love python!', 'tags': [{ 'name': 'python', 'versions': ['2.6', '2.7'] }], 'private': False, 'gist': False, 'tweet': False }
def setUp(self, m): from qiita.items import Items dummy_response(m, 'data/auth.json') self.params = settings() self.items = Items(**self.params) self.params = { 'title': u'Qiita Python library test.', 'body': u'I love python!', 'tags': [{'name': 'python', 'versions': ['2.6', '2.7']}], 'private': False, 'gist': False, 'tweet': False }
class TestItems(TestCase): @patch('qiita.client.requests.post') def setUp(self, m): from qiita.items import Items dummy_response(m, 'data/auth.json') self.params = settings() self.items = Items(**self.params) self.params = { 'title': u'Qiita Python library test.', 'body': u'I love python!', 'tags': [{'name': 'python', 'versions': ['2.6', '2.7']}], 'private': False, 'gist': False, 'tweet': False } @patch('qiita.client.requests.post') def test_post_item(self, m): """ Items should post new item. """ dummy_response(m, 'data/post_item.json') result = self.items.post_item(self.params) self.assertEqual(result['title'], self.params['title']) @patch('qiita.client.requests.delete') @patch('qiita.client.requests.post') def test_delete_item(self, mock_post, mock_delete): """ Items should delete item. """ dummy_response(mock_post, 'data/post_item.json') post_result = self.items.post_item(self.params) dummy_response(mock_delete) result = self.items.delete_item(post_result['uuid']) self.assertEqual(result, '') @patch('qiita.client.requests.put') @patch('qiita.client.requests.post') def test_update_item(self, mock_post, mock_put): """ Items should update item. """ dummy_response(mock_post, 'data/post_item.json') post_result = self.items.post_item(self.params) self.params['title'] = u'Qiita Python library test update.' self.params['body'] = u'I love Python and Vim!' dummy_response(mock_put, 'data/update_item.json') result = self.items.update_item(post_result['uuid'], self.params) self.assertEqual(result['title'], self.params['title']) @patch('qiita.client.requests.get') def test_public_item(self, m): """ Items should get item without login. """ from qiita.items import Items dummy_response(m, 'data/public_items.json') client = Items() items = client.item('3288bf96ddc14bcef31c') self.assertTrue('body' in items) @patch('qiita.client.requests.get') def test_search_items(self, m): """ Items should search items by query 'python'. """ dummy_response(m, 'data/search_items.json') items = self.items.search_items(query='python') self.assertTrue('body' in items[0]) @patch('qiita.client.requests.get') def test_search_stock(self, m): """ Items should search stocked itmes by query. """ dummy_response(m, 'data/search_items_stock.json') params = {'stocked': 'true'} items = self.items.search_items(query='vim', params=params) self.assertTrue('body' in items[0]) @patch('qiita.client.requests.put') def test_stock_item(self, m): """ Items should stock post. """ dummy_response(m) stocked = self.items.stock_item('1489e2b291fed74713b2') self.assertEqual(stocked, '') @patch('qiita.client.requests.delete') def test_unstock_item(self, m): """ Items should unstock item. """ dummy_response(m) stocked = self.items.unstock_item('1489e2b291fed74713b2') self.assertEqual(stocked, '') @patch('qiita.client.requests.delete') def test_should_raise_not_found_exception(self, m): """ Items should raise exception when there were no stocked item. """ from qiita.exceptions import NotFoundError dummy_error_response(m, 404) try: self.items.unstock_item('1489e2b291fed74713b2') self.fail() except NotFoundError: self.assertTrue(True) except Exception: self.fail()
class TestItems(TestCase): @patch('qiita.client.requests.post') def setUp(self, m): from qiita.items import Items dummy_response(m, 'data/auth.json') self.params = settings() self.items = Items(**self.params) self.params = { 'title': u'Qiita Python library test.', 'body': u'I love python!', 'tags': [{ 'name': 'python', 'versions': ['2.6', '2.7'] }], 'private': False, 'gist': False, 'tweet': False } @patch('qiita.client.requests.post') def test_post_item(self, m): """ Items should post new item. """ dummy_response(m, 'data/post_item.json') result = self.items.post_item(self.params) self.assertEqual(result['title'], self.params['title']) @patch('qiita.client.requests.delete') @patch('qiita.client.requests.post') def test_delete_item(self, mock_post, mock_delete): """ Items should delete item. """ dummy_response(mock_post, 'data/post_item.json') post_result = self.items.post_item(self.params) dummy_response(mock_delete) result = self.items.delete_item(post_result['uuid']) self.assertEqual(result, '') @patch('qiita.client.requests.put') @patch('qiita.client.requests.post') def test_update_item(self, mock_post, mock_put): """ Items should update item. """ dummy_response(mock_post, 'data/post_item.json') post_result = self.items.post_item(self.params) self.params['title'] = u'Qiita Python library test update.' self.params['body'] = u'I love Python and Vim!' dummy_response(mock_put, 'data/update_item.json') result = self.items.update_item(post_result['uuid'], self.params) self.assertEqual(result['title'], self.params['title']) @patch('qiita.client.requests.get') def test_public_item(self, m): """ Items should get item without login. """ from qiita.items import Items dummy_response(m, 'data/public_items.json') client = Items() items = client.item('3288bf96ddc14bcef31c') self.assertTrue('body' in items) @patch('qiita.client.requests.get') def test_search_items(self, m): """ Items should search items by query 'python'. """ dummy_response(m, 'data/search_items.json') items = self.items.search_items(query='python') self.assertTrue('body' in items[0]) @patch('qiita.client.requests.get') def test_search_stock(self, m): """ Items should search stocked itmes by query. """ dummy_response(m, 'data/search_items_stock.json') params = {'stocked': 'true'} items = self.items.search_items(query='vim', params=params) self.assertTrue('body' in items[0]) @patch('qiita.client.requests.put') def test_stock_item(self, m): """ Items should stock post. """ dummy_response(m) stocked = self.items.stock_item('1489e2b291fed74713b2') self.assertEqual(stocked, '') @patch('qiita.client.requests.delete') def test_unstock_item(self, m): """ Items should unstock item. """ dummy_response(m) stocked = self.items.unstock_item('1489e2b291fed74713b2') self.assertEqual(stocked, '') @patch('qiita.client.requests.delete') def test_should_raise_not_found_exception(self, m): """ Items should raise exception when there were no stocked item. """ from qiita.exceptions import NotFoundError dummy_error_response(m, 404) try: self.items.unstock_item('1489e2b291fed74713b2') self.fail() except NotFoundError: self.assertTrue(True) except Exception: self.fail()