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

safe-global / safe-config-service / 5927002806

21 Aug 2023 01:35PM UTC coverage: 99.887% (+0.07%) from 99.816%
5927002806

Pull #925

github

schmanu
refactor: error into variable
Pull Request #925: feat: eip-1559 fixed gas prices

102 of 102 new or added lines in 6 files covered. (100.0%)

4436 of 4441 relevant lines covered (99.89%)

1.0 hits per line

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

96.67
/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 (
1✔
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