workflow = models.ForeignKey(Workflow) state = models.ForeignKey(State) class Meta: app_label = "stateworkflow" def hello_world(*args, **kw): print "hello_world" def null(*args, **kw): return True def error(*args, **kw): raise WorkflowScriptError register("null", "Null script, will do nothing", null) register("error", "Error script, will just raise an error", null) class basic(TestCase): fixtures = ["test.json", ] def setUp(self): self.workflow = Workflow.objects.get(id=1) self.states = {} for state in self.workflow.state_set.all(): self.states[state.name] = state self.transitions = Transition.objects.all() def _create_workflow(self): workflow = Workflow() workflow.name = "Test"
def test_script_registry(self): assert len(admin_registry) == 4 register("hello", "hello world", hello_world) assert len(admin_registry) == 5
from django.db import models from django.db import connection def check_complete(obj, transition): for field in ["title", "description"]: if not getattr(obj, field): return False return True def set_published_date(obj, transition): from datetime import datetime obj.published_date = datetime.now() obj.save() register("check_complete", "Check news item is complete", check_complete) register("set_published_date", "Set the published date on the news item", set_published_date) class NewsItem(models.Model): title = models.CharField(max_length=255) description = models.TextField() published_date = models.DateTimeField(blank=True, null=True) state = models.ForeignKey(State) class Meta: app_label = "stateworkflow" class advanced(TestCase): fixtures = ["test.json", ] def setUp(self):