예제 #1
0
    def test_fetch(self):
        encoding = 'UTF-8'
        credentials = Credentials()
        shopify = Shopify(shop_name='test', credentials=credentials)

        data = '{"test_model": {"id": 1, "name": "test"}}'
        response = requests.Response()
        response.encoding = encoding
        response._content = data.encode(encoding)
        response.status_code = 200

        shopify.session.get = mock.Mock(return_value=response)
        instance = shopify.fetch(TestModel, 2)
        self.assertIsInstance(instance, TestModel)
        self.assertEquals(instance.name, "test")
        self.assertEquals(instance.id, 1)

        result = shopify.fetch(TestModel, 2, auto_instance=False)
        self.assertIsInstance(result, dict)

        try:
            response = requests.Response()
            response.encoding = encoding
            response._content = data.encode(encoding)
            response.status_code = 404
            shopify.session.get = mock.Mock(return_value=response)
            result = shopify.fetch(TestModel, 2)
            self.fail()
        except ShopifyException:
            pass
예제 #2
0
    def test_fetch(self):
        encoding = 'UTF-8'
        credentials = Credentials()
        shopify = Shopify(shop_name='test', credentials=credentials)

        data = '{"test_model": {"id": 1, "name": "test"}}'
        response = requests.Response()
        response.encoding = encoding
        response._content = data.encode(encoding)
        response.status_code = 200

        shopify.session.get = mock.Mock(return_value=response)
        instance = shopify.fetch(TestModel, 2)
        self.assertIsInstance(instance, TestModel)
        self.assertEquals(instance.name, "test")
        self.assertEquals(instance.id, 1)

        result = shopify.fetch(TestModel, 2, auto_instance=False)
        self.assertIsInstance(result, dict)

        try:
            response = requests.Response()
            response.encoding = encoding
            response._content = data.encode(encoding)
            response.status_code = 404
            shopify.session.get = mock.Mock(return_value=response)
            result = shopify.fetch(TestModel, 2)
            self.fail()
        except ShopifyException:
            pass
예제 #3
0
    def test_fetch_subresource(self):
        encoding = 'UTF-8'
        credentials = Credentials()
        shopify = Shopify(shop_name='test', credentials=credentials)

        data = '{"test_sub_resource": {"id": 1, "name": "test"}}'
        response = requests.Response()
        response.encoding = encoding
        response._content = data.encode(encoding)
        response.status_code = 200

        shopify.session.get = mock.Mock(return_value=response)
        instance = shopify.fetch(TestSubResource, 2, parent_id=1)
        self.assertIsInstance(instance, TestModel)
        self.assertEquals(instance.name, "test")
        self.assertEquals(instance.id, 1)
예제 #4
0
    def test_fetch_subresource(self):
        encoding = 'UTF-8'
        credentials = Credentials()
        shopify = Shopify(shop_name='test', credentials=credentials)

        data = '{"test_sub_resource": {"id": 1, "name": "test"}}'
        response = requests.Response()
        response.encoding = encoding
        response._content = data.encode(encoding)
        response.status_code = 200

        shopify.session.get = mock.Mock(return_value=response)
        instance = shopify.fetch(TestSubResource, 2, parent_id=1)
        self.assertIsInstance(instance, TestModel)
        self.assertEquals(instance.name, "test")
        self.assertEquals(instance.id, 1)