Beispiel #1
0
    def test_list_scripts_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')
        s = ScriptResource(cli, '46')

        res = s.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/scripts',
            headers={
                'Authentication': 'bearer test_api_key',
                'User-Agent': 'test user agent'
            },
            params={
                'since_id': 47,
                'fields': 'id'
            })
Beispiel #2
0
    def test_update_script(self, requests_mock):
        response_mock = Mock()
        response_mock.status_code = 200
        response_mock.text = json.dumps(
            {'id': 991, 'name': 'test script'},
        )
        requests_mock.put.return_value = response_mock
        cli = APIClient('test_api_key', 'test user agent')
        s = ScriptResource(cli, '46')

        s.update({'id': 991, 'name': 'test script updated'})

        requests_mock.put.assert_called_with(
            url='https://api.tiendanube.com/v1/46/scripts/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 script updated'})
        )
    def test_update_script(self, requests_mock):
        response_mock = Mock()
        response_mock.status_code = 200
        response_mock.text = json.dumps(
            {'id': 991, 'name': 'test script'},
        )
        requests_mock.put.return_value = response_mock
        cli = APIClient('test_api_key', 'test user agent')
        s = ScriptResource(cli, '46')

        s.update({'id': 991, 'name': 'test script updated'})

        requests_mock.put.assert_called_with(
            url='https://api.tiendanube.com/v1/46/scripts/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 script updated'})
        )
Beispiel #4
0
    def test_get_script(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')
        s = ScriptResource(cli, '46')


        res = s.get(991)

        self.assertEqual(991, res.id)

        requests_mock.get.assert_called_with(
            url='https://api.tiendanube.com/v1/46/scripts/991',
            headers={'Authentication': 'bearer test_api_key', 'User-Agent': 'test user agent'},
            params=None
        )
    def test_get_script(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')
        s = ScriptResource(cli, '46')


        res = s.get(991)

        self.assertEqual(991, res.id)

        requests_mock.get.assert_called_with(
            url='https://api.tiendanube.com/v1/46/scripts/991',
            headers={'Authentication': 'bearer test_api_key', 'User-Agent': 'test user agent'},
            params=None
        )
Beispiel #6
0
    def test_add_script(self, requests_mock):
        response_mock = Mock()
        response_mock.status_code = 201
        response_mock.text = json.dumps(
            {'id': 46, 'name': 'test script'},
        )
        requests_mock.post.return_value = response_mock
        cli = APIClient('test_api_key', 'test user agent')
        s = ScriptResource(cli, '46')

        res = s.add({'id': 46, 'name': 'test script'})

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

        requests_mock.post.assert_called_with(
            url='https://api.tiendanube.com/v1/46/scripts',
            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 script'})
        )
    def test_list_scripts_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')
        s = ScriptResource(cli, '46')

        res = s.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/scripts',
            headers={'Authentication': 'bearer test_api_key', 'User-Agent': 'test user agent'},
            params={'since_id': 47, 'fields': 'id'}
        )
    def test_add_script(self, requests_mock):
        response_mock = Mock()
        response_mock.status_code = 201
        response_mock.text = json.dumps(
            {'id': 46, 'name': 'test script'},
        )
        requests_mock.post.return_value = response_mock
        cli = APIClient('test_api_key', 'test user agent')
        s = ScriptResource(cli, '46')

        res = s.add({'id': 46, 'name': 'test script'})

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

        requests_mock.post.assert_called_with(
            url='https://api.tiendanube.com/v1/46/scripts',
            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 script'})
        )
Beispiel #9
0
    def test_list_scripts_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')
        s = ScriptResource(cli, '46')

        created_at_min = datetime.datetime(2013, 1, 1, 0, 0, 0).replace(tzinfo=utc)
        res = s.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/scripts',
            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'}
        )
    def test_list_scripts_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')
        s = ScriptResource(cli, '46')

        created_at_min = datetime.datetime(2013, 1, 1, 0, 0, 0).replace(tzinfo=utc)
        res = s.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/scripts',
            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'}
        )