コード例 #1
0
    def test_update_category(self, requests_mock):
        response_mock = Mock()
        response_mock.status_code = 200
        response_mock.text = json.dumps(
            {'id': 991, 'name': 'test cat'},
        )
        requests_mock.put.return_value = response_mock
        cli = APIClient('test_api_key', 'test user agent')
        c = CategoryResource(cli, '46')

        c.update({'id': 991, 'name': 'test cat updated'})

        requests_mock.put.assert_called_with(
            url='https://api.tiendanube.com/v1/46/categories/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 cat updated'})
        )
コード例 #2
0
    def test_get_category(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')
        c = CategoryResource(cli, '46')


        res = c.get(991)

        self.assertEqual(991, res.id)

        requests_mock.get.assert_called_with(
            url='https://api.tiendanube.com/v1/46/categories/991',
            headers={'Authentication': 'bearer test_api_key', 'User-Agent': 'test user agent'},
            params=None
        )
コード例 #3
0
    def test_list_categories_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')
        c = CategoryResource(cli, '46')

        res = c.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/categories',
            headers={'Authentication': 'bearer test_api_key', 'User-Agent': 'test user agent'},
            params={'since_id': 47, 'fields': 'id'},
        )
コード例 #4
0
    def test_add_category(self, requests_mock):
        response_mock = Mock()
        response_mock.status_code = 201
        response_mock.text = json.dumps(
            {'id': 46, 'name': 'test category'},
        )
        requests_mock.post.return_value = response_mock
        cli = APIClient('test_api_key', 'test user agent')
        c = CategoryResource(cli, '46')

        res = c.add({'id': 46, 'name': 'test category'})

        self.assertEqual(bunchify(
            {'id': 46, 'name': 'test category'}
        ), res)

        requests_mock.post.assert_called_with(
            url='https://api.tiendanube.com/v1/46/categories',
            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 category'})
        )
コード例 #5
0
    def test_list_categories_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')
        c = CategoryResource(cli, '46')

        created_at_min = datetime.datetime(2013, 1, 1, 0, 0, 0).replace(tzinfo=utc)
        res = c.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/categories',
            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'}
        )
コード例 #6
0
    def test_list_categories_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')
        c = CategoryResource(cli, '46')

        created_at_min = datetime.datetime(2013, 1, 1, 0, 0, 0).replace(tzinfo=utc)
        res = c.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/categories',
            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'}
        )
コード例 #7
0
    def test_list_categories_base(self, requests_mock):
        response_mock = Mock()
        response_mock.status_code = 200
        response_mock.content = json.dumps([
            {
                'id': 46,
                'name': 'test cat'
            },
            {
                'id': 47,
                'name': 'test cat 2'
            },
        ])
        requests_mock.get.return_value = response_mock
        cli = APIClient('test_api_key', 'test user agent')
        c = CategoryResource(cli, '46')

        res = c.list()

        self.assertEqual(
            bunchify([
                {
                    'id': 46,
                    'name': 'test cat'
                },
                {
                    'id': 47,
                    'name': 'test cat 2'
                },
            ]), res)

        requests_mock.get.assert_called_with(
            url='https://api.tiendanube.com/v1/46/categories',
            headers={
                'Authentication': 'bearer test_api_key',
                'User-Agent': 'test user agent'
            },
            params=None)
コード例 #8
0
    def test_add_category(self, requests_mock):
        response_mock = Mock()
        response_mock.status_code = 201
        response_mock.text = json.dumps({'id': 46, 'name': 'test category'}, )
        requests_mock.post.return_value = response_mock
        cli = APIClient('test_api_key', 'test user agent')
        c = CategoryResource(cli, '46')

        res = c.add({'id': 46, 'name': 'test category'})

        self.assertEqual(bunchify({'id': 46, 'name': 'test category'}), res)

        requests_mock.post.assert_called_with(
            url='https://api.tiendanube.com/v1/46/categories',
            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 category'
            }))