def test_update(self): encoding = 'UTF-8' credentials = Credentials() shopify = Shopify(shop_name='test', credentials=credentials) # A new entity should not be updateable without it's pk being set. try: instance = TestModel() shopify.update(instance) self.fail() except InvalidRequestException: pass data = '{"test_model": {"name": "test"}}' response = requests.Response() response.encoding = encoding response._content = data.encode(encoding) response.status_code = 200 shopify.session.put = mock.Mock(return_value=response) instance = TestModel(id=2) shopify.update(instance) self.assertEquals(instance.name, "test") #TODO Mock the OAuthEngine.put method to capture the extra prop shopify.ignore_model_properties = True instance = TestModel(id=1, extra_property="Hello") shopify.update(instance) self.assertEquals(instance.name, "test") self.assertEquals(instance.id, 1) shopify.ignore_model_properties = False instance = TestModel(id=1) result = shopify.update(instance, auto_update=False) self.assertIsInstance(result, dict) self.assertFalse(hasattr(instance, "name")) try: response = requests.Response() response.encoding = encoding response._content = data.encode(encoding) response.status_code = 404 shopify.session.put = mock.Mock(return_value=response) result = shopify.update(instance) self.fail() except ShopifyException: pass