def test_create(self, request): request.return_value = Mock(status_code=200, text='[]') eq_(API.create('pies', {'Name': 'Cheese & Onion'}), []) request.assert_called_once_with( 'POST', 'https://api.litmos.com/v1.svc/pies?apikey=api-key-123&source=app-name-123&format=json', json={'Name': 'Cheese & Onion'})
def create(cls, attributes): schema = copy(cls.SCHEMA) for param in schema: attribute_value = attributes.get(param, None) if attribute_value: schema[param] = attribute_value return cls._parse_response(API.create(cls.name(), schema))
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