예제 #1
0
    def test_with_project(self):
        """Testing get_evolutions_path with project-provided evolutions"""
        custom_evolutions = {
            'django_evolution.tests.evolutions_app':
                'django_evolution.tests.evolutions_app.evolutions',
        }

        with self.settings(CUSTOM_EVOLUTIONS=custom_evolutions):
            self.assertEqual(get_evolutions_path(get_app('evolutions_app')),
                             os.path.join(self.base_dir, 'tests',
                                          'evolutions_app', 'evolutions'))
예제 #2
0
 def test_with_not_found(self):
     """Testing get_evolutions_path with evolutions not found"""
     self.assertIsNone(get_evolutions_path(get_app('migrations_app')))
예제 #3
0
 def test_with_builtin(self):
     """Testing get_evolutions_path with built-in evolutions"""
     self.assertEqual(get_evolutions_path(get_app('auth')),
                      os.path.join(self.base_dir, 'builtin_evolutions'))
예제 #4
0
 def test_with_app(self):
     """Testing get_evolutions_path with app-provided evolutions"""
     self.assertEqual(get_evolutions_path(get_app('django_evolution')),
                      os.path.join(self.base_dir, 'evolutions'))
예제 #5
0
    def _generate_evolution_contents(self, evolution_label=None):
        """Generate the contents of evolution files or hinted evolutions.

        This will grab the contents of either the stored evolution files
        or hinted evolutions (if using ``--hint``) and write them to the
        console or to generated evolution files (if using ``--write``).

        Args:
            evolution_label (unicode, optional):
                The label used as a base for any generated filenames.
                If provided, the filenames will be written to the appropriate
                evolution directories, with a ``.py`` appended.

        Raises:
            django.core.management.base.CommandError:
                An evolution file couldn't be written. Details are in the
                error message.
        """
        evolution_contents = self.evolver.iter_evolution_content()

        if evolution_label:
            # We're writing the hinted evolution files to disk. Notify the user
            # and begin writing.
            verbosity = self.verbosity

            if verbosity > 0:
                self.stdout.write('\n%s\n\n' % self._wrap_paragraphs(
                    _('The following evolution files were written. Verify the '
                      'contents and add them to the SEQUENCE lists in each '
                      '__init__.py.')))

            for task, content in evolution_contents:
                assert hasattr(task, 'app')

                dirname = get_evolutions_path(task.app)
                filename = os.path.join(dirname, '%s.py' % evolution_label)

                if not os.path.exists(dirname):
                    try:
                        os.mkdir(dirname, 0o755)
                    except IOError as e:
                        raise CommandError(
                            _('Unable to create evolutions directory "%s": %s')
                            % (dirname, e))

                try:
                    with open(filename, 'w') as fp:
                        fp.write(content.strip())
                        fp.write('\n')
                except Exception as e:
                    raise CommandError(
                        _('Unable to write evolution file "%s": %s') %
                        (filename, e))

                if verbosity > 0:
                    self.stdout.write('  * %s\n' % os.path.relpath(filename))
        else:
            # We're just going to output the hint content.
            for i, (task, content) in enumerate(evolution_contents):
                assert hasattr(task, 'app_label')

                self.stdout.write('#----- Evolution for %s\n' % task.app_label)
                self.stdout.write(content.strip())
                self.stdout.write('#----------------------\n')

            self.stdout.write('\n')
예제 #6
0
    def _generate_evolution_contents(self, evolution_label=None):
        """Generate the contents of evolution files or hinted evolutions.

        This will grab the contents of either the stored evolution files
        or hinted evolutions (if using ``--hint``) and write them to the
        console or to generated evolution files (if using ``--write``).

        Args:
            evolution_label (unicode, optional):
                The label used as a base for any generated filenames.
                If provided, the filenames will be written to the appropriate
                evolution directories, with a ``.py`` appended.

        Raises:
            django.core.management.base.CommandError:
                An evolution file couldn't be written. Details are in the
                error message.
        """
        evolution_contents = self.evolver.iter_evolution_content()

        if evolution_label:
            # We're writing the hinted evolution files to disk. Notify the user
            # and begin writing.
            verbosity = self.verbosity

            if verbosity > 0:
                self.stdout.write('\n%s\n\n' % self._wrap_paragraphs(_(
                    'The following evolution files were written. Verify the '
                    'contents and add them to the SEQUENCE lists in each '
                    '__init__.py.')))

            for task, content in evolution_contents:
                assert hasattr(task, 'app')

                dirname = get_evolutions_path(task.app)
                filename = os.path.join(dirname, '%s.py' % evolution_label)

                if not os.path.exists(dirname):
                    try:
                        os.mkdir(dirname, 0o755)
                    except IOError as e:
                        raise CommandError(
                            _('Unable to create evolutions directory "%s": %s')
                            % (dirname, e))

                try:
                    with open(filename, 'w') as fp:
                        fp.write(content.strip())
                        fp.write('\n')
                except Exception as e:
                    raise CommandError(
                        _('Unable to write evolution file "%s": %s')
                        % (filename, e))

                if verbosity > 0:
                    self.stdout.write('  * %s\n' % os.path.relpath(filename))
        else:
            # We're just going to output the hint content.
            for i, (task, content) in enumerate(evolution_contents):
                assert hasattr(task, 'app_label')

                self.stdout.write('#----- Evolution for %s\n' % task.app_label)
                self.stdout.write(content.strip())
                self.stdout.write('#----------------------\n')

            self.stdout.write('\n')