• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

safe-global / safe-config-service / 7528317545

11 Jan 2024 03:28PM UTC coverage: 99.757% (-0.02%) from 99.772%
7528317545

push

github

web-flow
Invalidate safe apps for removed chains (#1020)

- Decouples `post_delete` signal from the affected flow, as it remains as it is.
- Change the handling of `post_save` signal to handle `pre_save` signal, to have access to the instance's `Chain` list before the update is made.
- Both the `Chain` items related to the `SafeApp` before and after the update are stored in a `Set` to avoid repetitions. Hooks are dispatched for all the `Chain` items in the set.

4923 of 4935 relevant lines covered (99.76%)

1.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.55
/src/chains/migrations/tests/utils.py
1
from django.apps import apps
1✔
2
from django.db import connection
1✔
3
from django.db.migrations.executor import MigrationExecutor
1✔
4
from django.db.migrations.state import StateApps
1✔
5
from django.test import TestCase
1✔
6

7

8
# Use this TestCase class in order to test migrations
9
# migrate_from – the name of the migration where the test starts
10
# migrate_to – the target migration
11
#
12
# Example:
13
# You can set models on a specific migration inside your implementation of setUpBeforeMigration()
14
# The validation can then be performed on each test function of the Test class
15
# This class is heavily inspired by https://www.caktusgroup.com/blog/2016/02/02/writing-unit-tests-django-migrations/
16
class TestMigrations(TestCase):
1✔
17
    @property
1✔
18
    def app(self) -> str:
1✔
19
        app_config = apps.get_containing_app_config(type(self).__module__)
1✔
20
        if app_config is None:
1✔
21
            raise Exception("Could not retrieve app configuration")  # pragma: no cover
×
22
        return app_config.name
1✔
23

24
    migrate_from: str
1✔
25
    migrate_to: str
1✔
26
    apps_registry: StateApps
1✔
27

28
    def setUp(self) -> None:
1✔
29
        assert (
30
            self.migrate_from and self.migrate_to
1✔
31
        ), "TestCase '{}' must define migrate_from and migrate_to     properties".format(
32
            type(self).__name__
33
        )
34
        migrate_from: tuple[str, str] = (self.app, self.migrate_from)
1✔
35
        migrate_to: tuple[str, str] = (self.app, self.migrate_to)
1✔
36
        executor = MigrationExecutor(connection)
1✔
37
        old_apps = executor.loader.project_state(migrate_from).apps
1✔
38

39
        # Reverse to the original migration
40
        executor.migrate([migrate_from])
1✔
41

42
        self.setUpBeforeMigration(old_apps)
1✔
43

44
        # Run the migration to test
45
        executor = MigrationExecutor(connection)
1✔
46
        executor.loader.build_graph()  # reload.
1✔
47
        executor.migrate([migrate_to])
1✔
48

49
        self.apps_registry = executor.loader.project_state(migrate_to).apps
1✔
50

51
    def setUpBeforeMigration(self, apps: StateApps) -> None:
1✔
52
        pass  # pragma: no cover
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc