Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions tests/testapp/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,26 @@ def dean_rejected(self):
pass


class DbState(models.Model):
"""
States in DB
"""

id = models.CharField(primary_key=True, max_length=50)

label = models.CharField(max_length=255)

def __str__(self):
return self.label


class FKApplication(models.Model):
"""
Student application need to be approved by dept chair and dean.
Test workflow for FSMKeyField
"""

state = FSMKeyField("testapp.DbState", default="new", on_delete=models.CASCADE)
state = FSMKeyField(DbState, default="new", on_delete=models.CASCADE)

@transition(field=state, source="new", target="draft")
def draft(self):
Expand All @@ -73,19 +86,6 @@ def dean_rejected(self):
pass


class DbState(models.Model):
"""
States in DB
"""

id = models.CharField(primary_key=True, max_length=50)

label = models.CharField(max_length=255)

def __str__(self):
return self.label


class BlogPost(models.Model):
"""
Test workflow
Expand Down
3 changes: 0 additions & 3 deletions tests/testapp/tests/test_access_deferred_fsm_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
class DeferrableModel(models.Model):
state = FSMField(default="new")

class Meta:
app_label = "testapp"

@transition(field=state, source="new", target="published")
def publish(self):
pass
Expand Down
3 changes: 0 additions & 3 deletions tests/testapp/tests/test_custom_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
class BlogPostWithCustomData(models.Model):
state = FSMField(default="new")

class Meta:
app_label = "testapp"

@transition(field=state, source="new", target="published", conditions=[], custom={"label": "Publish", "type": "*"})
def publish(self):
pass
Expand Down
3 changes: 0 additions & 3 deletions tests/testapp/tests/test_exception_transitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
class ExceptionalBlogPost(models.Model):
state = FSMField(default="new")

class Meta:
app_label = "testapp"

@transition(field=state, source="new", target="published", on_error="crashed")
def publish(self):
raise Exception("Upss")
Expand Down
11 changes: 6 additions & 5 deletions tests/testapp/tests/test_key_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ def moderate(self):

class FSMKeyFieldTest(TestCase):
def setUp(self):
for item in FK_AVAILABLE_STATES:
DbState.objects.create(pk=item[0], label=item[1])
DbState.objects.bulk_create(DbState(pk=item[0], label=item[1]) for item in FK_AVAILABLE_STATES)
self.model = FKBlogPost()

def test_initial_state_instantiated(self):
Expand Down Expand Up @@ -126,9 +125,11 @@ def hide(self):

class BlogPostWithFKStateTest(TestCase):
def setUp(self):
BlogPostStatus.objects.create(name="new")
BlogPostStatus.objects.create(name="published")
BlogPostStatus.objects.create(name="hidden")
BlogPostStatus.objects.bulk_create([
BlogPostStatus(name="new")
BlogPostStatus(name="published")
BlogPostStatus(name="hidden")
])
self.model = BlogPostWithFKState()

def test_known_transition_should_succeed(self):
Expand Down
6 changes: 0 additions & 6 deletions tests/testapp/tests/test_lock_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ class LockedBlogPost(ConcurrentTransitionMixin, models.Model):
state = FSMField(default="new")
text = models.CharField(max_length=50)

class Meta:
app_label = "testapp"

@transition(field=state, source="new", target="published")
def publish(self):
pass
Expand All @@ -30,9 +27,6 @@ class ExtendedBlogPost(LockedBlogPost):
review_state = FSMField(default="waiting", protected=True)
notes = models.CharField(max_length=50)

class Meta:
app_label = "testapp"

@transition(field=review_state, source="waiting", target="rejected")
def reject(self):
pass
Expand Down
3 changes: 0 additions & 3 deletions tests/testapp/tests/test_mixin_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@


class WorkflowMixin:
class Meta:
app_label = "testapp"

@transition(field="state", source="*", target="draft")
def draft(self):
pass
Expand Down
13 changes: 2 additions & 11 deletions tests/testapp/tests/test_model_create_with_generic.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
from __future__ import annotations

try:
from django.contrib.contenttypes.fields import GenericForeignKey
except ImportError:
# Django 1.6
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👴

from django.contrib.contenttypes.generic import GenericForeignKey
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from django.db import models
from django.test import TestCase
Expand All @@ -13,9 +9,7 @@
from django_fsm import transition


class Ticket(models.Model):
class Meta:
app_label = "testapp"
class Ticket(models.Model): ...


class TaskState(models.TextChoices):
Expand All @@ -29,9 +23,6 @@ class Task(models.Model):
causality = GenericForeignKey("content_type", "object_id")
state = FSMField(default=TaskState.NEW)

class Meta:
app_label = "testapp"

@transition(field=state, source=TaskState.NEW, target=TaskState.DONE)
def do(self):
pass
Expand Down
3 changes: 0 additions & 3 deletions tests/testapp/tests/test_multi_resultstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
class MultiResultTest(models.Model):
state = FSMField(default="new")

class Meta:
app_label = "testapp"

@transition(field=state, source="new", target=RETURN_VALUE("for_moderators", "published"))
def publish(self, *, is_public=False):
return "published" if is_public else "for_moderators"
Expand Down
3 changes: 0 additions & 3 deletions tests/testapp/tests/test_multidecorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ class TestModel(models.Model):
signal_counter = models.IntegerField(default=0)
state = FSMField(default="SUBMITTED_BY_USER")

class Meta:
app_label = "testapp"

@transition(field=state, source="SUBMITTED_BY_USER", target="REVIEW_USER")
@transition(field=state, source="SUBMITTED_BY_ADMIN", target="REVIEW_ADMIN")
@transition(field=state, source="SUBMITTED_BY_ANONYMOUS", target="REVIEW_ANONYMOUS")
Expand Down
2 changes: 0 additions & 2 deletions tests/testapp/tests/test_object_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ class ObjectPermissionTestModel(models.Model):
state = FSMField(default="new")

class Meta:
app_label = "testapp"

permissions = [
("can_publish_objectpermissiontestmodel", "Can publish ObjectPermissionTestModel"),
]
Expand Down
2 changes: 1 addition & 1 deletion tests/testapp/tests/test_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def setUp(self):
self.privileged.user_permissions.add(Permission.objects.get_by_natural_key("can_publish_post", "testapp", "blogpost"))
self.privileged.user_permissions.add(Permission.objects.get_by_natural_key("can_remove_post", "testapp", "blogpost"))

def test_proviledged_access_succeed(self):
def test_privileged_access_succeed(self):
assert has_transition_perm(self.model.publish, self.privileged)
assert has_transition_perm(self.model.remove, self.privileged)

Expand Down
13 changes: 6 additions & 7 deletions tests/testapp/tests/test_state_transitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ class STATE:

state = FSMField(default=STATE.CATERPILLAR, state_choices=STATE_CHOICES)

class Meta:
app_label = "testapp"

@transition(field=state, source=STATE.CATERPILLAR, target=STATE.BUTTERFLY)
def cocoon(self):
pass
Expand All @@ -32,7 +29,6 @@ def crawl(self):

class Caterpillar(Insect):
class Meta:
app_label = "testapp"
proxy = True

def crawl(self):
Expand All @@ -43,7 +39,6 @@ def crawl(self):

class Butterfly(Insect):
class Meta:
app_label = "testapp"
proxy = True

def fly(self):
Expand All @@ -63,8 +58,12 @@ def test_transition_proxy_set_succeed(self):
assert isinstance(insect, Butterfly)

def test_load_proxy_set(self):
Insect.objects.create(state=Insect.STATE.CATERPILLAR)
Insect.objects.create(state=Insect.STATE.BUTTERFLY)
Insect.objects.bulk_create(
[
Insect(state=Insect.STATE.CATERPILLAR),
Insect(state=Insect.STATE.BUTTERFLY),
]
)

insects = Insect.objects.all()
assert {Caterpillar, Butterfly} == {insect.__class__ for insect in insects}
3 changes: 0 additions & 3 deletions tests/testapp/tests/test_string_field_parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
class BlogPostWithStringField(models.Model):
state = FSMField(default="new")

class Meta:
app_label = "testapp"

@transition(field="state", source="new", target="published", conditions=[])
def publish(self):
pass
Expand Down
3 changes: 0 additions & 3 deletions tests/testapp/tests/test_transition_all_except_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
class TestExceptTargetTransitionShortcut(models.Model):
state = FSMField(default="new")

class Meta:
app_label = "testapp"

@transition(field=state, source="new", target="published")
def publish(self):
pass
Expand Down
1 change: 0 additions & 1 deletion tests/testapp/views.py

This file was deleted.