# Copyright (c) 2011 Rafael Caricio rafael@caricio.com
frompyvowsimportVows,expect
classModel(object):
def__init__(self,context,model):
self.context=context
self.model=model
@Vows.assertion
defto_be_cruddable(topic):
importdjango.db.models.fieldsasfields
instance=__create_instance(topic)
assertinstance,"An instance could not be created for model %s"%topic.model.__name__
retrieved=topic.model.objects.get(id=instance.id)
assertretrieved.id==instance.id,"An instance could not be retrieved for model %s with id %d"%(topic.model.__name__,instance.id)
updated=__update_instance(topic,retrieved)
forfield,valueintopic.model._meta._field_cache:
iffield.__class__==fields.AutoField:
continue
assertgetattr(updated,field.name)!=getattr(instance,field.name),"The instance should have been updated but the field %s is the same in both the original instance and the updated one (%s)."%(field.name,getattr(updated,field.name))