def parse_and_save(data, current_template): """Parse the data to create custom resources and save them. Args: data: dict current_template: Returns: """ for key in data.keys(): resource = data[key] custom_resource = CustomResource(template=current_template) if _is_type_all(resource): custom_resource = _create_custom_resource_type_all( custom_resource, resource, key) # TODO: make sure only one type = 'all' ? else: custom_resource = _create_custom_resource(custom_resource, resource, key) try: _check_curate(custom_resource) custom_resource.save() except Exception as e: raise exceptions.ModelError(str(e))
def test_create_custom_resource_wrong_type_return_except(self): # Act template = self.fixture.create_and_save_template() # Assert with self.assertRaises(ValidationError): custom_resource = CustomResource( template=template, title="title", type="wrong", icon="icon", sort=0 ) custom_resource.save()