Esempio n. 1
0
    def test_resource_update_returns_model_instance(self):
        client = MockClient(response=ATTRIBUTE_SET)
        res = OpfrontResource(ENDPOINT, client)

        m = res.update(Model(res, **ATTRIBUTE_SET))

        self.assertIsInstance(m, Model)
Esempio n. 2
0
    def test_resource_delete_does_delete_request(self):
        client = MockClient()
        res = OpfrontResource(ENDPOINT, client)

        res.delete(RES_ID)

        self.assertEqual(client.do_request.call_args[0][1], 'DELETE')
Esempio n. 3
0
    def test_resource_update_does_put_request(self):
        client = MockClient(response=ATTRIBUTE_SET)
        res = OpfrontResource(ENDPOINT, client)

        res.update(Model(res, **ATTRIBUTE_SET))

        self.assertEqual(client.do_request.call_args[0][1], 'PATCH')
Esempio n. 4
0
    def test_resource_get_calls_do_request_with_http_get(self):
        client = MockClient()
        res = OpfrontResource(ENDPOINT, client)

        res.get(RES_ID)

        self.assertEqual(client.do_request.call_args[0][1], 'GET')
Esempio n. 5
0
    def test_resource_create_does_not_append_to_url(self):
        client = MockClient(response=ATTRIBUTE_SET)
        res = OpfrontResource(ENDPOINT, client)

        res.create(Model(res, **ATTRIBUTE_SET))

        self.assertEqual(client.do_request.call_args[0][0], ENDPOINT)
Esempio n. 6
0
    def test_resource_list_returns_correct_item_count(self):
        client = MockClient(response=LIST_BODY)
        res = OpfrontResource(ENDPOINT, client)

        hits = [hit for hit in res.list(page_size=PAGE_SIZE)]

        self.assertEqual(len(hits), TOTAL_LIST_HITS)
Esempio n. 7
0
    def test_resource_get_returns_model_instance(self):
        client = MockClient()
        res = OpfrontResource(ENDPOINT, client)

        m = res.get(RES_ID)

        self.assertIsInstance(m, Model)
Esempio n. 8
0
    def test_resource_list_returns_a_generator(self):
        client = MockClient(response=LIST_BODY)
        res = OpfrontResource(ENDPOINT, client)

        hits = res.list()

        self.assertIsInstance(hits, types.GeneratorType)
Esempio n. 9
0
    def test_resource_update_calls_do_request(self):
        client = MockClient(response=ATTRIBUTE_SET)
        res = OpfrontResource(ENDPOINT, client)

        res.update(Model(res, **ATTRIBUTE_SET))

        self.assertTrue(client.do_request.called)
        self.assertEqual(client.do_request.call_count, 1)
Esempio n. 10
0
    def test_resource_list_perform_correct_number_of_request(self):
        client = MockClient(response=LIST_BODY)
        res = OpfrontResource(ENDPOINT, client)

        hits = [hit for hit in res.list(page_size=PAGE_SIZE)]

        self.assertEqual(client.do_request.call_count,
                         TOTAL_LIST_HITS / PAGE_SIZE)
Esempio n. 11
0
    def test_resource_get_appends_id_to_endpoint(self):
        client = MockClient()
        res = OpfrontResource(ENDPOINT, client)

        res.get(RES_ID)

        self.assertEqual(client.do_request.call_args[0][0],
                         '{0}/{1}'.format(ENDPOINT, RES_ID))
Esempio n. 12
0
    def test_resource_get_returns_model_with_response_attributes(self):
        client = MockClient(response=ATTRIBUTE_SET)
        res = OpfrontResource(ENDPOINT, client)

        m = res.get(RES_ID)

        for k, v in ATTRIBUTE_SET.items():
            self.assertEqual(getattr(m, k), v)
Esempio n. 13
0
    def test_resource_get_calls_do_request(self):
        client = MockClient()
        res = OpfrontResource(ENDPOINT, client)

        res.get(RES_ID)

        self.assertTrue(client.do_request.called)
        self.assertEqual(client.do_request.call_count, 1)
Esempio n. 14
0
    def test_resource_update_appends_id_to_url(self):
        client = MockClient(response=ATTRIBUTE_SET)
        res = OpfrontResource(ENDPOINT, client)

        res.update(Model(res, **ATTRIBUTE_SET))

        self.assertEqual(client.do_request.call_args[0][0],
                         '{0}/{1}'.format(ENDPOINT, RES_ID))
Esempio n. 15
0
    def __init__(self, email, password, **kwargs):
        client = OpfrontClient(email, password, **kwargs)

        # Resource definition
        self.banner = OpfrontResource('/banners', client)
        self.spectacle = OpfrontResource('/spectacles', client)
        self.store = StoreResource('/stores', client)
        self.product = ProductResource('/products', client)
        self.order = OrderResource('/orders', client)
        self.user = UserResource('/users', client)
Esempio n. 16
0
    def _make_model(self, **args):
        model = super()._make_model(**args)
        if getattr(model, 'products', None) is not None:
            model.products = [
                Model(OpfrontResource('/products', self._client), **prod)
                for prod in model.products
            ]

        if getattr(model, 'store', None) is not None:
            model.store = Model(OpfrontResource('/stores', self._client),
                                **model.store)

        return model
Esempio n. 17
0
    def _make_model(self, **args):
        model = super()._make_model(**args)
        if getattr(model, 'banner', None) is not None:
            model.banner = Model(OpfrontResource('/banners', self._client),
                                 **model.banner)

        return model
Esempio n. 18
0
    def _make_model(self, **args):
        model = super()._make_model(**args)
        if getattr(model, 'spectacle', None) is not None:
            model.spectacle = Model(
                OpfrontResource('/spectacles', self._client),
                **model.spectacle)

        return model
Esempio n. 19
0
    def test_resource_exists_returns_true_when_no_exception_is_raised(self):
        client = MockClient(response=ATTRIBUTE_SET)
        res = OpfrontResource(ENDPOINT, client)

        self.assertTrue(res.exists(RES_ID))
Esempio n. 20
0
    def test_resource_exists_returns_false_when_resource_not_found_is_raised(
            self):
        client = MockClient(should_raise=ResourceNotFoundError)
        res = OpfrontResource(ENDPOINT, client)

        self.assertFalse(res.exists(RES_ID))
Esempio n. 21
0
    def test_resource_exists_reraises_other_exceptions(self):
        client = MockClient(response=ATTRIBUTE_SET)
        res = OpfrontResource(ENDPOINT, client)

        with self.assertRaises(ValueError):
            res.exists(RES_ID)
Esempio n. 22
0
    def test_resource_call_returns_model(self):
        res = OpfrontResource(ENDPOINT, MockClient())
        m = res(**ATTRIBUTE_SET)

        self.assertIsInstance(m, Model)
Esempio n. 23
0
    def test_resource_passes_attributes_to_model(self):
        res = OpfrontResource(ENDPOINT, MockClient())
        m = res(**ATTRIBUTE_SET)

        for k, v in ATTRIBUTE_SET.items():
            self.assertEqual(getattr(m, k), v)
Esempio n. 24
0
    def test_resource_call_passes_self_to_model(self):
        res = OpfrontResource(ENDPOINT, MockClient())
        m = res(**ATTRIBUTE_SET)

        self.assertIs(m._res, res)