From f610151141edb416e0f619b34c5c656dba3b81d7 Mon Sep 17 00:00:00 2001 From: Pascal F Date: Tue, 3 Jun 2025 16:26:10 +0200 Subject: [PATCH] Add basic test of graph_transitions (and centralize tests) --- .../management/commands/graph_transitions.py | 2 +- django_fsm/tests/__init__.py | 0 .../tests/test_abstract_inheritance.py | 0 .../testapp}/tests/test_basic_transitions.py | 12 ++--- .../testapp}/tests/test_conditions.py | 0 tests/testapp/tests/test_graph_transitions.py | 49 +++++++++++++++++++ .../testapp}/tests/test_integer_field.py | 0 .../testapp}/tests/test_key_field.py | 0 .../testapp}/tests/test_protected_field.py | 0 .../testapp}/tests/test_protected_fields.py | 0 .../testapp}/tests/test_proxy_inheritance.py | 0 11 files changed, 56 insertions(+), 7 deletions(-) delete mode 100644 django_fsm/tests/__init__.py rename {django_fsm => tests/testapp}/tests/test_abstract_inheritance.py (100%) rename {django_fsm => tests/testapp}/tests/test_basic_transitions.py (97%) rename {django_fsm => tests/testapp}/tests/test_conditions.py (100%) create mode 100644 tests/testapp/tests/test_graph_transitions.py rename {django_fsm => tests/testapp}/tests/test_integer_field.py (100%) rename {django_fsm => tests/testapp}/tests/test_key_field.py (100%) rename {django_fsm => tests/testapp}/tests/test_protected_field.py (100%) rename {django_fsm => tests/testapp}/tests/test_protected_fields.py (100%) rename {django_fsm => tests/testapp}/tests/test_proxy_inheritance.py (100%) diff --git a/django_fsm/management/commands/graph_transitions.py b/django_fsm/management/commands/graph_transitions.py index 21a191d..467cc80 100644 --- a/django_fsm/management/commands/graph_transitions.py +++ b/django_fsm/management/commands/graph_transitions.py @@ -114,7 +114,7 @@ def get_graphviz_layouts(): except ModuleNotFoundError: return {"sfdp", "circo", "twopi", "dot", "neato", "fdp", "osage", "patchwork"} else: - return graphviz.backend.ENGINES + return graphviz.ENGINES class Command(BaseCommand): diff --git a/django_fsm/tests/__init__.py b/django_fsm/tests/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/django_fsm/tests/test_abstract_inheritance.py b/tests/testapp/tests/test_abstract_inheritance.py similarity index 100% rename from django_fsm/tests/test_abstract_inheritance.py rename to tests/testapp/tests/test_abstract_inheritance.py diff --git a/django_fsm/tests/test_basic_transitions.py b/tests/testapp/tests/test_basic_transitions.py similarity index 97% rename from django_fsm/tests/test_basic_transitions.py rename to tests/testapp/tests/test_basic_transitions.py index ce1a37a..0414029 100644 --- a/django_fsm/tests/test_basic_transitions.py +++ b/tests/testapp/tests/test_basic_transitions.py @@ -12,7 +12,7 @@ from django_fsm.signals import pre_transition -class BlogPost(models.Model): +class SimpleBlogPost(models.Model): state = FSMField(default="new") @transition(field=state, source="new", target="published") @@ -50,7 +50,7 @@ def empty(self): class FSMFieldTest(TestCase): def setUp(self): - self.model = BlogPost() + self.model = SimpleBlogPost() def test_initial_state_instantiated(self): self.assertEqual(self.model.state, "new") @@ -121,11 +121,11 @@ def test_empty_string_target(self): class StateSignalsTests(TestCase): def setUp(self): - self.model = BlogPost() + self.model = SimpleBlogPost() self.pre_transition_called = False self.post_transition_called = False - pre_transition.connect(self.on_pre_transition, sender=BlogPost) - post_transition.connect(self.on_post_transition, sender=BlogPost) + pre_transition.connect(self.on_pre_transition, sender=SimpleBlogPost) + post_transition.connect(self.on_post_transition, sender=SimpleBlogPost) def on_pre_transition(self, sender, instance, name, source, target, **kwargs): self.assertEqual(instance.state, source) @@ -148,7 +148,7 @@ def test_signals_not_called_on_invalid_transition(self): class TestFieldTransitionsInspect(TestCase): def setUp(self): - self.model = BlogPost() + self.model = SimpleBlogPost() def test_in_operator_for_available_transitions(self): # store the generator in a list, so we can reuse the generator and do multiple asserts diff --git a/django_fsm/tests/test_conditions.py b/tests/testapp/tests/test_conditions.py similarity index 100% rename from django_fsm/tests/test_conditions.py rename to tests/testapp/tests/test_conditions.py diff --git a/tests/testapp/tests/test_graph_transitions.py b/tests/testapp/tests/test_graph_transitions.py new file mode 100644 index 0000000..e814a11 --- /dev/null +++ b/tests/testapp/tests/test_graph_transitions.py @@ -0,0 +1,49 @@ +from __future__ import annotations + +from django.core.management import call_command +from django.db import models +from django.test import TestCase + +from django_fsm import FSMField +from django_fsm import transition + + +class VisualBlogPost(models.Model): + state = FSMField(default="new") + + @transition(field=state, source="new", target="published") + def publish(self): + pass + + @transition(source="published", field=state) + def notify_all(self): + pass + + @transition(source="published", target="hidden", field=state) + def hide(self): + pass + + @transition(source="new", target="removed", field=state) + def remove(self): + raise Exception("Upss") + + @transition(source=["published", "hidden"], target="stolen", field=state) + def steal(self): + pass + + @transition(source="*", target="moderated", field=state) + def moderate(self): + pass + + @transition(source="+", target="blocked", field=state) + def block(self): + pass + + @transition(source="*", target="", field=state) + def empty(self): + pass + + +class GraphTransitionsCommandTest(TestCase): + def test_dummy(self): + call_command("graph_transitions", "testapp.VisualBlogPost") diff --git a/django_fsm/tests/test_integer_field.py b/tests/testapp/tests/test_integer_field.py similarity index 100% rename from django_fsm/tests/test_integer_field.py rename to tests/testapp/tests/test_integer_field.py diff --git a/django_fsm/tests/test_key_field.py b/tests/testapp/tests/test_key_field.py similarity index 100% rename from django_fsm/tests/test_key_field.py rename to tests/testapp/tests/test_key_field.py diff --git a/django_fsm/tests/test_protected_field.py b/tests/testapp/tests/test_protected_field.py similarity index 100% rename from django_fsm/tests/test_protected_field.py rename to tests/testapp/tests/test_protected_field.py diff --git a/django_fsm/tests/test_protected_fields.py b/tests/testapp/tests/test_protected_fields.py similarity index 100% rename from django_fsm/tests/test_protected_fields.py rename to tests/testapp/tests/test_protected_fields.py diff --git a/django_fsm/tests/test_proxy_inheritance.py b/tests/testapp/tests/test_proxy_inheritance.py similarity index 100% rename from django_fsm/tests/test_proxy_inheritance.py rename to tests/testapp/tests/test_proxy_inheritance.py