Skip to content

Commit eb03f98

Browse files
authored
DX: Cleanup tests using Ruff (#45)
1 parent 42a87f2 commit eb03f98

16 files changed

+29
-71
lines changed

tests/testapp/models.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,26 @@ def dean_rejected(self):
4040
pass
4141

4242

43+
class DbState(models.Model):
44+
"""
45+
States in DB
46+
"""
47+
48+
id = models.CharField(primary_key=True, max_length=50)
49+
50+
label = models.CharField(max_length=255)
51+
52+
def __str__(self):
53+
return self.label
54+
55+
4356
class FKApplication(models.Model):
4457
"""
4558
Student application need to be approved by dept chair and dean.
4659
Test workflow for FSMKeyField
4760
"""
4861

49-
state = FSMKeyField("testapp.DbState", default="new", on_delete=models.CASCADE)
62+
state = FSMKeyField(DbState, default="new", on_delete=models.CASCADE)
5063

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

7588

76-
class DbState(models.Model):
77-
"""
78-
States in DB
79-
"""
80-
81-
id = models.CharField(primary_key=True, max_length=50)
82-
83-
label = models.CharField(max_length=255)
84-
85-
def __str__(self):
86-
return self.label
87-
88-
8989
class BlogPost(models.Model):
9090
"""
9191
Test workflow

tests/testapp/tests/test_access_deferred_fsm_field.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111
class DeferrableModel(models.Model):
1212
state = FSMField(default="new")
1313

14-
class Meta:
15-
app_label = "testapp"
16-
1714
@transition(field=state, source="new", target="published")
1815
def publish(self):
1916
pass

tests/testapp/tests/test_custom_data.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
class BlogPostWithCustomData(models.Model):
1111
state = FSMField(default="new")
1212

13-
class Meta:
14-
app_label = "testapp"
15-
1613
@transition(field=state, source="new", target="published", conditions=[], custom={"label": "Publish", "type": "*"})
1714
def publish(self):
1815
pass

tests/testapp/tests/test_exception_transitions.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313
class ExceptionalBlogPost(models.Model):
1414
state = FSMField(default="new")
1515

16-
class Meta:
17-
app_label = "testapp"
18-
1916
@transition(field=state, source="new", target="published", on_error="crashed")
2017
def publish(self):
2118
raise Exception("Upss")

tests/testapp/tests/test_key_field.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ def moderate(self):
5050

5151
class FSMKeyFieldTest(TestCase):
5252
def setUp(self):
53-
for item in FK_AVAILABLE_STATES:
54-
DbState.objects.create(pk=item[0], label=item[1])
53+
DbState.objects.bulk_create(DbState(pk=item[0], label=item[1]) for item in FK_AVAILABLE_STATES)
5554
self.model = FKBlogPost()
5655

5756
def test_initial_state_instantiated(self):
@@ -126,9 +125,11 @@ def hide(self):
126125
127126
class BlogPostWithFKStateTest(TestCase):
128127
def setUp(self):
129-
BlogPostStatus.objects.create(name="new")
130-
BlogPostStatus.objects.create(name="published")
131-
BlogPostStatus.objects.create(name="hidden")
128+
BlogPostStatus.objects.bulk_create([
129+
BlogPostStatus(name="new")
130+
BlogPostStatus(name="published")
131+
BlogPostStatus(name="hidden")
132+
])
132133
self.model = BlogPostWithFKState()
133134
134135
def test_known_transition_should_succeed(self):

tests/testapp/tests/test_lock_mixin.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ class LockedBlogPost(ConcurrentTransitionMixin, models.Model):
1414
state = FSMField(default="new")
1515
text = models.CharField(max_length=50)
1616

17-
class Meta:
18-
app_label = "testapp"
19-
2017
@transition(field=state, source="new", target="published")
2118
def publish(self):
2219
pass
@@ -30,9 +27,6 @@ class ExtendedBlogPost(LockedBlogPost):
3027
review_state = FSMField(default="waiting", protected=True)
3128
notes = models.CharField(max_length=50)
3229

33-
class Meta:
34-
app_label = "testapp"
35-
3630
@transition(field=review_state, source="waiting", target="rejected")
3731
def reject(self):
3832
pass

tests/testapp/tests/test_mixin_support.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88

99

1010
class WorkflowMixin:
11-
class Meta:
12-
app_label = "testapp"
13-
1411
@transition(field="state", source="*", target="draft")
1512
def draft(self):
1613
pass

tests/testapp/tests/test_model_create_with_generic.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
from __future__ import annotations
22

3-
try:
4-
from django.contrib.contenttypes.fields import GenericForeignKey
5-
except ImportError:
6-
# Django 1.6
7-
from django.contrib.contenttypes.generic import GenericForeignKey
3+
from django.contrib.contenttypes.fields import GenericForeignKey
84
from django.contrib.contenttypes.models import ContentType
95
from django.db import models
106
from django.test import TestCase
@@ -13,9 +9,7 @@
139
from django_fsm import transition
1410

1511

16-
class Ticket(models.Model):
17-
class Meta:
18-
app_label = "testapp"
12+
class Ticket(models.Model): ...
1913

2014

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

32-
class Meta:
33-
app_label = "testapp"
34-
3526
@transition(field=state, source=TaskState.NEW, target=TaskState.DONE)
3627
def do(self):
3728
pass

tests/testapp/tests/test_multi_resultstate.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
class MultiResultTest(models.Model):
1515
state = FSMField(default="new")
1616

17-
class Meta:
18-
app_label = "testapp"
19-
2017
@transition(field=state, source="new", target=RETURN_VALUE("for_moderators", "published"))
2118
def publish(self, *, is_public=False):
2219
return "published" if is_public else "for_moderators"

tests/testapp/tests/test_multidecorators.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ class TestModel(models.Model):
1313
signal_counter = models.IntegerField(default=0)
1414
state = FSMField(default="SUBMITTED_BY_USER")
1515

16-
class Meta:
17-
app_label = "testapp"
18-
1916
@transition(field=state, source="SUBMITTED_BY_USER", target="REVIEW_USER")
2017
@transition(field=state, source="SUBMITTED_BY_ADMIN", target="REVIEW_ADMIN")
2118
@transition(field=state, source="SUBMITTED_BY_ANONYMOUS", target="REVIEW_ANONYMOUS")

tests/testapp/tests/test_object_permissions.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ class ObjectPermissionTestModel(models.Model):
1515
state = FSMField(default="new")
1616

1717
class Meta:
18-
app_label = "testapp"
19-
2018
permissions = [
2119
("can_publish_objectpermissiontestmodel", "Can publish ObjectPermissionTestModel"),
2220
]

tests/testapp/tests/test_permissions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def setUp(self):
1818
self.privileged.user_permissions.add(Permission.objects.get_by_natural_key("can_publish_post", "testapp", "blogpost"))
1919
self.privileged.user_permissions.add(Permission.objects.get_by_natural_key("can_remove_post", "testapp", "blogpost"))
2020

21-
def test_proviledged_access_succeed(self):
21+
def test_privileged_access_succeed(self):
2222
assert has_transition_perm(self.model.publish, self.privileged)
2323
assert has_transition_perm(self.model.remove, self.privileged)
2424

tests/testapp/tests/test_state_transitions.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ class STATE:
1616

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

19-
class Meta:
20-
app_label = "testapp"
21-
2219
@transition(field=state, source=STATE.CATERPILLAR, target=STATE.BUTTERFLY)
2320
def cocoon(self):
2421
pass
@@ -32,7 +29,6 @@ def crawl(self):
3229

3330
class Caterpillar(Insect):
3431
class Meta:
35-
app_label = "testapp"
3632
proxy = True
3733

3834
def crawl(self):
@@ -43,7 +39,6 @@ def crawl(self):
4339

4440
class Butterfly(Insect):
4541
class Meta:
46-
app_label = "testapp"
4742
proxy = True
4843

4944
def fly(self):
@@ -63,8 +58,12 @@ def test_transition_proxy_set_succeed(self):
6358
assert isinstance(insect, Butterfly)
6459

6560
def test_load_proxy_set(self):
66-
Insect.objects.create(state=Insect.STATE.CATERPILLAR)
67-
Insect.objects.create(state=Insect.STATE.BUTTERFLY)
61+
Insect.objects.bulk_create(
62+
[
63+
Insect(state=Insect.STATE.CATERPILLAR),
64+
Insect(state=Insect.STATE.BUTTERFLY),
65+
]
66+
)
6867

6968
insects = Insect.objects.all()
7069
assert {Caterpillar, Butterfly} == {insect.__class__ for insect in insects}

tests/testapp/tests/test_string_field_parameter.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
class BlogPostWithStringField(models.Model):
1111
state = FSMField(default="new")
1212

13-
class Meta:
14-
app_label = "testapp"
15-
1613
@transition(field="state", source="new", target="published", conditions=[])
1714
def publish(self):
1815
pass

tests/testapp/tests/test_transition_all_except_target.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111
class TestExceptTargetTransitionShortcut(models.Model):
1212
state = FSMField(default="new")
1313

14-
class Meta:
15-
app_label = "testapp"
16-
1714
@transition(field=state, source="new", target="published")
1815
def publish(self):
1916
pass

tests/testapp/views.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)