def test_get_product_get_image(self, requests_mock): response_mock = Mock() response_mock.status_code = 200 response_mock.content = json.dumps({'id': 991, 'name': 'test prod'}) requests_mock.get.return_value = response_mock cli = APIClient('test_api_key', 'test user agent') p = ProductResource(cli, '46') res = p.get(991) self.assertEqual(991, res.id) requests_mock.get.assert_called_with( url='https://api.tiendanube.com/v1/46/products/991', headers={'Authentication': 'bearer test_api_key', 'User-Agent': 'test user agent'}, params=None ) response_mock.content = json.dumps({'id': 1, 'name': 'test prod image'}) res = res.images.get(1) self.assertEqual(bunchify({'id': 1, 'name': 'test prod image'}), res) requests_mock.get.assert_called_with( url='https://api.tiendanube.com/v1/46/products/991/images/1', headers={'Authentication': 'bearer test_api_key', 'User-Agent': 'test user agent'}, params=None )
def test_list_products_fields(self, requests_mock): response_mock = Mock() response_mock.status_code = 200 response_mock.content = json.dumps([ { 'id': 46 }, { 'id': 47 }, ]) requests_mock.get.return_value = response_mock cli = APIClient('test_api_key', 'test user agent') p = ProductResource(cli, '46') res = p.list(fields='id') self.assertEqual(bunchify([ { 'id': 46 }, { 'id': 47 }, ]), res) requests_mock.get.assert_called_with( url='https://api.tiendanube.com/v1/46/products', headers={ 'Authentication': 'bearer test_api_key', 'User-Agent': 'test user agent' }, params={'fields': 'id'})
def test_update_product(self, requests_mock): response_mock = Mock() response_mock.status_code = 200 response_mock.text = json.dumps( {'id': 991, 'name': 'test prod'}, ) requests_mock.put.return_value = response_mock cli = APIClient('test_api_key', 'test user agent') p = ProductResource(cli, '46') p.update({'id': 991, 'name': 'test prod updated'}) requests_mock.put.assert_called_with( url='https://api.tiendanube.com/v1/46/products/991', headers={'Authentication': 'bearer test_api_key', 'User-Agent': 'test user agent', 'Content-Type': 'application/json; charset=utf-8'}, data=json.dumps({'id': 991, 'name': 'test prod updated'}) )
def test_add_product(self, requests_mock): response_mock = Mock() response_mock.status_code = 201 response_mock.text = json.dumps( {'id': 46, 'name': 'test prod'}, ) requests_mock.post.return_value = response_mock cli = APIClient('test_api_key', 'test user agent') p = ProductResource(cli, '46') res = p.add({'id': 46, 'name': 'test prod'}) self.assertEqual(bunchify( {'id': 46, 'name': 'test prod'} ), res) requests_mock.post.assert_called_with( url='https://api.tiendanube.com/v1/46/products', headers={'Authentication': 'bearer test_api_key', 'User-Agent': 'test user agent', 'Content-Type': 'application/json; charset=utf-8'}, data=json.dumps({'id': 46, 'name': 'test prod'}) )
def test_list_products_filter(self, requests_mock): response_mock = Mock() response_mock.status_code = 200 response_mock.content = json.dumps([ {'id': 47}, ]) requests_mock.get.return_value = response_mock cli = APIClient('test_api_key', 'test user agent') p = ProductResource(cli, '46') res = p.list(filters={'since_id': 47}, fields='id') self.assertEqual(bunchify([ {'id': 47}, ]), res) requests_mock.get.assert_called_with( url='https://api.tiendanube.com/v1/46/products', headers={'Authentication': 'bearer test_api_key', 'User-Agent': 'test user agent'}, params={'fields': 'id', 'since_id': 47} )
def test_list_products_filter_date(self, requests_mock): response_mock = Mock() response_mock.status_code = 200 response_mock.content = json.dumps([ {'id': 47}, ]) requests_mock.get.return_value = response_mock cli = APIClient('test_api_key', 'test user agent') p = ProductResource(cli, '46') created_at_min = datetime.datetime(2013, 1, 1, 0, 0, 0).replace(tzinfo=utc) res = p.list(filters={'since_id': 47, 'created_at_min': created_at_min}, fields='id') self.assertEqual(bunchify([ {'id': 47}, ]), res) requests_mock.get.assert_called_with( url='https://api.tiendanube.com/v1/46/products', headers={'Authentication': 'bearer test_api_key', 'User-Agent': 'test user agent'}, params={'since_id': 47, 'created_at_min': '2013-01-01T00:00:00+00:00', 'fields': 'id'}, )