Esempio n. 1
0
 def test_without_dependencies_and_custom_evolutions(self):
     """Testing get_evolution_dependencies without dependencies"""
     self.assertEqual(
         get_evolution_dependencies(get_app('app_deps_app'),
                                    'test_evolution'),
         {
             'after_evolutions': set(),
             'after_migrations': set(),
             'before_evolutions': set(),
             'before_migrations': set(),
         })
Esempio n. 2
0
 def test_with_dependencies_and_custom_evolutions(self):
     """Testing get_evolution_dependencies with dependencies and custom
     evolutions
     """
     self.assertEqual(
         get_evolution_dependencies(
             app=get_app('evolution_deps_app'),
             evolution_label='test_custom_evolution',
             custom_evolutions=[
                 {
                     'label': 'test_custom_evolution',
                     'after_evolutions': [
                         ('other_app1', 'other_evolution1'),
                         ('other_app1', 'other_evolution2'),
                     ],
                     'after_migrations': [
                         ('other_app2', '0001_migration'),
                         ('other_app2', '0002_migration'),
                     ],
                     'before_evolutions': [
                         ('other_app3', 'other_evolution3'),
                         ('other_app3', 'other_evolution4'),
                     ],
                     'before_migrations': [
                         ('other_app4', '0003_migration'),
                         ('other_app4', '0004_migration'),
                     ],
                     'mutations': [
                         AddField('MyModel', 'new_field',
                                  models.BooleanField),
                     ],
                 },
             ]),
         {
             'after_evolutions': {
                 ('other_app1', 'other_evolution1'),
                 ('other_app1', 'other_evolution2'),
             },
             'after_migrations': {
                 ('other_app2', '0001_migration'),
                 ('other_app2', '0002_migration'),
             },
             'before_evolutions': {
                 ('other_app3', 'other_evolution3'),
                 ('other_app3', 'other_evolution4'),
             },
             'before_migrations': {
                 ('other_app4', '0003_migration'),
                 ('other_app4', '0004_migration'),
             },
         })
Esempio n. 3
0
    def _add_evolution(self,
                       app,
                       evolution,
                       extra_state={},
                       custom_evolutions=[]):
        """Add a node for an evolution.

        Node dependencies will be registered based on any evolution/migration
        dependencies defined by this evolution.

        Args:
            app (module):
                The app module the evolution applies to.

            evolution (django_evolution.models.Evolution):
                The evolution to add.

            extra_state (dict, optional):
                Extra state to set in the evolution node.

            custom_evolutions (list of dict, optional):
                An optional list of custom evolutions for the app, for
                dependency resolution.

                Version Added:
                    2.2

        Returns:
            Node:
            The resulting node.
        """
        key = self._make_evolution_key(evolution)
        node = self.add_node(key=key,
                             state=dict(
                                 {
                                     'app': app,
                                     'evolution': evolution,
                                     'type': self.NODE_TYPE_EVOLUTION,
                                 }, **extra_state))

        # Begin adding any dependencies between this evolution and any other
        # evolution or migration.
        deps = get_evolution_dependencies(app=app,
                                          evolution_label=evolution.label,
                                          custom_evolutions=custom_evolutions)

        if deps:
            self._add_evolution_node_before_deps(node, deps)
            self._add_evolution_node_after_deps(node, deps)

        return node
Esempio n. 4
0
 def test_with_move_to_django_migrations(self):
     """Testing get_evolution_dependencies with MoveToDjangoMigrations
     mutation
     """
     self.assertEqual(
         get_evolution_dependencies(get_app('admin'),
                                    'admin_move_to_migrations'),
         {
             'after_evolutions': set(),
             'after_migrations': {
                 ('admin', '0001_initial'),
             },
             'before_evolutions': set(),
             'before_migrations': set(),
         })
Esempio n. 5
0
 def test_without_dependencies(self):
     """Testing get_evolution_dependencies without dependencies"""
     self.assertEqual(
         get_evolution_dependencies(
             app=get_app('app_deps_app'),
             evolution_label='test_evolution',
             custom_evolutions=[
                 {
                     'label': 'test_custom_evolution',
                     'mutations': [
                         AddField('MyModel', 'new_field',
                                  models.BooleanField),
                     ],
                 },
             ]),
         {
             'after_evolutions': set(),
             'after_migrations': set(),
             'before_evolutions': set(),
             'before_migrations': set(),
         })
Esempio n. 6
0
 def test_with_dependencies(self):
     """Testing get_evolution_dependencies with dependencies"""
     self.assertEqual(
         get_evolution_dependencies(get_app('evolution_deps_app'),
                                    'test_evolution'),
         {
             'after_evolutions': {
                 'evolutions_app',
                 ('evolutions_app', 'first_evolution'),
             },
             'after_migrations': {
                 ('migrations_app', '0001_initial'),
             },
             'before_evolutions': {
                 'evolutions_app2',
                 ('evolutions_app2', 'second_evolution'),
             },
             'before_migrations': {
                 ('migrations_app2', '0002_add_field'),
             },
         })
Esempio n. 7
0
 def test_with_invalid_evolution(self):
     """Testing get_evolution_dependencies with invalid evolution name"""
     self.assertIsNone(
         get_evolution_dependencies(app=get_app('django_evolution'),
                                    evolution_label='invalid_evolution'))
Esempio n. 8
0
 def test_with_invalid_app(self):
     """Testing get_evolution_dependencies with non-evolution app"""
     self.assertIsNone(
         get_evolution_dependencies(app=get_app('migrations_app'),
                                    evolution_label='invalid_evolution'))