def save(self): schema = copy(self.SCHEMA) for param in schema: attribute_value = getattr(self, param) if attribute_value is not None: schema[param] = attribute_value if self.is_new_record: response = API.create(self.__class__.name(), schema) for attr in response: setattr(self, attr, response[attr]) else: API.update(self.__class__.name(), self.Id, schema) return True
def test_update(self, request): request.return_value = Mock(status_code=200, text='[]') eq_(API.update('pies', '12345', {'Name': 'Cheese & Onion'}), []) request.assert_called_once_with( 'PUT', 'https://api.litmos.com/v1.svc/pies/12345?apikey=api-key-123&source=app-name-123&format=json', json={'Name': 'Cheese & Onion'})