diff --git a/.travis.yml b/.travis.yml index 5fea858..de36ce3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,31 +1,37 @@ sudo: false language: python +dist: xenial matrix: include: - - python: 2.7 - env: TOXENV=py27-django110 - python: 2.7 env: TOXENV=py27-django111 - - python: 3.4 - env: TOXENV=py34-django110 - python: 3.4 env: TOXENV=py34-django111 - python: 3.4 env: TOXENV=py34-django20 - - python: 3.5 - env: TOXENV=py35-django110 - python: 3.5 env: TOXENV=py35-django111 - python: 3.5 env: TOXENV=py35-django20 + - python: 3.5 + env: TOXENV=py35-django21 - python: 3.6 env: TOXENV=py36-django111 - python: 3.6 env: TOXENV=py36-django20 + - python: 3.6 + env: TOXENV=py36-django21 + + - python: 3.7 + env: TOXENV=py37-django111 + - python: 3.7 + env: TOXENV=py37-django20 + - python: 3.7 + env: TOXENV=py37-django21 - python: 3.6 env: TOXENV=lint diff --git a/README.rst b/README.rst index 30875a0..996762f 100644 --- a/README.rst +++ b/README.rst @@ -44,12 +44,54 @@ Usage ``--exclude-apps EXCLUDE_APPS [EXCLUDE_APPS ...]`` Ignore migrations that are in the specified django apps. ``--verbose or -v`` Print more information during execution. ``--database DATABASE`` Specify the database for which to generate the SQL. Defaults to *default*. +``--cache-path PATH`` specify a directory that should be used to store cache-files in. +``--no-cache`` Don't use a cache. ================================================== =========================================================================================================================== Examples -------- -3YOURMIND is running the linter on `Bitbucket Pipelines`_ on every build getting pushed. +3YOURMIND is running the linter on every build getting pushed through CI. +Checkout the ``examples/`` folder to see how you could integrate the linter in your test suite. + +Backward incompatible migrations +-------------------------------- + +The linter analyses your migrations and checks the SQL for: + +- Added ``NOT NULL`` columns, which don't have a DEFAULT value +- Dropping columns +- Renaming columns +- Renaming tables +- Altering columns (which can be backward compatible and eventually ignored) + +Those are the most important and frequent backward incompatible migrations. We are happy to add more if you have some. + +Ignoring migrations +------------------- + +You can also ignore migrations by adding this to your migrations: + +.. code-block:: + + import django_migration_linter as linter + # ... + + operations = [ + linter.IgnoreMigration(), + # ... + ] + # ... + +Cache +----- +By default, the linter uses a cache to prevent linting the same migration again. +The default location of the cache on Linux is +``/home//.cache/django-migration-linter//.pickle``. + +Since the linter uses hashes, modifying migration files, will re-run the linter on that migration. +If you want to run the linter without cache, use the flag ``--no-cache``. +If you want to invalidate the cache, delete the cache folder. Tests ----- @@ -60,7 +102,7 @@ Contributing ------------ First, thank you very much if you want to contribute to the project. -Please base your work on the ``dev`` branch and also target this branch in your pull request. +Please base your work on the ``master`` branch and also target this branch in your pull request. License ------- @@ -68,6 +110,5 @@ License *django-migration-linter* is released under the `Apache 2.0 License`_. -.. _`Bitbucket Pipelines`: https://bitbucket.org/product/features/pipelines .. _`tox`: https://pypi.python.org/pypi/tox .. _`Apache 2.0 License`: https://github.com/3YOURMIND/django-migration-linter/blob/master/LICENSE diff --git a/django_migration_linter/__init__.py b/django_migration_linter/__init__.py index 959bac8..4060d62 100644 --- a/django_migration_linter/__init__.py +++ b/django_migration_linter/__init__.py @@ -1,4 +1,4 @@ -# Copyright 2018 3YOURMIND GmbH +# Copyright 2019 3YOURMIND GmbH # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -13,3 +13,4 @@ # limitations under the License. from .migration_linter import * # noqa +from .operations import * # noqa diff --git a/django_migration_linter/cache.py b/django_migration_linter/cache.py new file mode 100644 index 0000000..892e2df --- /dev/null +++ b/django_migration_linter/cache.py @@ -0,0 +1,50 @@ +# Copyright 2019 3YOURMIND GmbH + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import hashlib +import os +import pickle + +from .utils import split_path + + +class Cache(dict): + def __init__(self, django_folder, cache_path): + self.django_folder = django_folder + project_name = split_path(django_folder)[-1] + self.filename = os.path.join(cache_path, "{0}.pickle".format(project_name)) + + if not os.path.exists(os.path.dirname(self.filename)): + os.makedirs(os.path.dirname(self.filename)) + + super(Cache, self).__init__() + + def load(self): + try: + with open(self.filename, "rb") as f: + tmp_dict = pickle.load(f) + self.update(tmp_dict) + except IOError: + pass + + def save(self): + with open(self.filename, "wb") as f: + pickle.dump(self, f, protocol=2) + + def md5(self, path): + hash_md5 = hashlib.md5() + with open(path, "rb") as f: + for chunk in iter(lambda: f.read(4096), b""): + hash_md5.update(chunk) + return hash_md5.hexdigest() diff --git a/django_migration_linter/constants.py b/django_migration_linter/constants.py new file mode 100644 index 0000000..3260131 --- /dev/null +++ b/django_migration_linter/constants.py @@ -0,0 +1,21 @@ +# Copyright 2019 3YOURMIND GmbH + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from appdirs import user_cache_dir + +__version__ = "0.1.2" + +MIGRATION_FOLDER_NAME = "migrations" + +DEFAULT_CACHE_PATH = user_cache_dir("django-migration-linter", version=__version__) diff --git a/django_migration_linter/migration.py b/django_migration_linter/migration.py new file mode 100644 index 0000000..004f64c --- /dev/null +++ b/django_migration_linter/migration.py @@ -0,0 +1,12 @@ +from django_migration_linter.utils import split_migration_path + + +class Migration(object): + def __init__(self, abs_path): + self.abs_path = abs_path + self.app_name, self.name = split_migration_path(self.abs_path) + + def __lt__(self, other): + if not isinstance(other, Migration): + return NotImplemented + return self.abs_path < other.abs_path diff --git a/django_migration_linter/migration_linter.py b/django_migration_linter/migration_linter.py index f37a5bf..f9c0ab1 100644 --- a/django_migration_linter/migration_linter.py +++ b/django_migration_linter/migration_linter.py @@ -1,4 +1,4 @@ -# Copyright 2018 3YOURMIND GmbH +# Copyright 2019 3YOURMIND GmbH # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,35 +18,47 @@ import os import re from subprocess import Popen, PIPE import sys -from . import utils + +from .cache import Cache +from .constants import DEFAULT_CACHE_PATH, MIGRATION_FOLDER_NAME +from .migration import Migration +from .utils import is_directory, is_django_project, clean_bytes_to_str from .sql_analyser import analyse_sql_statements -log = logging.getLogger(__name__) +logger = logging.getLogger(__name__) class MigrationLinter(object): - MIGRATION_FOLDER_NAME = 'migrations' - def __init__(self, project_path, **kwargs): # Verify correctness - if not utils.is_directory(project_path): + if not is_directory(project_path): raise ValueError( - 'The given path {0} does not seem to be a directory.'.format( - project_path)) - if not utils.is_django_project(project_path): + "The given path {0} does not seem to be a directory.".format( + project_path + ) + ) + if not is_django_project(project_path): raise ValueError( - ('The given path {0} does not ' - 'seem to be a django project.').format(project_path)) + ("The given path {0} does not " "seem to be a django project.").format( + project_path + ) + ) # Store parameters and options - self.django_path = project_path - self.ignore_name_contains = kwargs.get('ignore_name_contains', None) - self.ignore_name = kwargs.get('ignore_name', None) or tuple() - self.include_apps = kwargs.get('include_apps', None) - self.exclude_apps = kwargs.get('exclude_apps', None) - self.database = kwargs.get('database', None) or 'default' - self.python_exe = '{0}/bin/{1}'.format(sys.prefix, 'python') if \ - hasattr(sys, 'real_prefix') else 'python' + self.django_path = os.path.abspath(project_path) + self.ignore_name_contains = kwargs.get("ignore_name_contains", None) + self.ignore_name = kwargs.get("ignore_name", None) or tuple() + self.include_apps = kwargs.get("include_apps", None) + self.exclude_apps = kwargs.get("exclude_apps", None) + self.database = kwargs.get("database", None) or "default" + self.cache_path = kwargs.get("cache_path", None) or DEFAULT_CACHE_PATH + self.no_cache = kwargs.get("no_cache", None) or False + + self.python_exe = ( + "{0}/bin/{1}".format(sys.prefix, "python") + if hasattr(sys, "real_prefix") + else "python" + ) # Initialise counters self.nb_valid = 0 @@ -54,62 +66,96 @@ class MigrationLinter(object): self.nb_erroneous = 0 self.nb_total = 0 - def lint_migration(self, app_name, migration_name): - print('({0}, {1})... '.format(app_name, migration_name), end='') + # Initialise cache. Read from old, write to new to prune old entries. + self.old_cache = Cache(self.django_path, self.cache_path) + self.new_cache = Cache(self.django_path, self.cache_path) + if not self.no_cache: + self.old_cache.load() + + def lint_migration(self, migration): + app_name = migration.app_name + migration_name = migration.name + print("({0}, {1})... ".format(app_name, migration_name), end="") self.nb_total += 1 + md5hash = self.old_cache.md5(migration.abs_path) + if md5hash in self.old_cache: + if self.old_cache[md5hash]["result"] == "IGNORE": + print("IGNORE (cached)") + self.nb_ignored += 1 + elif self.old_cache[md5hash]["result"] == "OK": + print("OK (cached)") + self.nb_valid += 1 + else: + print("ERR (cached)") + self.nb_erroneous += 1 + + if "errors" in self.old_cache[md5hash]: + self.print_errors(self.old_cache[md5hash]["errors"]) + + self.new_cache[md5hash] = self.old_cache[md5hash] + return + if self.should_ignore_migration(app_name, migration_name): - print('IGNORE') + print("IGNORE") + self.nb_ignored += 1 + return + + sql_statements = self.get_sql(app_name, migration_name) + analysis_result = analyse_sql_statements(sql_statements) + errors = analysis_result["errors"] + + if analysis_result["ignored"]: + print("IGNORE") + self.new_cache[md5hash] = {"result": "IGNORE"} self.nb_ignored += 1 return - sql_statements = self.get_sql( - app_name, migration_name) - analysis_result = analyse_sql_statements( - sql_statements) - errors = analysis_result['errors'] if not errors: - print('OK') + print("OK") + self.new_cache[md5hash] = {"result": "OK"} self.nb_valid += 1 return - # Print errors - print('ERR') + print("ERR") + self.new_cache[md5hash] = {"result": "ERR", "errors": errors} self.nb_erroneous += 1 + self.print_errors(errors) + + @staticmethod + def print_errors(errors): for err in errors: - error_str = '\t{0}'.format(err['err_msg']) - if err['table']: - error_str += ' (table: {0}'.format(err['table']) - if err['column']: - error_str += ', column: {0}'.format( - err['column']) - error_str += ')' + error_str = "\t{0}".format(err["err_msg"]) + if err["table"]: + error_str += " (table: {0}".format(err["table"]) + if err["column"]: + error_str += ", column: {0}".format(err["column"]) + error_str += ")" print(error_str) def lint_all_migrations(self, git_commit_id=None): # Collect migrations if git_commit_id: - if not utils.is_git_project(self.django_path): - raise ValueError( - ('The given project {0} does not seem ' - 'to be versioned by git.').format(self.django_path)) migrations = self._gather_migrations_git(git_commit_id) else: migrations = self._gather_all_migrations() # Lint those migrations for m in migrations: - self.lint_migration(*m) + self.lint_migration(m) + + if not self.no_cache: + self.new_cache.save() def print_summary(self): - print('*** Summary:') - print(('Valid migrations: {1}/{0} - ' - 'erroneous migrations: {2}/{0} - ' - 'ignored migrations: {3}/{0}').format( - self.nb_total, - self.nb_valid, - self.nb_erroneous, - self.nb_ignored)) + print("*** Summary:") + print( + ( + "Valid migrations: {1}/{0} - " + "erroneous migrations: {2}/{0} - " + "ignored migrations: {3}/{0}" + ).format(self.nb_total, self.nb_valid, self.nb_erroneous, self.nb_ignored) + ) @property def has_errors(self): @@ -128,148 +174,157 @@ class MigrationLinter(object): it allows to seperate the instances correctly. """ sqlmigrate_command = ( - 'cd {0} && ' - '{1} manage.py sqlmigrate {2} {3} ' - '--database {4}').format( - self.django_path, - self.python_exe, app_name, migration_name, - self.database) - log.info('Executing {0}'.format(sqlmigrate_command)) + "cd {0} && {1} manage.py sqlmigrate {2} {3} " "--database {4}" + ).format( + self.django_path, self.python_exe, app_name, migration_name, self.database + ) + logger.info("Executing {0}".format(sqlmigrate_command)) sqlmigrate_process = Popen( - sqlmigrate_command, shell=True, stdout=PIPE, stderr=PIPE) + sqlmigrate_command, shell=True, stdout=PIPE, stderr=PIPE + ) sql_statements = [] - for line in map( - utils.clean_bytes_to_str, - sqlmigrate_process.stdout.readlines()): + for line in map(clean_bytes_to_str, sqlmigrate_process.stdout.readlines()): sql_statements.append(line) sqlmigrate_process.wait() if sqlmigrate_process.returncode != 0: _, err = sqlmigrate_process.communicate() - raise RuntimeError('sqlmigrate command failed {0}'.format( - err.decode('utf-8'))) - log.info('Found {0} sql migration lines'.format(len(sql_statements))) + raise RuntimeError( + "sqlmigrate command failed {0}".format(err.decode("utf-8")) + ) + logger.info("Found {0} sql migration lines".format(len(sql_statements))) return sql_statements def _gather_migrations_git(self, git_commit_id): migrations = [] # Get changes since specified commit git_diff_command = ( - 'cd {0} && ' - 'git diff --name-only --diff-filter=A {1}').format( - self.django_path, git_commit_id) - log.info('Executing {0}'.format(git_diff_command)) - diff_process = Popen( - git_diff_command, shell=True, stdout=PIPE, stderr=PIPE) - for line in map( - utils.clean_bytes_to_str, diff_process.stdout.readlines()): + "cd {0} && git diff --relative --name-only --diff-filter=A {1}" + ).format(self.django_path, git_commit_id) + logger.info("Executing {0}".format(git_diff_command)) + diff_process = Popen(git_diff_command, shell=True, stdout=PIPE, stderr=PIPE) + for line in map(clean_bytes_to_str, diff_process.stdout.readlines()): # Only gather lines that include added migrations - if re.search( - '\/{0}\/.*\.py'.format(self.MIGRATION_FOLDER_NAME), - line) and \ - '__init__' not in line: - app_name, migration_name = self._split_migration_path(line) - migrations.append((app_name, migration_name)) + if ( + re.search(r"\/{0}\/.*\.py".format(MIGRATION_FOLDER_NAME), line) + and "__init__" not in line + ): + migrations.append(Migration(os.path.join(self.django_path, line))) diff_process.wait() if diff_process.returncode != 0: output = [] - for line in map( - utils.clean_bytes_to_str, diff_process.stderr.readlines()): + for line in map(clean_bytes_to_str, diff_process.stderr.readlines()): output.append(line) - log.info("Error while git diff command:\n{}".format( - "".join(output))) - raise Exception('Error while executing git diff command') + logger.error("Error while git diff command:\n{}".format("".join(output))) + raise Exception("Error while executing git diff command") return migrations def _gather_all_migrations(self): migrations = [] for root, dirs, files in os.walk(self.django_path): - for file_name in files: - if os.path.basename(root) == self.MIGRATION_FOLDER_NAME and \ - file_name.endswith('.py') and \ - file_name != '__init__.py': + for file_name in sorted(files): + if ( + os.path.basename(root) == MIGRATION_FOLDER_NAME + and file_name.endswith(".py") + and file_name != "__init__.py" + ): full_migration_path = os.path.join(root, file_name) - app_name, migration_name = self._split_migration_path( - full_migration_path) - migrations.append((app_name, migration_name)) + migrations.append(Migration(full_migration_path)) return migrations def should_ignore_migration(self, app_name, migration_name): - return (self.include_apps and - app_name not in self.include_apps)\ - or (self.exclude_apps and - app_name in self.exclude_apps)\ - or (self.ignore_name_contains and - self.ignore_name_contains in migration_name)\ + return ( + (self.include_apps and app_name not in self.include_apps) + or (self.exclude_apps and app_name in self.exclude_apps) + or ( + self.ignore_name_contains + and self.ignore_name_contains in migration_name + ) or (migration_name in self.ignore_name) - - @classmethod - def _split_migration_path(cls, migration_path): - decomposed_path = utils.split_path(migration_path) - for i, p in enumerate(decomposed_path): - if p == cls.MIGRATION_FOLDER_NAME: - return (decomposed_path[i-1], - os.path.splitext(decomposed_path[i+1])[0]) + ) def _main(): import argparse + parser = argparse.ArgumentParser( - description='Detect backward incompatible django migrations.') + description="Detect backward incompatible django migrations." + ) parser.add_argument( - 'django_folder', - metavar='DJANGO_FOLDER', + "django_folder", + metavar="DJANGO_FOLDER", type=str, nargs=1, - help='the path to the django project') + help="the path to the django project", + ) parser.add_argument( - 'commit_id', - metavar='GIT_COMMIT_ID', - type=str, nargs='?', - help=('if specified, only migrations since this commit ' - 'will be taken into account. If not specified, ' - 'the initial repo commit will be used')) - parser.add_argument( - '--ignore-name-contains', + "commit_id", + metavar="GIT_COMMIT_ID", type=str, - nargs='?', - help='ignore migrations containing this name') + nargs="?", + help=( + "if specified, only migrations since this commit " + "will be taken into account. If not specified, " + "the initial repo commit will be used" + ), + ) parser.add_argument( - '--ignore-name', + "--ignore-name-contains", type=str, - nargs='*', - help='ignore migrations with exactly one of these names') + nargs="?", + help="ignore migrations containing this name", + ) parser.add_argument( - '--verbose', - '-v', - action='store_true', - help='print more information during execution') - parser.add_argument( - '--database', + "--ignore-name", type=str, - nargs='?', - help=('specify the database for which to generate the SQL. ' - 'Defaults to default')) + nargs="*", + help="ignore migrations with exactly one of these names", + ) + parser.add_argument( + "--verbose", + "-v", + action="store_true", + help="print more information during execution", + ) + parser.add_argument( + "--database", + type=str, + nargs="?", + help=( + "specify the database for which to generate the SQL. " "Defaults to default" + ), + ) - incl_excl_group = parser.add_mutually_exclusive_group( - required=False) - incl_excl_group.add_argument( - '--include-apps', + cache_group = parser.add_mutually_exclusive_group(required=False) + cache_group.add_argument( + "--cache-path", type=str, - nargs='*', - help='check only migrations that are in the specified django apps') + help="specify a directory that should be used to" "store cache-files in.", + ) + cache_group.add_argument( + "--no-cache", action="store_true", help="don't use a cache" + ) + + incl_excl_group = parser.add_mutually_exclusive_group(required=False) incl_excl_group.add_argument( - '--exclude-apps', + "--include-apps", type=str, - nargs='*', - help='ignore migrations that are in the specified django apps') + nargs="*", + help="check only migrations that are in the specified django apps", + ) + incl_excl_group.add_argument( + "--exclude-apps", + type=str, + nargs="*", + help="ignore migrations that are in the specified django apps", + ) args = parser.parse_args() if args.verbose: - logging.basicConfig(format='%(message)s', level=logging.DEBUG) + logging.basicConfig(format="%(message)s", level=logging.DEBUG) else: - logging.basicConfig(format='%(message)s') + logging.basicConfig(format="%(message)s") folder_name = args.django_folder[0] # Create and use linter @@ -279,13 +334,15 @@ def _main(): ignore_name=args.ignore_name, include_apps=args.include_apps, exclude_apps=args.exclude_apps, - database=args.database) - linter.lint_all_migrations( - git_commit_id=args.commit_id) + database=args.database, + cache_path=args.cache_path, + no_cache=args.no_cache, + ) + linter.lint_all_migrations(git_commit_id=args.commit_id) linter.print_summary() if linter.has_errors: sys.exit(1) -if __name__ == '__main__': +if __name__ == "__main__": _main() diff --git a/django_migration_linter/operations.py b/django_migration_linter/operations.py new file mode 100644 index 0000000..0262061 --- /dev/null +++ b/django_migration_linter/operations.py @@ -0,0 +1,36 @@ +# Copyright 2019 3YOURMIND GmbH + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from django.db.migrations.operations.base import Operation + +IGNORE_MIGRATION_SQL = "-- dml ignores this migration" + + +class IgnoreMigration(Operation): + + reversible = True + # Must be true to be generated through the sqlmigrate command + reduces_to_sql = True + + def state_forwards(self, app_label, state): + pass + + def database_forwards(self, app_label, schema_editor, from_state, to_state): + schema_editor.execute(IGNORE_MIGRATION_SQL) + + def database_backwards(self, app_label, schema_editor, from_state, to_state): + schema_editor.execute(IGNORE_MIGRATION_SQL + "(reversed)") + + def describe(self): + return "The Django migration linter will ignore this migration" diff --git a/django_migration_linter/sql_analyser.py b/django_migration_linter/sql_analyser.py index f1d074f..44b5246 100644 --- a/django_migration_linter/sql_analyser.py +++ b/django_migration_linter/sql_analyser.py @@ -1,4 +1,4 @@ -# Copyright 2018 3YOURMIND GmbH +# Copyright 2019 3YOURMIND GmbH # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,75 +15,91 @@ import re import logging -log = logging.getLogger(__name__) +from .operations import IGNORE_MIGRATION_SQL + +IGNORED_MIGRATION = "IGNORED_MIGRATION" + +logger = logging.getLogger(__name__) def has_default(sql, **kwargs): - if re.search('SET DEFAULT', sql) and kwargs['errors']: - err = next(err - for err in kwargs['errors'] - if err['code'] == 'NOT_NULL') + if re.search("SET DEFAULT", sql) and kwargs["errors"]: + err = next((err for err in kwargs["errors"] if err["code"] == "NOT_NULL"), None) if err: - log.info( - ('Found a NOT_NULL error in migration, ' - 'but it has a default value added: {}').format(err)) - kwargs['errors'].remove(err) + logger.info( + ( + "Found a NOT_NULL error in migration, " + "but it has a default value added: {}" + ).format(err) + ) + kwargs["errors"].remove(err) return False # Never fails migration_tests = ( { - 'code': 'NOT_NULL', - 'fn': lambda sql, **kw: re.search('NOT NULL', sql) and - not re.search('CREATE TABLE', sql), - 'err_msg': 'NOT NULL constraint on columns' - }, { - 'code': 'DROP_COLUMN', - 'fn': lambda sql, **kw: re.search('DROP COLUMN', sql), - 'err_msg': 'DROPPING columns' - }, { - 'code': 'RENAME_COLUMN', - 'fn': lambda sql, **kw: re.search('ALTER TABLE .* CHANGE', sql) or - re.search('ALTER TABLE .* RENAME COLUMN', sql), - 'err_msg': 'RENAMING columns' - }, { - 'code': 'RENAME_TABLE', - 'fn': lambda sql, **kw: re.search('RENAME TABLE', sql) or - re.search('ALTER TABLE .* RENAME TO', sql), - 'err_msg': 'RENAMING tables' - }, { - 'code': 'ALTER_COLUMN', - 'fn': lambda sql, **kw: re.search('ALTER TABLE .* MODIFY', sql), - 'err_msg': ('ALTERING columns (Could be backward compatible. ' - 'You may ignore this migration.)') - }, { - 'code': '', - 'fn': has_default, - 'err_msg': '' - } + "code": "NOT_NULL", + "fn": lambda sql, **kw: re.search("NOT NULL", sql) + and not re.search("CREATE TABLE", sql), + "err_msg": "NOT NULL constraint on columns", + }, + { + "code": "DROP_COLUMN", + "fn": lambda sql, **kw: re.search("DROP COLUMN", sql), + "err_msg": "DROPPING columns", + }, + { + "code": "RENAME_COLUMN", + "fn": lambda sql, **kw: re.search("ALTER TABLE .* CHANGE", sql) + or re.search("ALTER TABLE .* RENAME COLUMN", sql), + "err_msg": "RENAMING columns", + }, + { + "code": "RENAME_TABLE", + "fn": lambda sql, **kw: re.search("RENAME TABLE", sql) + or re.search("ALTER TABLE .* RENAME TO", sql), + "err_msg": "RENAMING tables", + }, + { + "code": "ALTER_COLUMN", + "fn": lambda sql, **kw: re.search("ALTER TABLE .* MODIFY", sql), + "err_msg": ( + "ALTERING columns (Could be backward compatible. " + "You may ignore this migration.)" + ), + }, + {"code": "", "fn": has_default, "err_msg": ""}, + { + "code": IGNORED_MIGRATION, + "fn": lambda sql, **kw: re.search(IGNORE_MIGRATION_SQL, sql), + "err_msg": "", + }, ) def analyse_sql_statements(sql_statements): errors = [] + ignored = False for statement in sql_statements: for test in migration_tests: - if test['fn'](statement, errors=errors): - log.info('Testing {0} -- ERROR'.format(statement)) - table_search = re.search( - 'TABLE `([^`]*)`', statement, re.IGNORECASE) - col_search = re.search( - 'COLUMN `([^`]*)`', statement, re.IGNORECASE) - err = { - 'err_msg': test['err_msg'], - 'code': test['code'], - 'table': table_search.group(1) if table_search else None, - 'column': col_search.group(1) if col_search else None - } - errors.append(err) + if test["fn"](statement, errors=errors): + if test["code"] == IGNORED_MIGRATION: + logger.info("Testing {0} -- IGNORING MIGRATION".format(statement)) + ignored = True + else: + logger.info("Testing {0} -- ERROR".format(statement)) + table_search = re.search( + "TABLE `([^`]*)`", statement, re.IGNORECASE + ) + col_search = re.search("COLUMN `([^`]*)`", statement, re.IGNORECASE) + err = { + "err_msg": test["err_msg"], + "code": test["code"], + "table": table_search.group(1) if table_search else None, + "column": col_search.group(1) if col_search else None, + } + errors.append(err) else: - log.info('Testing {0} -- PASSED'.format(statement)) - return { - 'errors': errors, - } + logger.info("Testing {0} -- PASSED".format(statement)) + return {"errors": errors, "ignored": ignored} diff --git a/django_migration_linter/utils.py b/django_migration_linter/utils.py index b2b8f23..e358593 100644 --- a/django_migration_linter/utils.py +++ b/django_migration_linter/utils.py @@ -1,4 +1,4 @@ -# Copyright 2018 3YOURMIND GmbH +# Copyright 2019 3YOURMIND GmbH # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -13,20 +13,18 @@ # limitations under the License. from __future__ import print_function + import os import sys +from .constants import MIGRATION_FOLDER_NAME + def is_django_project(path): - django_manage_file = os.path.join(path, 'manage.py') + django_manage_file = os.path.join(path, "manage.py") return os.path.isfile(django_manage_file) -def is_git_project(path): - git_directory = os.path.join(path, '.git') - return os.path.isdir(git_directory) - - def is_directory(path): return os.path.isdir(path) @@ -41,16 +39,31 @@ def find_project_settings_module(path): """ for root, dirs, files in os.walk(path): for file_name in files: - if file_name == 'settings.py': - return os.path.join( - root.replace(path, ''), - file_name).replace('/', '.').rstrip('.py') + if file_name == "settings.py": + return ( + os.path.join(root.replace(path, ""), file_name) + .replace("/", ".") + .rstrip(".py") + ) def split_path(path): a, b = os.path.split(path) - return (split_path(a) if (len(a) > 0 and a != '/') else []) + [b] + return (split_path(a) if (len(a) > 0 and a != "/") else []) + ([b] if b else []) + + +def split_migration_path(migration_path): + decomposed_path = split_path(migration_path) + for i, p in enumerate(decomposed_path): + if p == MIGRATION_FOLDER_NAME: + return (decomposed_path[i - 1], os.path.splitext(decomposed_path[i + 1])[0]) + + +def compose_migration_path(django_folder, app_name, migration): + return os.path.join( + django_folder, app_name, MIGRATION_FOLDER_NAME, "{0}.py".format(migration) + ) def clean_bytes_to_str(byte_input): - return byte_input.decode('utf-8').strip() + return byte_input.decode("utf-8").strip() diff --git a/examples/example_test_integration.py b/examples/example_test_integration.py index 5cfd59f..aa8f576 100644 --- a/examples/example_test_integration.py +++ b/examples/example_test_integration.py @@ -1,4 +1,4 @@ -# Copyright 2018 3YOURMIND GmbH +# Copyright 2019 3YOURMIND GmbH # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/setup.py b/setup.py index f50c7d5..9e896cb 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,4 @@ -# Copyright 2018 3YOURMIND GmbH +# Copyright 2019 3YOURMIND GmbH # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,18 +11,30 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - +import ast +import re from os import path from setuptools import setup, find_packages PROJECT_DIR = path.abspath(path.dirname(__file__)) + +def get_version(): + constants = path.join(PROJECT_DIR, 'django_migration_linter', 'constants.py') + _version_re = re.compile(r"__version__\s+=\s+(?P.*)") + with open(constants, "r") as f: + match = _version_re.search(f.read()) + version = match.group("version") if match is not None else '"unknown"' + return str(ast.literal_eval(version)) + + with open(path.join(PROJECT_DIR, 'README.rst')) as f: long_description = f.read() install_requirements = [ - 'django>=1.10', + 'django>=1.11', + 'appdirs==1.4.3' ] test_requirements = [ @@ -31,9 +43,10 @@ test_requirements = [ 'django-fake-database-backends', ] +# noinspection PyUnresolvedReferences setup( name='django-migration-linter', - version='0.0.5', + version=get_version(), description='Detect backward incompatible migrations for your django project', long_description=long_description, @@ -54,13 +67,13 @@ setup( keywords='django migration lint linter database backward compatibility', classifiers=[ - 'Development Status :: 3 - Alpha', + 'Development Status :: 4 - Beta', 'Intended Audience :: Developers', 'Environment :: Web Environment', 'Framework :: Django', - 'Framework :: Django :: 1.10', 'Framework :: Django :: 1.11', 'Framework :: Django :: 2.0', + 'Framework :: Django :: 2.1', 'Programming Language :: Python', 'Programming Language :: Python :: 2', @@ -69,5 +82,6 @@ setup( 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', ] ) diff --git a/tests/fixtures.py b/tests/fixtures.py index 5d97a82..81fb577 100644 --- a/tests/fixtures.py +++ b/tests/fixtures.py @@ -1,4 +1,4 @@ -# Copyright 2018 3YOURMIND GmbH +# Copyright 2019 3YOURMIND GmbH # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -40,16 +40,27 @@ CORRECT_PROJECT = os.path.join( _FIXTURES_FOLDER, 'test_correct_project/') DELETED_MIGRATION_PROJECT = os.path.join( _FIXTURES_FOLDER, 'test_deleted_migration_project/') +IGNORE_MIGRATION_PROJECT = os.path.join( + _FIXTURES_FOLDER, 'test_project_ignore_migration/') NOT_DJANGO_GIT_PROJECT = os.path.join( _FIXTURES_FOLDER, 'test_git_project/') NOT_GIT_DJANGO_PROJECT = os.path.join( _FIXTURES_FOLDER, 'test_django_without_git_project/') +NON_GIT_ROOT_GIT_FOLDER = os.path.join( + _FIXTURES_FOLDER, 'test_non_root_git_project/' +) +NON_GIT_ROOT_DJANGO_PROJECT = os.path.join( + NON_GIT_ROOT_GIT_FOLDER, 'django_project/' +) + + ALL_GIT_PROJECTS = ( NOT_DJANGO_GIT_PROJECT, MULTI_COMMIT_PROJECT, - DELETED_MIGRATION_PROJECT + DELETED_MIGRATION_PROJECT, + NON_GIT_ROOT_GIT_FOLDER, ) diff --git a/tests/functional/test_cache.py b/tests/functional/test_cache.py new file mode 100644 index 0000000..99024da --- /dev/null +++ b/tests/functional/test_cache.py @@ -0,0 +1,165 @@ +# Copyright 2019 3YOURMIND GmbH + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import os +import pprint +import shutil +import tempfile +import unittest +import sys + +from tests import fixtures + +from django_migration_linter import MigrationLinter, Cache, DEFAULT_CACHE_PATH + +if sys.version_info >= (3, 3): + import unittest.mock as mock +else: + import mock + + +class CacheTest(unittest.TestCase): + MIGRATION_FILE = os.path.join(fixtures.ALTER_COLUMN_PROJECT, 'test_app', 'migrations', '0001_initial.py') + fd, temp_path = tempfile.mkstemp() + + def setUp(self): + shutil.copy2(self.MIGRATION_FILE, self.temp_path) + + def tearDown(self): + shutil.copy2(self.temp_path, self.MIGRATION_FILE) + os.remove(self.temp_path) + + def test_cache_normal(self): + cache_file = os.path.join(DEFAULT_CACHE_PATH, 'test_project_add_not_null_column.pickle') + if os.path.exists(cache_file): + os.remove(cache_file) + linter = MigrationLinter(fixtures.ADD_NOT_NULL_COLUMN_PROJECT) + + with mock.patch.object(MigrationLinter, 'get_sql', wraps=linter.get_sql)as sql_mock: + linter.lint_all_migrations() + self.assertEqual(sql_mock.call_count, 2) + + cache = Cache( + fixtures.ADD_NOT_NULL_COLUMN_PROJECT, + DEFAULT_CACHE_PATH + ) + cache.load() + + self.assertEqual(cache['3ef74e7f3e53e273e2fc95379248d58d']['result'], 'OK') + self.assertEqual(cache['e1e312b6d08ecbe017c25c58fc2be257']['result'], 'ERR') + self.assertListEqual( + cache['e1e312b6d08ecbe017c25c58fc2be257']['errors'], + [{'err_msg': 'RENAMING tables', 'code': 'RENAME_TABLE', 'table': None, 'column': None}] + ) + + # Start the Linter again -> should use cache now. + linter = MigrationLinter(fixtures.ADD_NOT_NULL_COLUMN_PROJECT) + + with mock.patch.object(MigrationLinter, 'get_sql', wraps=linter.get_sql) as sql_mock: + linter.lint_all_migrations() + self.assertEqual(sql_mock.call_count, 0) + + self.assertTrue(linter.has_errors) + + def test_cache_ignored(self): + cache_file = os.path.join(DEFAULT_CACHE_PATH, 'test_project_ignore_migration.pickle') + if os.path.exists(cache_file): + os.remove(cache_file) + linter = MigrationLinter(fixtures.IGNORE_MIGRATION_PROJECT) + + with mock.patch.object(MigrationLinter, 'get_sql', wraps=linter.get_sql) as sql_mock: + linter.lint_all_migrations() + self.assertEqual(sql_mock.call_count, 2) + + cache = Cache( + fixtures.IGNORE_MIGRATION_PROJECT, + DEFAULT_CACHE_PATH + ) + cache.load() + + self.assertEqual(cache['63230606af0eccaef7f1f78c537c624c']['result'], 'OK') + self.assertEqual(cache['5c5ca1780a9f28439c1defc1f32af894']['result'], 'IGNORE') + + # Start the Linter again -> should use cache now. + linter = MigrationLinter(fixtures.IGNORE_MIGRATION_PROJECT) + + with mock.patch.object(MigrationLinter, 'get_sql', wraps=linter.get_sql) as sql_mock: + linter.lint_all_migrations() + self.assertEqual(sql_mock.call_count, 0) + + def test_cache_ignored_command_line(self): + cache_file = os.path.join(DEFAULT_CACHE_PATH, 'test_project_ignore_migration.pickle') + if os.path.exists(cache_file): + os.remove(cache_file) + linter = MigrationLinter(fixtures.IGNORE_MIGRATION_PROJECT, + ignore_name_contains='0001') + + with mock.patch.object(MigrationLinter, 'get_sql', wraps=linter.get_sql) as sql_mock: + linter.lint_all_migrations() + self.assertEqual(sql_mock.call_count, 1) + + cache = Cache( + fixtures.IGNORE_MIGRATION_PROJECT, + DEFAULT_CACHE_PATH + ) + cache.load() + + self.assertNotIn('63230606af0eccaef7f1f78c537c624c', cache) + self.assertEqual(cache['5c5ca1780a9f28439c1defc1f32af894']['result'], 'IGNORE') + + def test_cache_modified(self): + cache_file = os.path.join(DEFAULT_CACHE_PATH, 'test_project_alter_column.pickle') + if os.path.exists(cache_file): + os.remove(cache_file) + linter = MigrationLinter(fixtures.ALTER_COLUMN_PROJECT) + linter.lint_all_migrations() + cache = Cache( + fixtures.ALTER_COLUMN_PROJECT, + DEFAULT_CACHE_PATH + ) + cache.load() + + self.assertEqual(cache['8589aa107b6da296c4b49cd2681d2230']['result'], 'OK', + 'If this fails, tearDown might have failed to remove ' + 'the modification from tests/test_project_fixtures/' + 'test_project_alter_column/test_app/migrations/0001_initial.py' + ) + self.assertEqual(cache['8f54c4a434cfaa9838e8ca12eb988255']['result'], 'ERR') + self.assertListEqual( + cache['8f54c4a434cfaa9838e8ca12eb988255']['errors'], + [{u'err_msg': u'ALTERING columns (Could be backward compatible. ' + u'You may ignore this migration.)', + u'code': u'ALTER_COLUMN', + u'table': u'test_app_a', + u'column': None} + ] + ) + + # Modify migration + with open(self.MIGRATION_FILE, "a") as f: + f.write("# modification at the end of the file\n") + + # Start the Linter again -> Cache should look different now + linter = MigrationLinter(fixtures.ALTER_COLUMN_PROJECT) + linter.lint_all_migrations() + cache = Cache( + fixtures.ALTER_COLUMN_PROJECT, + DEFAULT_CACHE_PATH + ) + cache.load() + + pp = pprint.PrettyPrinter(indent=4) + pp.pprint(cache) + + self.assertNotIn('8589aa107b6da296c4b49cd2681d2230', cache) + self.assertEqual(cache['44f9d6d019d6f158946c2819b2bd8bf9']['result'], 'OK') diff --git a/tests/functional/test_cmd_line_call.py b/tests/functional/test_cmd_line_call.py index a3afd33..a2861fa 100644 --- a/tests/functional/test_cmd_line_call.py +++ b/tests/functional/test_cmd_line_call.py @@ -1,4 +1,4 @@ -# Copyright 2018 3YOURMIND GmbH +# Copyright 2019 3YOURMIND GmbH # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -12,9 +12,11 @@ # See the License for the specific language governing permissions and # limitations under the License. +import os +import shutil import unittest from subprocess import Popen, PIPE -from django_migration_linter import utils +from django_migration_linter import utils, DEFAULT_CACHE_PATH from tests import fixtures import sys @@ -27,20 +29,26 @@ class CallLinterFromCommandLineTest(unittest.TestCase): cls.linter_exec = '{0}/bin/{1}'.format(sys.prefix, linter_name) if hasattr(sys, 'real_prefix') else linter_name def test_call_linter_cmd_line_working(self): - cmd = '{0} {1}'.format(self.linter_exec, fixtures.CORRECT_PROJECT) + cmd = '{0} --no-cache {1}'.format(self.linter_exec, fixtures.CORRECT_PROJECT) process = Popen( cmd, shell=True, stdout=PIPE, stderr=PIPE) process.wait() self.assertEqual(process.returncode, 0) lines = list(map(utils.clean_bytes_to_str, process.stdout.readlines())) - self.assertEqual(len(lines), 5) - self.assertTrue(lines[0].endswith('OK')) - self.assertTrue(lines[1].endswith('OK')) - self.assertTrue(lines[2].endswith('OK')) + self.assertEqual(len(lines), 6) + self.assertEqual( + sorted(lines[:4]), + sorted([ + "(test_app1, 0001_initial)... OK", + "(test_app1, 0002_a_new_null_field)... OK", + "(test_app2, 0001_foo)... OK", + "(test_app3, 0001_initial)... OK", + ]) + ) def test_call_linter_cmd_line_errors(self): - cmd = '{0} {1}'.format( + cmd = '{0} --no-cache {1}'.format( self.linter_exec, fixtures.ADD_NOT_NULL_COLUMN_PROJECT) @@ -50,13 +58,12 @@ class CallLinterFromCommandLineTest(unittest.TestCase): self.assertNotEqual(process.returncode, 0) lines = list(map(utils.clean_bytes_to_str, process.stdout.readlines())) self.assertEqual(len(lines), 5) - print(lines) self.assertTrue(lines[0].endswith('OK')) self.assertTrue(lines[1].endswith('ERR')) self.assertTrue('RENAMING tables' in lines[2]) def test_call_linter_cmd_line_exclude_apps(self): - cmd = '{0} {1} --exclude-apps test_app2'.format( + cmd = '{0} --no-cache {1} --exclude-apps test_app2'.format( self.linter_exec, fixtures.CORRECT_PROJECT) @@ -65,13 +72,19 @@ class CallLinterFromCommandLineTest(unittest.TestCase): process.wait() self.assertEqual(process.returncode, 0) lines = list(map(utils.clean_bytes_to_str, process.stdout.readlines())) - self.assertEqual(len(lines), 5) - self.assertTrue(lines[0].endswith('OK')) - self.assertTrue(lines[1].endswith('OK')) - self.assertTrue(lines[2].endswith('IGNORE')) + self.assertEqual(len(lines), 6) + self.assertEqual( + sorted(lines[:4]), + sorted([ + "(test_app1, 0001_initial)... OK", + "(test_app1, 0002_a_new_null_field)... OK", + "(test_app2, 0001_foo)... IGNORE", + "(test_app3, 0001_initial)... OK", + ]) + ) def test_call_linter_cmd_line_include_apps(self): - cmd = '{0} {1} --include-apps test_app2'.format( + cmd = '{0} --no-cache {1} --include-apps test_app2'.format( self.linter_exec, fixtures.CORRECT_PROJECT) @@ -80,13 +93,19 @@ class CallLinterFromCommandLineTest(unittest.TestCase): process.wait() self.assertEqual(process.returncode, 0) lines = list(map(utils.clean_bytes_to_str, process.stdout.readlines())) - self.assertEqual(len(lines), 5) - self.assertTrue(lines[0].endswith('IGNORE')) - self.assertTrue(lines[1].endswith('IGNORE')) - self.assertTrue(lines[2].endswith('OK')) + self.assertEqual(len(lines), 6) + self.assertEqual( + sorted(lines[:4]), + sorted([ + "(test_app1, 0001_initial)... IGNORE", + "(test_app1, 0002_a_new_null_field)... IGNORE", + "(test_app2, 0001_foo)... OK", + "(test_app3, 0001_initial)... IGNORE", + ]) + ) def test_call_linter_cmd_line_ignore_name(self): - cmd = '{0} {1} --ignore-name 0001_initial'.format( + cmd = '{0} --no-cache {1} --ignore-name 0001_initial'.format( self.linter_exec, fixtures.CORRECT_PROJECT) @@ -95,13 +114,19 @@ class CallLinterFromCommandLineTest(unittest.TestCase): process.wait() self.assertEqual(process.returncode, 0) lines = list(map(utils.clean_bytes_to_str, process.stdout.readlines())) - self.assertEqual(len(lines), 5) - self.assertTrue(lines[0].endswith('IGNORE')) - self.assertTrue(lines[1].endswith('OK')) - self.assertTrue(lines[2].endswith('OK')) + self.assertEqual(len(lines), 6) + self.assertEqual( + sorted(lines[:4]), + sorted([ + "(test_app1, 0001_initial)... IGNORE", + "(test_app1, 0002_a_new_null_field)... OK", + "(test_app2, 0001_foo)... OK", + "(test_app3, 0001_initial)... IGNORE", + ]) + ) def test_call_linter_cmd_line_ignore_name_contains(self): - cmd = '{0} {1} --ignore-name-contains 0001'.format( + cmd = '{0} --no-cache {1} --ignore-name-contains 0001'.format( self.linter_exec, fixtures.CORRECT_PROJECT) @@ -110,13 +135,64 @@ class CallLinterFromCommandLineTest(unittest.TestCase): process.wait() self.assertEqual(process.returncode, 0) lines = list(map(utils.clean_bytes_to_str, process.stdout.readlines())) - self.assertEqual(len(lines), 5) - self.assertTrue(lines[0].endswith('IGNORE')) - self.assertTrue(lines[1].endswith('OK')) - self.assertTrue(lines[2].endswith('IGNORE')) + self.assertEqual(len(lines), 6) + self.assertEqual( + sorted(lines[:4]), + sorted([ + "(test_app1, 0001_initial)... IGNORE", + "(test_app1, 0002_a_new_null_field)... OK", + "(test_app2, 0001_foo)... IGNORE", + "(test_app3, 0001_initial)... IGNORE", + ]) + ) + + def test_call_linter_cmd_line_cache(self): + cache_file = os.path.join(DEFAULT_CACHE_PATH, 'test_correct_project.pickle') + if os.path.exists(cache_file): + os.remove(cache_file) + cmd = '{0} {1}'.format( + self.linter_exec, + fixtures.CORRECT_PROJECT + ) + + process = Popen( + cmd, shell=True, stdout=PIPE, stderr=PIPE) + process.wait() + self.assertTrue(os.path.exists(DEFAULT_CACHE_PATH)) + + def test_call_linter_cmd_line_cache_path(self): + if os.path.exists('/tmp/migration-linter-cache-tests/'): + shutil.rmtree('/tmp/migration-linter-cache-tests/') + cmd = '{0} {1} --cache-path={2}'.format( + self.linter_exec, + fixtures.CORRECT_PROJECT, + '/tmp/migration-linter-cache-tests/' + ) + + process = Popen( + cmd, shell=True, stdout=PIPE, stderr=PIPE) + process.wait() + self.assertEqual(process.returncode, 0) + self.assertTrue(os.path.exists('/tmp/migration-linter-cache-tests')) + + def test_call_linter_cmd_line_no_cache(self): + cache_file = os.path.join(DEFAULT_CACHE_PATH, 'test_correct_project.pickle') + if os.path.exists(cache_file): + os.remove(cache_file) + + cmd = '{0} --no-cache {1}'.format( + self.linter_exec, + fixtures.CORRECT_PROJECT + ) + + process = Popen( + cmd, shell=True, stdout=PIPE, stderr=PIPE) + process.wait() + self.assertEqual(process.returncode, 0) + self.assertFalse(os.path.exists(cache_file)) def test_call_linter_cmd_line_git_id(self): - cmd = '{0} {1} d7125d5f4f0cc9623f670a66c54f131acc50032d'.format( + cmd = '{0} --no-cache {1} d7125d5f4f0cc9623f670a66c54f131acc50032d'.format( self.linter_exec, fixtures.MULTI_COMMIT_PROJECT) fixtures.prepare_git_project(fixtures.MULTI_COMMIT_PROJECT) @@ -131,7 +207,7 @@ class CallLinterFromCommandLineTest(unittest.TestCase): self.assertTrue(lines[1].startswith('*** Summary')) def test_call_linter_with_deleted_migrations(self): - cmd = '{0} {1} 154ecf6119325cc3b1f3f5a4e709bfbd61a4a4ba'.format( + cmd = '{0} --no-cache {1} 154ecf6119325cc3b1f3f5a4e709bfbd61a4a4ba'.format( self.linter_exec, fixtures.DELETED_MIGRATION_PROJECT) fixtures.prepare_git_project(fixtures.DELETED_MIGRATION_PROJECT) @@ -144,3 +220,57 @@ class CallLinterFromCommandLineTest(unittest.TestCase): self.assertEqual(len(lines), 3) self.assertTrue(lines[0].endswith('OK')) self.assertTrue(lines[1].startswith('*** Summary')) + + def test_call_from_within_project(self): + cmd = 'cd {0} && {1} --no-cache .'.format( + fixtures.CORRECT_PROJECT, + self.linter_exec) + + process = Popen( + cmd, shell=True, stdout=PIPE, stderr=PIPE) + process.wait() + self.assertEqual(process.returncode, 0) + lines = list(map(utils.clean_bytes_to_str, process.stdout.readlines())) + self.assertEqual(len(lines), 6) + self.assertEqual( + sorted(lines[:4]), + sorted([ + "(test_app1, 0001_initial)... OK", + "(test_app1, 0002_a_new_null_field)... OK", + "(test_app2, 0001_foo)... OK", + "(test_app3, 0001_initial)... OK", + ]) + ) + + def test_call_project_non_git_root(self): + # could use tag: version_ok (but doesn't work in Travis) + cmd = '{0} --no-cache {1} 2c46f438a89972f9ce2d5151a825a5bfb7f7db4b'.format( + self.linter_exec, + fixtures.NON_GIT_ROOT_DJANGO_PROJECT) + fixtures.prepare_git_project(fixtures.NON_GIT_ROOT_GIT_FOLDER) + + process = Popen( + cmd, shell=True, stdout=PIPE, stderr=PIPE) + process.wait() + self.assertEqual(process.returncode, 0) + lines = list(map(utils.clean_bytes_to_str, process.stdout.readlines())) + self.assertEqual(len(lines), 3) + self.assertTrue(lines[0].endswith('OK')) + self.assertTrue(lines[1].startswith('*** Summary')) + + def test_call_project_non_git_root_ko(self): + # could use tag: version_ko (but doesn't work in Travis) + cmd = '{0} --no-cache {1} 0140e142724fc58944797f9ddc2ebf964146339a'.format( + self.linter_exec, + fixtures.NON_GIT_ROOT_DJANGO_PROJECT) + fixtures.prepare_git_project(fixtures.NON_GIT_ROOT_GIT_FOLDER) + + process = Popen( + cmd, shell=True, stdout=PIPE, stderr=PIPE) + process.wait() + self.assertNotEqual(process.returncode, 0) + lines = list(map(utils.clean_bytes_to_str, process.stdout.readlines())) + self.assertEqual(len(lines), 5) + self.assertTrue(lines[0].endswith('ERR')) + self.assertTrue(lines[2].endswith('OK')) + self.assertTrue(lines[3].startswith('*** Summary')) diff --git a/tests/functional/test_migration_linter.py b/tests/functional/test_migration_linter.py index 6187613..42d3cc8 100644 --- a/tests/functional/test_migration_linter.py +++ b/tests/functional/test_migration_linter.py @@ -1,4 +1,4 @@ -# Copyright 2018 3YOURMIND GmbH +# Copyright 2019 3YOURMIND GmbH # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -56,6 +56,10 @@ class BackwardcompatibilityDetectionTest(unittest.TestCase): test_project_path = fixtures.RENAME_TABLE_PROJECT self._test_linter_finds_errors(test_project_path) + def test_ignore_migration(self): + test_project_path = fixtures.IGNORE_MIGRATION_PROJECT + self._test_linter_finds_no_errors(test_project_path) + def test_accept_not_null_column_followed_by_adding_default(self): test_project_path = \ fixtures.ADD_NOT_NULL_COLUMN_FOLLOWED_BY_DEFAULT_PROJECT diff --git a/tests/functional/test_multiple_calls.py b/tests/functional/test_multiple_calls.py index bea9262..e58a473 100644 --- a/tests/functional/test_multiple_calls.py +++ b/tests/functional/test_multiple_calls.py @@ -1,4 +1,4 @@ -# Copyright 2018 3YOURMIND GmbH +# Copyright 2019 3YOURMIND GmbH # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -13,8 +13,10 @@ # limitations under the License. import unittest +import os from django_migration_linter import MigrationLinter +from django_migration_linter.migration import Migration from tests import fixtures @@ -24,10 +26,10 @@ class TestMultipleLinters(unittest.TestCase): l2 = MigrationLinter(fixtures.RENAME_COLUMN_PROJECT) l3 = MigrationLinter(fixtures.CORRECT_PROJECT) - l1.lint_migration('test_app', '0002') - l2.lint_migration('test_app', '0002') - l3.lint_migration('test_app1', '0001') - l3.lint_migration('test_app1', '0002') + l1.lint_migration(Migration(os.path.join(fixtures.ADD_NOT_NULL_COLUMN_PROJECT, 'test_app/migrations/0002_add_new_not_null_field.py'))) + l2.lint_migration(Migration(os.path.join(fixtures.RENAME_COLUMN_PROJECT, 'test_app/migrations/0002_rename_column.py'))) + l3.lint_migration(Migration(os.path.join(fixtures.CORRECT_PROJECT, 'test_app1/migrations/0001_initial.py'))) + l3.lint_migration(Migration(os.path.join(fixtures.CORRECT_PROJECT, 'test_app1/migrations/0002_a_new_null_field.py'))) self.assertTrue(l1.has_errors) self.assertTrue(l2.has_errors) diff --git a/tests/test_project_fixtures/test_correct_project/apps/__init__.py b/tests/test_project_fixtures/test_correct_project/apps/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_project_fixtures/test_correct_project/apps/test_app3/__init__.py b/tests/test_project_fixtures/test_correct_project/apps/test_app3/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_project_fixtures/test_correct_project/apps/test_app3/admin.py b/tests/test_project_fixtures/test_correct_project/apps/test_app3/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/tests/test_project_fixtures/test_correct_project/apps/test_app3/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/tests/test_project_fixtures/test_correct_project/apps/test_app3/apps.py b/tests/test_project_fixtures/test_correct_project/apps/test_app3/apps.py new file mode 100644 index 0000000..7a1fd83 --- /dev/null +++ b/tests/test_project_fixtures/test_correct_project/apps/test_app3/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class TestApp3Config(AppConfig): + name = 'test_app3' diff --git a/tests/test_project_fixtures/test_correct_project/apps/test_app3/migrations/0001_initial.py b/tests/test_project_fixtures/test_correct_project/apps/test_app3/migrations/0001_initial.py new file mode 100644 index 0000000..beaa780 --- /dev/null +++ b/tests/test_project_fixtures/test_correct_project/apps/test_app3/migrations/0001_initial.py @@ -0,0 +1,21 @@ +# Generated by Django 2.1.4 on 2019-01-04 20:55 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='C', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('not_null_field', models.IntegerField()), + ], + ), + ] diff --git a/tests/test_project_fixtures/test_correct_project/apps/test_app3/migrations/__init__.py b/tests/test_project_fixtures/test_correct_project/apps/test_app3/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_project_fixtures/test_correct_project/apps/test_app3/models.py b/tests/test_project_fixtures/test_correct_project/apps/test_app3/models.py new file mode 100644 index 0000000..0124f42 --- /dev/null +++ b/tests/test_project_fixtures/test_correct_project/apps/test_app3/models.py @@ -0,0 +1,4 @@ +from django.db import models + +class C(models.Model): + not_null_field = models.IntegerField(null=False) diff --git a/tests/test_project_fixtures/test_correct_project/apps/test_app3/tests.py b/tests/test_project_fixtures/test_correct_project/apps/test_app3/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/tests/test_project_fixtures/test_correct_project/apps/test_app3/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/tests/test_project_fixtures/test_correct_project/apps/test_app3/views.py b/tests/test_project_fixtures/test_correct_project/apps/test_app3/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/tests/test_project_fixtures/test_correct_project/apps/test_app3/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/tests/test_project_fixtures/test_correct_project/test_project/settings.py b/tests/test_project_fixtures/test_correct_project/test_project/settings.py index f0642cc..8145e44 100644 --- a/tests/test_project_fixtures/test_correct_project/test_project/settings.py +++ b/tests/test_project_fixtures/test_correct_project/test_project/settings.py @@ -11,10 +11,12 @@ https://docs.djangoproject.com/en/1.11/ref/settings/ """ import os +import sys # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +sys.path.insert(0, os.path.join(BASE_DIR, 'apps')) # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/ @@ -38,7 +40,8 @@ INSTALLED_APPS = [ 'django.contrib.messages', 'django.contrib.staticfiles', 'test_app1', - 'test_app2' + 'test_app2', + 'apps.test_app3', ] MIDDLEWARE = [ diff --git a/tests/test_project_fixtures/test_non_root_git_project/django_project/manage.py b/tests/test_project_fixtures/test_non_root_git_project/django_project/manage.py new file mode 100644 index 0000000..3390cc6 --- /dev/null +++ b/tests/test_project_fixtures/test_non_root_git_project/django_project/manage.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +import os +import sys + +if __name__ == "__main__": + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "test_project.settings") + try: + from django.core.management import execute_from_command_line + except ImportError: + # The above import may fail for some other reason. Ensure that the + # issue is really that Django is missing to avoid masking other + # exceptions on Python 2. + try: + import django + except ImportError: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) + raise + execute_from_command_line(sys.argv) diff --git a/tests/test_project_fixtures/test_non_root_git_project/django_project/test_app1/__init__.py b/tests/test_project_fixtures/test_non_root_git_project/django_project/test_app1/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_project_fixtures/test_non_root_git_project/django_project/test_app1/admin.py b/tests/test_project_fixtures/test_non_root_git_project/django_project/test_app1/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/tests/test_project_fixtures/test_non_root_git_project/django_project/test_app1/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/tests/test_project_fixtures/test_non_root_git_project/django_project/test_app1/apps.py b/tests/test_project_fixtures/test_non_root_git_project/django_project/test_app1/apps.py new file mode 100644 index 0000000..1dc36fd --- /dev/null +++ b/tests/test_project_fixtures/test_non_root_git_project/django_project/test_app1/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class TestApp1Config(AppConfig): + name = 'test_app1' diff --git a/tests/test_project_fixtures/test_non_root_git_project/django_project/test_app1/migrations/0001_initial.py b/tests/test_project_fixtures/test_non_root_git_project/django_project/test_app1/migrations/0001_initial.py new file mode 100644 index 0000000..9bb5157 --- /dev/null +++ b/tests/test_project_fixtures/test_non_root_git_project/django_project/test_app1/migrations/0001_initial.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.18 on 2019-01-20 10:31 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='A', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('null_field', models.IntegerField()), + ], + ), + ] diff --git a/tests/test_project_fixtures/test_non_root_git_project/django_project/test_app1/migrations/0002_a_null_field_2.py b/tests/test_project_fixtures/test_non_root_git_project/django_project/test_app1/migrations/0002_a_null_field_2.py new file mode 100644 index 0000000..15d47f2 --- /dev/null +++ b/tests/test_project_fixtures/test_non_root_git_project/django_project/test_app1/migrations/0002_a_null_field_2.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.18 on 2019-01-20 10:32 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('test_app1', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='a', + name='null_field_2', + field=models.IntegerField(default=1), + ), + ] diff --git a/tests/test_project_fixtures/test_non_root_git_project/django_project/test_app1/migrations/0003_a_non_null_field.py b/tests/test_project_fixtures/test_non_root_git_project/django_project/test_app1/migrations/0003_a_non_null_field.py new file mode 100644 index 0000000..8fbe1b0 --- /dev/null +++ b/tests/test_project_fixtures/test_non_root_git_project/django_project/test_app1/migrations/0003_a_non_null_field.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.18 on 2019-01-20 10:33 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('test_app1', '0002_a_null_field_2'), + ] + + operations = [ + migrations.AddField( + model_name='a', + name='non_null_field', + field=models.IntegerField(null=True), + ), + ] diff --git a/tests/test_project_fixtures/test_non_root_git_project/django_project/test_app1/migrations/__init__.py b/tests/test_project_fixtures/test_non_root_git_project/django_project/test_app1/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_project_fixtures/test_non_root_git_project/django_project/test_app1/models.py b/tests/test_project_fixtures/test_non_root_git_project/django_project/test_app1/models.py new file mode 100644 index 0000000..1cdc834 --- /dev/null +++ b/tests/test_project_fixtures/test_non_root_git_project/django_project/test_app1/models.py @@ -0,0 +1,6 @@ +from django.db import models + +class A(models.Model): + null_field = models.IntegerField() + null_field_2 = models.IntegerField(default=1) + non_null_field = models.IntegerField(null=True) diff --git a/tests/test_project_fixtures/test_non_root_git_project/django_project/test_app1/tests.py b/tests/test_project_fixtures/test_non_root_git_project/django_project/test_app1/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/tests/test_project_fixtures/test_non_root_git_project/django_project/test_app1/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/tests/test_project_fixtures/test_non_root_git_project/django_project/test_app1/views.py b/tests/test_project_fixtures/test_non_root_git_project/django_project/test_app1/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/tests/test_project_fixtures/test_non_root_git_project/django_project/test_app1/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/tests/test_project_fixtures/test_non_root_git_project/django_project/test_project/__init__.py b/tests/test_project_fixtures/test_non_root_git_project/django_project/test_project/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_project_fixtures/test_non_root_git_project/django_project/test_project/settings.py b/tests/test_project_fixtures/test_non_root_git_project/django_project/test_project/settings.py new file mode 100644 index 0000000..986913f --- /dev/null +++ b/tests/test_project_fixtures/test_non_root_git_project/django_project/test_project/settings.py @@ -0,0 +1,122 @@ +""" +Django settings for test_project project. + +Generated by 'django-admin startproject' using Django 1.11.6. + +For more information on this file, see +https://docs.djangoproject.com/en/1.11/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/1.11/ref/settings/ +""" + +import os +import sys + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + +sys.path.insert(0, os.path.join(BASE_DIR, 'apps')) + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'gtb+mohs%gf0+#fr89vw7e&#edmv=q8!iv+n&j_soawk$tkj3^' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'test_app1', +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'test_project.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'test_project.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/1.11/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django_fake_database_backends.backends.mysql' + } +} + + +# Password validation +# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/1.11/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/1.11/howto/static-files/ + +STATIC_URL = '/static/' diff --git a/tests/test_project_fixtures/test_non_root_git_project/django_project/test_project/urls.py b/tests/test_project_fixtures/test_non_root_git_project/django_project/test_project/urls.py new file mode 100644 index 0000000..735de5d --- /dev/null +++ b/tests/test_project_fixtures/test_non_root_git_project/django_project/test_project/urls.py @@ -0,0 +1,21 @@ +"""linter_test_project URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/1.11/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.conf.urls import url, include + 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) +""" +from django.conf.urls import url +from django.contrib import admin + +urlpatterns = [ + url(r'^admin/', admin.site.urls), +] diff --git a/tests/test_project_fixtures/test_non_root_git_project/django_project/test_project/wsgi.py b/tests/test_project_fixtures/test_non_root_git_project/django_project/test_project/wsgi.py new file mode 100644 index 0000000..aa66ac1 --- /dev/null +++ b/tests/test_project_fixtures/test_non_root_git_project/django_project/test_project/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for linter_test_project project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/1.11/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "test_project.settings") + +application = get_wsgi_application() diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/COMMIT_EDITMSG b/tests/test_project_fixtures/test_non_root_git_project/git/COMMIT_EDITMSG new file mode 100644 index 0000000..46d3912 --- /dev/null +++ b/tests/test_project_fixtures/test_non_root_git_project/git/COMMIT_EDITMSG @@ -0,0 +1 @@ +Add ok migration diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/HEAD b/tests/test_project_fixtures/test_non_root_git_project/git/HEAD new file mode 100644 index 0000000..cb089cd --- /dev/null +++ b/tests/test_project_fixtures/test_non_root_git_project/git/HEAD @@ -0,0 +1 @@ +ref: refs/heads/master diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/config b/tests/test_project_fixtures/test_non_root_git_project/git/config new file mode 100644 index 0000000..515f483 --- /dev/null +++ b/tests/test_project_fixtures/test_non_root_git_project/git/config @@ -0,0 +1,5 @@ +[core] + repositoryformatversion = 0 + filemode = true + bare = false + logallrefupdates = true diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/description b/tests/test_project_fixtures/test_non_root_git_project/git/description new file mode 100644 index 0000000..498b267 --- /dev/null +++ b/tests/test_project_fixtures/test_non_root_git_project/git/description @@ -0,0 +1 @@ +Unnamed repository; edit this file 'description' to name the repository. diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/hooks/applypatch-msg.sample b/tests/test_project_fixtures/test_non_root_git_project/git/hooks/applypatch-msg.sample new file mode 100755 index 0000000..a5d7b84 --- /dev/null +++ b/tests/test_project_fixtures/test_non_root_git_project/git/hooks/applypatch-msg.sample @@ -0,0 +1,15 @@ +#!/bin/sh +# +# An example hook script to check the commit log message taken by +# applypatch from an e-mail message. +# +# The hook should exit with non-zero status after issuing an +# appropriate message if it wants to stop the commit. The hook is +# allowed to edit the commit message file. +# +# To enable this hook, rename this file to "applypatch-msg". + +. git-sh-setup +commitmsg="$(git rev-parse --git-path hooks/commit-msg)" +test -x "$commitmsg" && exec "$commitmsg" ${1+"$@"} +: diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/hooks/commit-msg.sample b/tests/test_project_fixtures/test_non_root_git_project/git/hooks/commit-msg.sample new file mode 100755 index 0000000..b58d118 --- /dev/null +++ b/tests/test_project_fixtures/test_non_root_git_project/git/hooks/commit-msg.sample @@ -0,0 +1,24 @@ +#!/bin/sh +# +# An example hook script to check the commit log message. +# Called by "git commit" with one argument, the name of the file +# that has the commit message. The hook should exit with non-zero +# status after issuing an appropriate message if it wants to stop the +# commit. The hook is allowed to edit the commit message file. +# +# To enable this hook, rename this file to "commit-msg". + +# Uncomment the below to add a Signed-off-by line to the message. +# Doing this in a hook is a bad idea in general, but the prepare-commit-msg +# hook is more suited to it. +# +# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p') +# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1" + +# This example catches duplicate Signed-off-by lines. + +test "" = "$(grep '^Signed-off-by: ' "$1" | + sort | uniq -c | sed -e '/^[ ]*1[ ]/d')" || { + echo >&2 Duplicate Signed-off-by lines. + exit 1 +} diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/hooks/fsmonitor-watchman.sample b/tests/test_project_fixtures/test_non_root_git_project/git/hooks/fsmonitor-watchman.sample new file mode 100755 index 0000000..e673bb3 --- /dev/null +++ b/tests/test_project_fixtures/test_non_root_git_project/git/hooks/fsmonitor-watchman.sample @@ -0,0 +1,114 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use IPC::Open2; + +# An example hook script to integrate Watchman +# (https://facebook.github.io/watchman/) with git to speed up detecting +# new and modified files. +# +# The hook is passed a version (currently 1) and a time in nanoseconds +# formatted as a string and outputs to stdout all files that have been +# modified since the given time. Paths must be relative to the root of +# the working tree and separated by a single NUL. +# +# To enable this hook, rename this file to "query-watchman" and set +# 'git config core.fsmonitor .git/hooks/query-watchman' +# +my ($version, $time) = @ARGV; + +# Check the hook interface version + +if ($version == 1) { + # convert nanoseconds to seconds + $time = int $time / 1000000000; +} else { + die "Unsupported query-fsmonitor hook version '$version'.\n" . + "Falling back to scanning...\n"; +} + +my $git_work_tree; +if ($^O =~ 'msys' || $^O =~ 'cygwin') { + $git_work_tree = Win32::GetCwd(); + $git_work_tree =~ tr/\\/\//; +} else { + require Cwd; + $git_work_tree = Cwd::cwd(); +} + +my $retry = 1; + +launch_watchman(); + +sub launch_watchman { + + my $pid = open2(\*CHLD_OUT, \*CHLD_IN, 'watchman -j --no-pretty') + or die "open2() failed: $!\n" . + "Falling back to scanning...\n"; + + # In the query expression below we're asking for names of files that + # changed since $time but were not transient (ie created after + # $time but no longer exist). + # + # To accomplish this, we're using the "since" generator to use the + # recency index to select candidate nodes and "fields" to limit the + # output to file names only. Then we're using the "expression" term to + # further constrain the results. + # + # The category of transient files that we want to ignore will have a + # creation clock (cclock) newer than $time_t value and will also not + # currently exist. + + my $query = <<" END"; + ["query", "$git_work_tree", { + "since": $time, + "fields": ["name"], + "expression": ["not", ["allof", ["since", $time, "cclock"], ["not", "exists"]]] + }] + END + + print CHLD_IN $query; + close CHLD_IN; + my $response = do {local $/; }; + + die "Watchman: command returned no output.\n" . + "Falling back to scanning...\n" if $response eq ""; + die "Watchman: command returned invalid output: $response\n" . + "Falling back to scanning...\n" unless $response =~ /^\{/; + + my $json_pkg; + eval { + require JSON::XS; + $json_pkg = "JSON::XS"; + 1; + } or do { + require JSON::PP; + $json_pkg = "JSON::PP"; + }; + + my $o = $json_pkg->new->utf8->decode($response); + + if ($retry > 0 and $o->{error} and $o->{error} =~ m/unable to resolve root .* directory (.*) is not watched/) { + print STDERR "Adding '$git_work_tree' to watchman's watch list.\n"; + $retry--; + qx/watchman watch "$git_work_tree"/; + die "Failed to make watchman watch '$git_work_tree'.\n" . + "Falling back to scanning...\n" if $? != 0; + + # Watchman will always return all files on the first query so + # return the fast "everything is dirty" flag to git and do the + # Watchman query just to get it over with now so we won't pay + # the cost in git to look up each individual file. + print "/\0"; + eval { launch_watchman() }; + exit 0; + } + + die "Watchman: $o->{error}.\n" . + "Falling back to scanning...\n" if $o->{error}; + + binmode STDOUT, ":utf8"; + local $, = "\0"; + print @{$o->{files}}; +} diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/hooks/post-update.sample b/tests/test_project_fixtures/test_non_root_git_project/git/hooks/post-update.sample new file mode 100755 index 0000000..ec17ec1 --- /dev/null +++ b/tests/test_project_fixtures/test_non_root_git_project/git/hooks/post-update.sample @@ -0,0 +1,8 @@ +#!/bin/sh +# +# An example hook script to prepare a packed repository for use over +# dumb transports. +# +# To enable this hook, rename this file to "post-update". + +exec git update-server-info diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/hooks/pre-applypatch.sample b/tests/test_project_fixtures/test_non_root_git_project/git/hooks/pre-applypatch.sample new file mode 100755 index 0000000..4142082 --- /dev/null +++ b/tests/test_project_fixtures/test_non_root_git_project/git/hooks/pre-applypatch.sample @@ -0,0 +1,14 @@ +#!/bin/sh +# +# An example hook script to verify what is about to be committed +# by applypatch from an e-mail message. +# +# The hook should exit with non-zero status after issuing an +# appropriate message if it wants to stop the commit. +# +# To enable this hook, rename this file to "pre-applypatch". + +. git-sh-setup +precommit="$(git rev-parse --git-path hooks/pre-commit)" +test -x "$precommit" && exec "$precommit" ${1+"$@"} +: diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/hooks/pre-commit.sample b/tests/test_project_fixtures/test_non_root_git_project/git/hooks/pre-commit.sample new file mode 100755 index 0000000..68d62d5 --- /dev/null +++ b/tests/test_project_fixtures/test_non_root_git_project/git/hooks/pre-commit.sample @@ -0,0 +1,49 @@ +#!/bin/sh +# +# An example hook script to verify what is about to be committed. +# Called by "git commit" with no arguments. The hook should +# exit with non-zero status after issuing an appropriate message if +# it wants to stop the commit. +# +# To enable this hook, rename this file to "pre-commit". + +if git rev-parse --verify HEAD >/dev/null 2>&1 +then + against=HEAD +else + # Initial commit: diff against an empty tree object + against=4b825dc642cb6eb9a060e54bf8d69288fbee4904 +fi + +# If you want to allow non-ASCII filenames set this variable to true. +allownonascii=$(git config --bool hooks.allownonascii) + +# Redirect output to stderr. +exec 1>&2 + +# Cross platform projects tend to avoid non-ASCII filenames; prevent +# them from being added to the repository. We exploit the fact that the +# printable range starts at the space character and ends with tilde. +if [ "$allownonascii" != "true" ] && + # Note that the use of brackets around a tr range is ok here, (it's + # even required, for portability to Solaris 10's /usr/bin/tr), since + # the square bracket bytes happen to fall in the designated range. + test $(git diff --cached --name-only --diff-filter=A -z $against | + LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0 +then + cat <<\EOF +Error: Attempt to add a non-ASCII file name. + +This can cause problems if you want to work with people on other platforms. + +To be portable it is advisable to rename the file. + +If you know what you are doing you can disable this check using: + + git config hooks.allownonascii true +EOF + exit 1 +fi + +# If there are whitespace errors, print the offending file names and fail. +exec git diff-index --check --cached $against -- diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/hooks/pre-push.sample b/tests/test_project_fixtures/test_non_root_git_project/git/hooks/pre-push.sample new file mode 100755 index 0000000..6187dbf --- /dev/null +++ b/tests/test_project_fixtures/test_non_root_git_project/git/hooks/pre-push.sample @@ -0,0 +1,53 @@ +#!/bin/sh + +# An example hook script to verify what is about to be pushed. Called by "git +# push" after it has checked the remote status, but before anything has been +# pushed. If this script exits with a non-zero status nothing will be pushed. +# +# This hook is called with the following parameters: +# +# $1 -- Name of the remote to which the push is being done +# $2 -- URL to which the push is being done +# +# If pushing without using a named remote those arguments will be equal. +# +# Information about the commits which are being pushed is supplied as lines to +# the standard input in the form: +# +# +# +# This sample shows how to prevent push of commits where the log message starts +# with "WIP" (work in progress). + +remote="$1" +url="$2" + +z40=0000000000000000000000000000000000000000 + +while read local_ref local_sha remote_ref remote_sha +do + if [ "$local_sha" = $z40 ] + then + # Handle delete + : + else + if [ "$remote_sha" = $z40 ] + then + # New branch, examine all commits + range="$local_sha" + else + # Update to existing branch, examine new commits + range="$remote_sha..$local_sha" + fi + + # Check for WIP commit + commit=`git rev-list -n 1 --grep '^WIP' "$range"` + if [ -n "$commit" ] + then + echo >&2 "Found WIP commit in $local_ref, not pushing" + exit 1 + fi + fi +done + +exit 0 diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/hooks/pre-rebase.sample b/tests/test_project_fixtures/test_non_root_git_project/git/hooks/pre-rebase.sample new file mode 100755 index 0000000..6cbef5c --- /dev/null +++ b/tests/test_project_fixtures/test_non_root_git_project/git/hooks/pre-rebase.sample @@ -0,0 +1,169 @@ +#!/bin/sh +# +# Copyright (c) 2006, 2008 Junio C Hamano +# +# The "pre-rebase" hook is run just before "git rebase" starts doing +# its job, and can prevent the command from running by exiting with +# non-zero status. +# +# The hook is called with the following parameters: +# +# $1 -- the upstream the series was forked from. +# $2 -- the branch being rebased (or empty when rebasing the current branch). +# +# This sample shows how to prevent topic branches that are already +# merged to 'next' branch from getting rebased, because allowing it +# would result in rebasing already published history. + +publish=next +basebranch="$1" +if test "$#" = 2 +then + topic="refs/heads/$2" +else + topic=`git symbolic-ref HEAD` || + exit 0 ;# we do not interrupt rebasing detached HEAD +fi + +case "$topic" in +refs/heads/??/*) + ;; +*) + exit 0 ;# we do not interrupt others. + ;; +esac + +# Now we are dealing with a topic branch being rebased +# on top of master. Is it OK to rebase it? + +# Does the topic really exist? +git show-ref -q "$topic" || { + echo >&2 "No such branch $topic" + exit 1 +} + +# Is topic fully merged to master? +not_in_master=`git rev-list --pretty=oneline ^master "$topic"` +if test -z "$not_in_master" +then + echo >&2 "$topic is fully merged to master; better remove it." + exit 1 ;# we could allow it, but there is no point. +fi + +# Is topic ever merged to next? If so you should not be rebasing it. +only_next_1=`git rev-list ^master "^$topic" ${publish} | sort` +only_next_2=`git rev-list ^master ${publish} | sort` +if test "$only_next_1" = "$only_next_2" +then + not_in_topic=`git rev-list "^$topic" master` + if test -z "$not_in_topic" + then + echo >&2 "$topic is already up to date with master" + exit 1 ;# we could allow it, but there is no point. + else + exit 0 + fi +else + not_in_next=`git rev-list --pretty=oneline ^${publish} "$topic"` + /usr/bin/perl -e ' + my $topic = $ARGV[0]; + my $msg = "* $topic has commits already merged to public branch:\n"; + my (%not_in_next) = map { + /^([0-9a-f]+) /; + ($1 => 1); + } split(/\n/, $ARGV[1]); + for my $elem (map { + /^([0-9a-f]+) (.*)$/; + [$1 => $2]; + } split(/\n/, $ARGV[2])) { + if (!exists $not_in_next{$elem->[0]}) { + if ($msg) { + print STDERR $msg; + undef $msg; + } + print STDERR " $elem->[1]\n"; + } + } + ' "$topic" "$not_in_next" "$not_in_master" + exit 1 +fi + +<<\DOC_END + +This sample hook safeguards topic branches that have been +published from being rewound. + +The workflow assumed here is: + + * Once a topic branch forks from "master", "master" is never + merged into it again (either directly or indirectly). + + * Once a topic branch is fully cooked and merged into "master", + it is deleted. If you need to build on top of it to correct + earlier mistakes, a new topic branch is created by forking at + the tip of the "master". This is not strictly necessary, but + it makes it easier to keep your history simple. + + * Whenever you need to test or publish your changes to topic + branches, merge them into "next" branch. + +The script, being an example, hardcodes the publish branch name +to be "next", but it is trivial to make it configurable via +$GIT_DIR/config mechanism. + +With this workflow, you would want to know: + +(1) ... if a topic branch has ever been merged to "next". Young + topic branches can have stupid mistakes you would rather + clean up before publishing, and things that have not been + merged into other branches can be easily rebased without + affecting other people. But once it is published, you would + not want to rewind it. + +(2) ... if a topic branch has been fully merged to "master". + Then you can delete it. More importantly, you should not + build on top of it -- other people may already want to + change things related to the topic as patches against your + "master", so if you need further changes, it is better to + fork the topic (perhaps with the same name) afresh from the + tip of "master". + +Let's look at this example: + + o---o---o---o---o---o---o---o---o---o "next" + / / / / + / a---a---b A / / + / / / / + / / c---c---c---c B / + / / / \ / + / / / b---b C \ / + / / / / \ / + ---o---o---o---o---o---o---o---o---o---o---o "master" + + +A, B and C are topic branches. + + * A has one fix since it was merged up to "next". + + * B has finished. It has been fully merged up to "master" and "next", + and is ready to be deleted. + + * C has not merged to "next" at all. + +We would want to allow C to be rebased, refuse A, and encourage +B to be deleted. + +To compute (1): + + git rev-list ^master ^topic next + git rev-list ^master next + + if these match, topic has not merged in next at all. + +To compute (2): + + git rev-list master..topic + + if this is empty, it is fully merged to "master". + +DOC_END diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/hooks/pre-receive.sample b/tests/test_project_fixtures/test_non_root_git_project/git/hooks/pre-receive.sample new file mode 100755 index 0000000..a1fd29e --- /dev/null +++ b/tests/test_project_fixtures/test_non_root_git_project/git/hooks/pre-receive.sample @@ -0,0 +1,24 @@ +#!/bin/sh +# +# An example hook script to make use of push options. +# The example simply echoes all push options that start with 'echoback=' +# and rejects all pushes when the "reject" push option is used. +# +# To enable this hook, rename this file to "pre-receive". + +if test -n "$GIT_PUSH_OPTION_COUNT" +then + i=0 + while test "$i" -lt "$GIT_PUSH_OPTION_COUNT" + do + eval "value=\$GIT_PUSH_OPTION_$i" + case "$value" in + echoback=*) + echo "echo from the pre-receive-hook: ${value#*=}" >&2 + ;; + reject) + exit 1 + esac + i=$((i + 1)) + done +fi diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/hooks/prepare-commit-msg.sample b/tests/test_project_fixtures/test_non_root_git_project/git/hooks/prepare-commit-msg.sample new file mode 100755 index 0000000..10fa14c --- /dev/null +++ b/tests/test_project_fixtures/test_non_root_git_project/git/hooks/prepare-commit-msg.sample @@ -0,0 +1,42 @@ +#!/bin/sh +# +# An example hook script to prepare the commit log message. +# Called by "git commit" with the name of the file that has the +# commit message, followed by the description of the commit +# message's source. The hook's purpose is to edit the commit +# message file. If the hook fails with a non-zero status, +# the commit is aborted. +# +# To enable this hook, rename this file to "prepare-commit-msg". + +# This hook includes three examples. The first one removes the +# "# Please enter the commit message..." help message. +# +# The second includes the output of "git diff --name-status -r" +# into the message, just before the "git status" output. It is +# commented because it doesn't cope with --amend or with squashed +# commits. +# +# The third example adds a Signed-off-by line to the message, that can +# still be edited. This is rarely a good idea. + +COMMIT_MSG_FILE=$1 +COMMIT_SOURCE=$2 +SHA1=$3 + +/usr/bin/perl -i.bak -ne 'print unless(m/^. Please enter the commit message/..m/^#$/)' "$COMMIT_MSG_FILE" + +# case "$COMMIT_SOURCE,$SHA1" in +# ,|template,) +# /usr/bin/perl -i.bak -pe ' +# print "\n" . `git diff --cached --name-status -r` +# if /^#/ && $first++ == 0' "$COMMIT_MSG_FILE" ;; +# *) ;; +# esac + +# SOB=$(git var GIT_COMMITTER_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p') +# git interpret-trailers --in-place --trailer "$SOB" "$COMMIT_MSG_FILE" +# if test -z "$COMMIT_SOURCE" +# then +# /usr/bin/perl -i.bak -pe 'print "\n" if !$first_line++' "$COMMIT_MSG_FILE" +# fi diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/hooks/update.sample b/tests/test_project_fixtures/test_non_root_git_project/git/hooks/update.sample new file mode 100755 index 0000000..80ba941 --- /dev/null +++ b/tests/test_project_fixtures/test_non_root_git_project/git/hooks/update.sample @@ -0,0 +1,128 @@ +#!/bin/sh +# +# An example hook script to block unannotated tags from entering. +# Called by "git receive-pack" with arguments: refname sha1-old sha1-new +# +# To enable this hook, rename this file to "update". +# +# Config +# ------ +# hooks.allowunannotated +# This boolean sets whether unannotated tags will be allowed into the +# repository. By default they won't be. +# hooks.allowdeletetag +# This boolean sets whether deleting tags will be allowed in the +# repository. By default they won't be. +# hooks.allowmodifytag +# This boolean sets whether a tag may be modified after creation. By default +# it won't be. +# hooks.allowdeletebranch +# This boolean sets whether deleting branches will be allowed in the +# repository. By default they won't be. +# hooks.denycreatebranch +# This boolean sets whether remotely creating branches will be denied +# in the repository. By default this is allowed. +# + +# --- Command line +refname="$1" +oldrev="$2" +newrev="$3" + +# --- Safety check +if [ -z "$GIT_DIR" ]; then + echo "Don't run this script from the command line." >&2 + echo " (if you want, you could supply GIT_DIR then run" >&2 + echo " $0 )" >&2 + exit 1 +fi + +if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then + echo "usage: $0 " >&2 + exit 1 +fi + +# --- Config +allowunannotated=$(git config --bool hooks.allowunannotated) +allowdeletebranch=$(git config --bool hooks.allowdeletebranch) +denycreatebranch=$(git config --bool hooks.denycreatebranch) +allowdeletetag=$(git config --bool hooks.allowdeletetag) +allowmodifytag=$(git config --bool hooks.allowmodifytag) + +# check for no description +projectdesc=$(sed -e '1q' "$GIT_DIR/description") +case "$projectdesc" in +"Unnamed repository"* | "") + echo "*** Project description file hasn't been set" >&2 + exit 1 + ;; +esac + +# --- Check types +# if $newrev is 0000...0000, it's a commit to delete a ref. +zero="0000000000000000000000000000000000000000" +if [ "$newrev" = "$zero" ]; then + newrev_type=delete +else + newrev_type=$(git cat-file -t $newrev) +fi + +case "$refname","$newrev_type" in + refs/tags/*,commit) + # un-annotated tag + short_refname=${refname##refs/tags/} + if [ "$allowunannotated" != "true" ]; then + echo "*** The un-annotated tag, $short_refname, is not allowed in this repository" >&2 + echo "*** Use 'git tag [ -a | -s ]' for tags you want to propagate." >&2 + exit 1 + fi + ;; + refs/tags/*,delete) + # delete tag + if [ "$allowdeletetag" != "true" ]; then + echo "*** Deleting a tag is not allowed in this repository" >&2 + exit 1 + fi + ;; + refs/tags/*,tag) + # annotated tag + if [ "$allowmodifytag" != "true" ] && git rev-parse $refname > /dev/null 2>&1 + then + echo "*** Tag '$refname' already exists." >&2 + echo "*** Modifying a tag is not allowed in this repository." >&2 + exit 1 + fi + ;; + refs/heads/*,commit) + # branch + if [ "$oldrev" = "$zero" -a "$denycreatebranch" = "true" ]; then + echo "*** Creating a branch is not allowed in this repository" >&2 + exit 1 + fi + ;; + refs/heads/*,delete) + # delete branch + if [ "$allowdeletebranch" != "true" ]; then + echo "*** Deleting a branch is not allowed in this repository" >&2 + exit 1 + fi + ;; + refs/remotes/*,commit) + # tracking branch + ;; + refs/remotes/*,delete) + # delete tracking branch + if [ "$allowdeletebranch" != "true" ]; then + echo "*** Deleting a tracking branch is not allowed in this repository" >&2 + exit 1 + fi + ;; + *) + # Anything else (is there anything else?) + echo "*** Update hook: unknown type of update to ref $refname of type $newrev_type" >&2 + exit 1 + ;; +esac + +# --- Finished +exit 0 diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/index b/tests/test_project_fixtures/test_non_root_git_project/git/index new file mode 100644 index 0000000..dbd8c5d Binary files /dev/null and b/tests/test_project_fixtures/test_non_root_git_project/git/index differ diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/info/exclude b/tests/test_project_fixtures/test_non_root_git_project/git/info/exclude new file mode 100644 index 0000000..a5196d1 --- /dev/null +++ b/tests/test_project_fixtures/test_non_root_git_project/git/info/exclude @@ -0,0 +1,6 @@ +# git ls-files --others --exclude-from=.git/info/exclude +# Lines that start with '#' are comments. +# For a project mostly in C, the following would be a good set of +# exclude patterns (uncomment them if you want to use them): +# *.[oa] +# *~ diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/logs/HEAD b/tests/test_project_fixtures/test_non_root_git_project/git/logs/HEAD new file mode 100644 index 0000000..e3682ee --- /dev/null +++ b/tests/test_project_fixtures/test_non_root_git_project/git/logs/HEAD @@ -0,0 +1,6 @@ +0000000000000000000000000000000000000000 30b505e031fc496c88d36be5ed7892337c640223 David Wobrock 1547980206 +0100 commit (initial): init +30b505e031fc496c88d36be5ed7892337c640223 a3f20003e5407a44000854c41ba29c06a3bbba82 David Wobrock 1547980230 +0100 commit (amend): init +a3f20003e5407a44000854c41ba29c06a3bbba82 0e52dc2380789e401cf385d3376af39f4bb6598f David Wobrock 1547980287 +0100 commit (amend): init +0e52dc2380789e401cf385d3376af39f4bb6598f 0140e142724fc58944797f9ddc2ebf964146339a David Wobrock 1547980306 +0100 commit: init migration +0140e142724fc58944797f9ddc2ebf964146339a 2c46f438a89972f9ce2d5151a825a5bfb7f7db4b David Wobrock 1547980356 +0100 commit: add ko migration +2c46f438a89972f9ce2d5151a825a5bfb7f7db4b f122245e6a3ce63b99e0beeb8403031edd08ed50 David Wobrock 1547980398 +0100 commit: Add ok migration diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/logs/refs/heads/master b/tests/test_project_fixtures/test_non_root_git_project/git/logs/refs/heads/master new file mode 100644 index 0000000..e3682ee --- /dev/null +++ b/tests/test_project_fixtures/test_non_root_git_project/git/logs/refs/heads/master @@ -0,0 +1,6 @@ +0000000000000000000000000000000000000000 30b505e031fc496c88d36be5ed7892337c640223 David Wobrock 1547980206 +0100 commit (initial): init +30b505e031fc496c88d36be5ed7892337c640223 a3f20003e5407a44000854c41ba29c06a3bbba82 David Wobrock 1547980230 +0100 commit (amend): init +a3f20003e5407a44000854c41ba29c06a3bbba82 0e52dc2380789e401cf385d3376af39f4bb6598f David Wobrock 1547980287 +0100 commit (amend): init +0e52dc2380789e401cf385d3376af39f4bb6598f 0140e142724fc58944797f9ddc2ebf964146339a David Wobrock 1547980306 +0100 commit: init migration +0140e142724fc58944797f9ddc2ebf964146339a 2c46f438a89972f9ce2d5151a825a5bfb7f7db4b David Wobrock 1547980356 +0100 commit: add ko migration +2c46f438a89972f9ce2d5151a825a5bfb7f7db4b f122245e6a3ce63b99e0beeb8403031edd08ed50 David Wobrock 1547980398 +0100 commit: Add ok migration diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/objects/01/40e142724fc58944797f9ddc2ebf964146339a b/tests/test_project_fixtures/test_non_root_git_project/git/objects/01/40e142724fc58944797f9ddc2ebf964146339a new file mode 100644 index 0000000..3b6c8db --- /dev/null +++ b/tests/test_project_fixtures/test_non_root_git_project/git/objects/01/40e142724fc58944797f9ddc2ebf964146339a @@ -0,0 +1,2 @@ +x¥�Á +!E[ûîƒáéÓ…ˆýCk}ê$åbõû}BËsáî¥ZJî\*±ë-FnÒL„h¼I6H��¤Á*oÑ&OJR¤ØÃµ¸uQË@ ,ÆF‚—Ù¥QPÞÏÚšÄܳ_kãg÷Ê�_ªo•nü¾8½xZ‹Ë÷‰j9r¡Õb Ì|€�t íñËÛ¸ZòÚ\Ïuc�¿M1 \ No newline at end of file diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/objects/0e/52dc2380789e401cf385d3376af39f4bb6598f b/tests/test_project_fixtures/test_non_root_git_project/git/objects/0e/52dc2380789e401cf385d3376af39f4bb6598f new file mode 100644 index 0000000..e6f6376 Binary files /dev/null and b/tests/test_project_fixtures/test_non_root_git_project/git/objects/0e/52dc2380789e401cf385d3376af39f4bb6598f differ diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/objects/15/d47f23b30965a0ef668af1e639a23634e4532a b/tests/test_project_fixtures/test_non_root_git_project/git/objects/15/d47f23b30965a0ef668af1e639a23634e4532a new file mode 100644 index 0000000..359a966 Binary files /dev/null and b/tests/test_project_fixtures/test_non_root_git_project/git/objects/15/d47f23b30965a0ef668af1e639a23634e4532a differ diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/objects/16/8e382963b2ef0de835c22c48c2bf3a702e83a0 b/tests/test_project_fixtures/test_non_root_git_project/git/objects/16/8e382963b2ef0de835c22c48c2bf3a702e83a0 new file mode 100644 index 0000000..0835b5a Binary files /dev/null and b/tests/test_project_fixtures/test_non_root_git_project/git/objects/16/8e382963b2ef0de835c22c48c2bf3a702e83a0 differ diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/objects/1c/dc834ac63fc5edefbbdcabf264026ccc8cf4a7 b/tests/test_project_fixtures/test_non_root_git_project/git/objects/1c/dc834ac63fc5edefbbdcabf264026ccc8cf4a7 new file mode 100644 index 0000000..e0b776b Binary files /dev/null and b/tests/test_project_fixtures/test_non_root_git_project/git/objects/1c/dc834ac63fc5edefbbdcabf264026ccc8cf4a7 differ diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/objects/1d/c36fd270ce97d05f4fa75c3c16917951d71768 b/tests/test_project_fixtures/test_non_root_git_project/git/objects/1d/c36fd270ce97d05f4fa75c3c16917951d71768 new file mode 100644 index 0000000..829448e Binary files /dev/null and b/tests/test_project_fixtures/test_non_root_git_project/git/objects/1d/c36fd270ce97d05f4fa75c3c16917951d71768 differ diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/objects/21/a03f36ba451433c9fefe71d9fd05e80cefe458 b/tests/test_project_fixtures/test_non_root_git_project/git/objects/21/a03f36ba451433c9fefe71d9fd05e80cefe458 new file mode 100644 index 0000000..8db52c7 Binary files /dev/null and b/tests/test_project_fixtures/test_non_root_git_project/git/objects/21/a03f36ba451433c9fefe71d9fd05e80cefe458 differ diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/objects/29/56309db5fd77d3474462f613653d73787f214f b/tests/test_project_fixtures/test_non_root_git_project/git/objects/29/56309db5fd77d3474462f613653d73787f214f new file mode 100644 index 0000000..215b13d Binary files /dev/null and b/tests/test_project_fixtures/test_non_root_git_project/git/objects/29/56309db5fd77d3474462f613653d73787f214f differ diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/objects/2c/46f438a89972f9ce2d5151a825a5bfb7f7db4b b/tests/test_project_fixtures/test_non_root_git_project/git/objects/2c/46f438a89972f9ce2d5151a825a5bfb7f7db4b new file mode 100644 index 0000000..a022075 --- /dev/null +++ b/tests/test_project_fixtures/test_non_root_git_project/git/objects/2c/46f438a89972f9ce2d5151a825a5bfb7f7db4b @@ -0,0 +1,4 @@ +x¥ŽM!ƒ]sŠ·7™ðó˜�ÄÞÁ5ð`$Ê`êõÅxÓÕ×´MC-%w�¨v½ÅÞ�CLA%3›”P`M¼ \ No newline at end of file diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/objects/2c/5613c15e0a45ad460b4973dcdf942846b77b72 b/tests/test_project_fixtures/test_non_root_git_project/git/objects/2c/5613c15e0a45ad460b4973dcdf942846b77b72 new file mode 100644 index 0000000..71c146a Binary files /dev/null and b/tests/test_project_fixtures/test_non_root_git_project/git/objects/2c/5613c15e0a45ad460b4973dcdf942846b77b72 differ diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/objects/2f/3fa93ad05c33e1d0ccda111d881e192bccbc87 b/tests/test_project_fixtures/test_non_root_git_project/git/objects/2f/3fa93ad05c33e1d0ccda111d881e192bccbc87 new file mode 100644 index 0000000..b6b9461 Binary files /dev/null and b/tests/test_project_fixtures/test_non_root_git_project/git/objects/2f/3fa93ad05c33e1d0ccda111d881e192bccbc87 differ diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/objects/30/b505e031fc496c88d36be5ed7892337c640223 b/tests/test_project_fixtures/test_non_root_git_project/git/objects/30/b505e031fc496c88d36be5ed7892337c640223 new file mode 100644 index 0000000..f49d09e --- /dev/null +++ b/tests/test_project_fixtures/test_non_root_git_project/git/objects/30/b505e031fc496c88d36be5ed7892337c640223 @@ -0,0 +1,2 @@ +x¥�; +1@­sŠé…eÆ$ÎD,¼ƒõä§A³�õú®xË÷Š÷B«µ  YoFO |¦¤9EC죓�mÊFŒql3û µ!Qò·Öá,¯áÒ|oá‡øÅéýÃÓµJyL¡Õ#�5ìfÜá¶Hˆjµëx¤?ª,e¨tð<| \ No newline at end of file diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/objects/33/90cc679ea02b9ad1a57dc6ef711255b4f4d90c b/tests/test_project_fixtures/test_non_root_git_project/git/objects/33/90cc679ea02b9ad1a57dc6ef711255b4f4d90c new file mode 100644 index 0000000..7d7f517 Binary files /dev/null and b/tests/test_project_fixtures/test_non_root_git_project/git/objects/33/90cc679ea02b9ad1a57dc6ef711255b4f4d90c differ diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/objects/41/07cf9a6c4633c97bd7ee2a73353c88deca64a4 b/tests/test_project_fixtures/test_non_root_git_project/git/objects/41/07cf9a6c4633c97bd7ee2a73353c88deca64a4 new file mode 100644 index 0000000..90e5aac Binary files /dev/null and b/tests/test_project_fixtures/test_non_root_git_project/git/objects/41/07cf9a6c4633c97bd7ee2a73353c88deca64a4 differ diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/objects/43/4e403e49cc1e2037d29695e0cb6477f20acc2e b/tests/test_project_fixtures/test_non_root_git_project/git/objects/43/4e403e49cc1e2037d29695e0cb6477f20acc2e new file mode 100644 index 0000000..4a2e35f Binary files /dev/null and b/tests/test_project_fixtures/test_non_root_git_project/git/objects/43/4e403e49cc1e2037d29695e0cb6477f20acc2e differ diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/objects/4a/d7b8980d409199892bb78d1c77164fc6446993 b/tests/test_project_fixtures/test_non_root_git_project/git/objects/4a/d7b8980d409199892bb78d1c77164fc6446993 new file mode 100644 index 0000000..b0463b9 Binary files /dev/null and b/tests/test_project_fixtures/test_non_root_git_project/git/objects/4a/d7b8980d409199892bb78d1c77164fc6446993 differ diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/objects/4b/0dddde301971fc19f1817a22bf0948890ccacc b/tests/test_project_fixtures/test_non_root_git_project/git/objects/4b/0dddde301971fc19f1817a22bf0948890ccacc new file mode 100644 index 0000000..26178f2 Binary files /dev/null and b/tests/test_project_fixtures/test_non_root_git_project/git/objects/4b/0dddde301971fc19f1817a22bf0948890ccacc differ diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/objects/4c/f37def1d191c7c4b34e1053fa923e6d649525a b/tests/test_project_fixtures/test_non_root_git_project/git/objects/4c/f37def1d191c7c4b34e1053fa923e6d649525a new file mode 100644 index 0000000..e152596 Binary files /dev/null and b/tests/test_project_fixtures/test_non_root_git_project/git/objects/4c/f37def1d191c7c4b34e1053fa923e6d649525a differ diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/objects/4d/00aeaddee6c0c490e5018fa1d40b3fb4fd55a4 b/tests/test_project_fixtures/test_non_root_git_project/git/objects/4d/00aeaddee6c0c490e5018fa1d40b3fb4fd55a4 new file mode 100644 index 0000000..e213d67 Binary files /dev/null and b/tests/test_project_fixtures/test_non_root_git_project/git/objects/4d/00aeaddee6c0c490e5018fa1d40b3fb4fd55a4 differ diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/objects/56/26f87a33217c62ed70006bda0735aaa8578ee7 b/tests/test_project_fixtures/test_non_root_git_project/git/objects/56/26f87a33217c62ed70006bda0735aaa8578ee7 new file mode 100644 index 0000000..fa9f1c0 Binary files /dev/null and b/tests/test_project_fixtures/test_non_root_git_project/git/objects/56/26f87a33217c62ed70006bda0735aaa8578ee7 differ diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/objects/57/97dee69dcb584dede25d7c02d34caf96d70236 b/tests/test_project_fixtures/test_non_root_git_project/git/objects/57/97dee69dcb584dede25d7c02d34caf96d70236 new file mode 100644 index 0000000..b20e733 Binary files /dev/null and b/tests/test_project_fixtures/test_non_root_git_project/git/objects/57/97dee69dcb584dede25d7c02d34caf96d70236 differ diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/objects/59/e2ac235a403799063c7e7f2a137c462ac17ba2 b/tests/test_project_fixtures/test_non_root_git_project/git/objects/59/e2ac235a403799063c7e7f2a137c462ac17ba2 new file mode 100644 index 0000000..1d2d86c Binary files /dev/null and b/tests/test_project_fixtures/test_non_root_git_project/git/objects/59/e2ac235a403799063c7e7f2a137c462ac17ba2 differ diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/objects/5c/f2c8f1e59f99ac2de981abf2b6adf6279ea3da b/tests/test_project_fixtures/test_non_root_git_project/git/objects/5c/f2c8f1e59f99ac2de981abf2b6adf6279ea3da new file mode 100644 index 0000000..64d0dfa Binary files /dev/null and b/tests/test_project_fixtures/test_non_root_git_project/git/objects/5c/f2c8f1e59f99ac2de981abf2b6adf6279ea3da differ diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/objects/6b/f17bf7104d256ef447c26ecb37124331d29cae b/tests/test_project_fixtures/test_non_root_git_project/git/objects/6b/f17bf7104d256ef447c26ecb37124331d29cae new file mode 100644 index 0000000..b3da19a Binary files /dev/null and b/tests/test_project_fixtures/test_non_root_git_project/git/objects/6b/f17bf7104d256ef447c26ecb37124331d29cae differ diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/objects/73/5de5db8bc5e1ed29b3cb7ece62b5e7c8db06ee b/tests/test_project_fixtures/test_non_root_git_project/git/objects/73/5de5db8bc5e1ed29b3cb7ece62b5e7c8db06ee new file mode 100644 index 0000000..66ccc09 Binary files /dev/null and b/tests/test_project_fixtures/test_non_root_git_project/git/objects/73/5de5db8bc5e1ed29b3cb7ece62b5e7c8db06ee differ diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/objects/7c/dae90d4510701438cf671bb67772202f825891 b/tests/test_project_fixtures/test_non_root_git_project/git/objects/7c/dae90d4510701438cf671bb67772202f825891 new file mode 100644 index 0000000..f03c030 --- /dev/null +++ b/tests/test_project_fixtures/test_non_root_git_project/git/objects/7c/dae90d4510701438cf671bb67772202f825891 @@ -0,0 +1 @@ +x+)JMU0´0a040031Q0000ŒÏÌË,ÉLÌÑ+¨d˜½U´ä’}jZ$Ï·ÝsKd¸e?°G(5ŠOŒÏ+ÍɉOËLÍI‰7é½R¯¼™3uÁû´®�Ï,™™< ÖBè0éÈÏCÒÒÓ¿OšËÒ¿N1~η+}Ýoà“i€ê‰»&>¤ìÙÜG³7]¼æìÝ­¹®<êÆ¡'=Áå,JU \ No newline at end of file diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/objects/7c/e503c2dd97ba78597f6ff6e4393132753573f6 b/tests/test_project_fixtures/test_non_root_git_project/git/objects/7c/e503c2dd97ba78597f6ff6e4393132753573f6 new file mode 100644 index 0000000..250bef6 Binary files /dev/null and b/tests/test_project_fixtures/test_non_root_git_project/git/objects/7c/e503c2dd97ba78597f6ff6e4393132753573f6 differ diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/objects/81/45e446f728f9ed6ba04294b4c880be74383949 b/tests/test_project_fixtures/test_non_root_git_project/git/objects/81/45e446f728f9ed6ba04294b4c880be74383949 new file mode 100644 index 0000000..84e0a13 Binary files /dev/null and b/tests/test_project_fixtures/test_non_root_git_project/git/objects/81/45e446f728f9ed6ba04294b4c880be74383949 differ diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/objects/82/bc1ebd64ca46c16193d8f8407127f0f3e4164c b/tests/test_project_fixtures/test_non_root_git_project/git/objects/82/bc1ebd64ca46c16193d8f8407127f0f3e4164c new file mode 100644 index 0000000..bdee280 --- /dev/null +++ b/tests/test_project_fixtures/test_non_root_git_project/git/objects/82/bc1ebd64ca46c16193d8f8407127f0f3e4164c @@ -0,0 +1,2 @@ +x]ŽÁ +Â0 @+zAð<î2«âQDðîÅ«XºµÎŒµ)m&úÝþ€™ò/!IÑ`1_/7bøšN.³Ã¹} ¸î9Óˆa„8e�9f ñ‡Ô²“7tV}#M­}…¹ƒ*jôyžl”d¥UˆXÛ’ÔÔFÛÛcìlßýŽêVò·+I¥À)µOóå­CÓ6v×ý—8ÅÇ!:L \ No newline at end of file diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/objects/84/8eee04718d10f32f59ff9ae63afd8478ef68c4 b/tests/test_project_fixtures/test_non_root_git_project/git/objects/84/8eee04718d10f32f59ff9ae63afd8478ef68c4 new file mode 100644 index 0000000..d41572a Binary files /dev/null and b/tests/test_project_fixtures/test_non_root_git_project/git/objects/84/8eee04718d10f32f59ff9ae63afd8478ef68c4 differ diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/objects/88/c4bb3d2e2aa1968f90484f0b6cd77b7c4f7c57 b/tests/test_project_fixtures/test_non_root_git_project/git/objects/88/c4bb3d2e2aa1968f90484f0b6cd77b7c4f7c57 new file mode 100644 index 0000000..3f19464 Binary files /dev/null and b/tests/test_project_fixtures/test_non_root_git_project/git/objects/88/c4bb3d2e2aa1968f90484f0b6cd77b7c4f7c57 differ diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/objects/89/5be6939590f9199877bf41d9fe2ca0f5f501eb b/tests/test_project_fixtures/test_non_root_git_project/git/objects/89/5be6939590f9199877bf41d9fe2ca0f5f501eb new file mode 100644 index 0000000..3e08383 Binary files /dev/null and b/tests/test_project_fixtures/test_non_root_git_project/git/objects/89/5be6939590f9199877bf41d9fe2ca0f5f501eb differ diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/objects/8c/38f3f3dad51e4585f3984282c2a4bec5349c1e b/tests/test_project_fixtures/test_non_root_git_project/git/objects/8c/38f3f3dad51e4585f3984282c2a4bec5349c1e new file mode 100644 index 0000000..e68f806 Binary files /dev/null and b/tests/test_project_fixtures/test_non_root_git_project/git/objects/8c/38f3f3dad51e4585f3984282c2a4bec5349c1e differ diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/objects/8f/255685e632623f016e1ecf18a4e9d58746e1ce b/tests/test_project_fixtures/test_non_root_git_project/git/objects/8f/255685e632623f016e1ecf18a4e9d58746e1ce new file mode 100644 index 0000000..2299381 Binary files /dev/null and b/tests/test_project_fixtures/test_non_root_git_project/git/objects/8f/255685e632623f016e1ecf18a4e9d58746e1ce differ diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/objects/8f/be1b0a394f7e215f9cf6d48e8bfdc3b00e1c80 b/tests/test_project_fixtures/test_non_root_git_project/git/objects/8f/be1b0a394f7e215f9cf6d48e8bfdc3b00e1c80 new file mode 100644 index 0000000..c09f99a Binary files /dev/null and b/tests/test_project_fixtures/test_non_root_git_project/git/objects/8f/be1b0a394f7e215f9cf6d48e8bfdc3b00e1c80 differ diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/objects/91/3c6cc338b8f9d2530f21dd94b939fbc42cf1c4 b/tests/test_project_fixtures/test_non_root_git_project/git/objects/91/3c6cc338b8f9d2530f21dd94b939fbc42cf1c4 new file mode 100644 index 0000000..e62ddc5 Binary files /dev/null and b/tests/test_project_fixtures/test_non_root_git_project/git/objects/91/3c6cc338b8f9d2530f21dd94b939fbc42cf1c4 differ diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/objects/91/ea44a218fbd2f408430959283f0419c921093e b/tests/test_project_fixtures/test_non_root_git_project/git/objects/91/ea44a218fbd2f408430959283f0419c921093e new file mode 100644 index 0000000..263fc8c Binary files /dev/null and b/tests/test_project_fixtures/test_non_root_git_project/git/objects/91/ea44a218fbd2f408430959283f0419c921093e differ diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/objects/98/6913f97e6222f14be4db7d10e90430cc43cc4d b/tests/test_project_fixtures/test_non_root_git_project/git/objects/98/6913f97e6222f14be4db7d10e90430cc43cc4d new file mode 100644 index 0000000..c2660a4 Binary files /dev/null and b/tests/test_project_fixtures/test_non_root_git_project/git/objects/98/6913f97e6222f14be4db7d10e90430cc43cc4d differ diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/objects/9b/353778696f76f0288affbc392eeefa4df70e90 b/tests/test_project_fixtures/test_non_root_git_project/git/objects/9b/353778696f76f0288affbc392eeefa4df70e90 new file mode 100644 index 0000000..961f157 Binary files /dev/null and b/tests/test_project_fixtures/test_non_root_git_project/git/objects/9b/353778696f76f0288affbc392eeefa4df70e90 differ diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/objects/9b/b51574d23f6566590cf6bb9ce31868466be03f b/tests/test_project_fixtures/test_non_root_git_project/git/objects/9b/b51574d23f6566590cf6bb9ce31868466be03f new file mode 100644 index 0000000..d07a118 --- /dev/null +++ b/tests/test_project_fixtures/test_non_root_git_project/git/objects/9b/b51574d23f6566590cf6bb9ce31868466be03f @@ -0,0 +1,5 @@ +x]PËjÃ0ìY_±�ƒ�;m! øRrÈ­·„m­�ZY2zÒ¯¯d%MSa„™™�™U#TO�Ë»d÷´ŠqÙ¯ÁÙ.[„Ìà%êÚ"ƒæÛ�Zö +ʼôß +”„eQ>gE™- (‹õCI:­ ´sÖi¤ø0*mÁIîÝ‘ +n½�0$ +Ùd˜³æ¢xïÓ¸’fƒJÒŠÚ8\¨ô*ÊÁùšð‡Kny- ‚7í0b G” eËÑxâ}#§Æ°^üe‚ÍŸˆ�~ÿC(“N“�GÖVÉ&YÜ GÁLC¢0ÞiÂYrÙ*ß8«vAšÖþ�¶S«B錚µ>ÑO<�ƒÚoÅ¿±Úù×ó’/Ô�2Hc‰ý6™Ïo{„Ð4‘N:UºFï¥ÅuLÿ?v¼ºœ �äÓØŸº \ No newline at end of file diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/objects/9d/1dcfdaf1a6857c5f83dc27019c7600e1ffaff8 b/tests/test_project_fixtures/test_non_root_git_project/git/objects/9d/1dcfdaf1a6857c5f83dc27019c7600e1ffaff8 new file mode 100644 index 0000000..0f6ee3b Binary files /dev/null and b/tests/test_project_fixtures/test_non_root_git_project/git/objects/9d/1dcfdaf1a6857c5f83dc27019c7600e1ffaff8 differ diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/objects/a3/f20003e5407a44000854c41ba29c06a3bbba82 b/tests/test_project_fixtures/test_non_root_git_project/git/objects/a3/f20003e5407a44000854c41ba29c06a3bbba82 new file mode 100644 index 0000000..95bd2eb Binary files /dev/null and b/tests/test_project_fixtures/test_non_root_git_project/git/objects/a3/f20003e5407a44000854c41ba29c06a3bbba82 differ diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/objects/aa/66ac1debe2ae5fd39cd8e65f6dfd9786649490 b/tests/test_project_fixtures/test_non_root_git_project/git/objects/aa/66ac1debe2ae5fd39cd8e65f6dfd9786649490 new file mode 100644 index 0000000..6ec0e99 Binary files /dev/null and b/tests/test_project_fixtures/test_non_root_git_project/git/objects/aa/66ac1debe2ae5fd39cd8e65f6dfd9786649490 differ diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/objects/b8/da44fc3f868ffbd94e347927f138be8b5b5b2d b/tests/test_project_fixtures/test_non_root_git_project/git/objects/b8/da44fc3f868ffbd94e347927f138be8b5b5b2d new file mode 100644 index 0000000..416d9b8 Binary files /dev/null and b/tests/test_project_fixtures/test_non_root_git_project/git/objects/b8/da44fc3f868ffbd94e347927f138be8b5b5b2d differ diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/objects/bd/fc3d5864d2ad429269f80d739ef58ded2d4b35 b/tests/test_project_fixtures/test_non_root_git_project/git/objects/bd/fc3d5864d2ad429269f80d739ef58ded2d4b35 new file mode 100644 index 0000000..7bfac15 Binary files /dev/null and b/tests/test_project_fixtures/test_non_root_git_project/git/objects/bd/fc3d5864d2ad429269f80d739ef58ded2d4b35 differ diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/objects/bf/a71e37ed417bd9acf5ef4a44975f7bfd10341a b/tests/test_project_fixtures/test_non_root_git_project/git/objects/bf/a71e37ed417bd9acf5ef4a44975f7bfd10341a new file mode 100644 index 0000000..b4d68db Binary files /dev/null and b/tests/test_project_fixtures/test_non_root_git_project/git/objects/bf/a71e37ed417bd9acf5ef4a44975f7bfd10341a differ diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/objects/cb/96855f9aa7aae003123eca1addad870c7b8fde b/tests/test_project_fixtures/test_non_root_git_project/git/objects/cb/96855f9aa7aae003123eca1addad870c7b8fde new file mode 100644 index 0000000..df8c6f3 Binary files /dev/null and b/tests/test_project_fixtures/test_non_root_git_project/git/objects/cb/96855f9aa7aae003123eca1addad870c7b8fde differ diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 b/tests/test_project_fixtures/test_non_root_git_project/git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 new file mode 100644 index 0000000..7112238 Binary files /dev/null and b/tests/test_project_fixtures/test_non_root_git_project/git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 differ diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/objects/ea/9048c5860ddad87cb377574bd627fa4a7ccd4c b/tests/test_project_fixtures/test_non_root_git_project/git/objects/ea/9048c5860ddad87cb377574bd627fa4a7ccd4c new file mode 100644 index 0000000..c0f30e5 Binary files /dev/null and b/tests/test_project_fixtures/test_non_root_git_project/git/objects/ea/9048c5860ddad87cb377574bd627fa4a7ccd4c differ diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/objects/f1/22245e6a3ce63b99e0beeb8403031edd08ed50 b/tests/test_project_fixtures/test_non_root_git_project/git/objects/f1/22245e6a3ce63b99e0beeb8403031edd08ed50 new file mode 100644 index 0000000..343ce14 --- /dev/null +++ b/tests/test_project_fixtures/test_non_root_git_project/git/objects/f1/22245e6a3ce63b99e0beeb8403031edd08ed50 @@ -0,0 +1 @@ +x¥ŽAj1 E»ö)´�GÙPJ½Cײd§&u\ŒÓ^¿Sr„,߇÷yÒ[«®/sä ™£Å >lV•5�¤•È&ÝF&E1ß<òm·‚kà#¹%;õ‹_88Ï>•D…4a2|ŸŸ}À;ÿT…�žF—+¼ê?xº4®_Géí �ƒ]c€ƒ]¬5ûº‡ÎüÄ…9«B¿B«—Á³ö›ùÖ‚Nˆ \ No newline at end of file diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/objects/f1/ff8f0c6cca456e2e132263fd70ac9593ac1b53 b/tests/test_project_fixtures/test_non_root_git_project/git/objects/f1/ff8f0c6cca456e2e132263fd70ac9593ac1b53 new file mode 100644 index 0000000..19affa3 Binary files /dev/null and b/tests/test_project_fixtures/test_non_root_git_project/git/objects/f1/ff8f0c6cca456e2e132263fd70ac9593ac1b53 differ diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/objects/f6/7bb4d66d0955079a1365ba91ae91671796ce85 b/tests/test_project_fixtures/test_non_root_git_project/git/objects/f6/7bb4d66d0955079a1365ba91ae91671796ce85 new file mode 100644 index 0000000..1ee1d03 Binary files /dev/null and b/tests/test_project_fixtures/test_non_root_git_project/git/objects/f6/7bb4d66d0955079a1365ba91ae91671796ce85 differ diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/objects/f6/a170bb234332d6ecef3b4348f2da0e758c59a7 b/tests/test_project_fixtures/test_non_root_git_project/git/objects/f6/a170bb234332d6ecef3b4348f2da0e758c59a7 new file mode 100644 index 0000000..ea64db9 Binary files /dev/null and b/tests/test_project_fixtures/test_non_root_git_project/git/objects/f6/a170bb234332d6ecef3b4348f2da0e758c59a7 differ diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/objects/fb/3701d6fd9f5fa295ab981f9fac08c3156045d2 b/tests/test_project_fixtures/test_non_root_git_project/git/objects/fb/3701d6fd9f5fa295ab981f9fac08c3156045d2 new file mode 100644 index 0000000..0f1de85 Binary files /dev/null and b/tests/test_project_fixtures/test_non_root_git_project/git/objects/fb/3701d6fd9f5fa295ab981f9fac08c3156045d2 differ diff --git a/tests/test_project_fixtures/test_non_root_git_project/git/refs/heads/master b/tests/test_project_fixtures/test_non_root_git_project/git/refs/heads/master new file mode 100644 index 0000000..7ceae76 --- /dev/null +++ b/tests/test_project_fixtures/test_non_root_git_project/git/refs/heads/master @@ -0,0 +1 @@ +f122245e6a3ce63b99e0beeb8403031edd08ed50 diff --git a/tests/test_project_fixtures/test_project_create_table_with_not_null_column/test_app/migrations/0002_b_foreign_keys.py b/tests/test_project_fixtures/test_project_create_table_with_not_null_column/test_app/migrations/0002_b_foreign_keys.py new file mode 100644 index 0000000..9ffdb89 --- /dev/null +++ b/tests/test_project_fixtures/test_project_create_table_with_not_null_column/test_app/migrations/0002_b_foreign_keys.py @@ -0,0 +1,22 @@ +# Generated by Django 2.0.1 on 2018-05-07 18:35 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('test_app', '0001_create_table_with_not_null_field'), + ] + + operations = [ + migrations.CreateModel( + name='B', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('not_null_fk', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='nn_b', to='test_app.A')), + ('null_fk', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='b', to='test_app.A')), + ], + ), + ] diff --git a/tests/test_project_fixtures/test_project_create_table_with_not_null_column/test_app/models.py b/tests/test_project_fixtures/test_project_create_table_with_not_null_column/test_app/models.py index 76cc5dc..b347a42 100644 --- a/tests/test_project_fixtures/test_project_create_table_with_not_null_column/test_app/models.py +++ b/tests/test_project_fixtures/test_project_create_table_with_not_null_column/test_app/models.py @@ -2,3 +2,8 @@ from django.db import models class A(models.Model): not_null_field = models.IntegerField(null=False) + + +class B(models.Model): + not_null_fk = models.ForeignKey(to=A, null=False, on_delete=models.CASCADE, related_name='nn_b') + null_fk = models.ForeignKey(to=A, null=True, on_delete=models.CASCADE, related_name='b') diff --git a/tests/test_project_fixtures/test_project_ignore_migration/.gitignore b/tests/test_project_fixtures/test_project_ignore_migration/.gitignore new file mode 100644 index 0000000..63973d0 --- /dev/null +++ b/tests/test_project_fixtures/test_project_ignore_migration/.gitignore @@ -0,0 +1,3 @@ +*.pyc +__pycache__/ +*sqlite3 diff --git a/tests/test_project_fixtures/test_project_ignore_migration/manage.py b/tests/test_project_fixtures/test_project_ignore_migration/manage.py new file mode 100644 index 0000000..eba4c1f --- /dev/null +++ b/tests/test_project_fixtures/test_project_ignore_migration/manage.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +import os +import sys + +if __name__ == "__main__": + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "test_project_ignore_migration.settings") + try: + from django.core.management import execute_from_command_line + except ImportError: + # The above import may fail for some other reason. Ensure that the + # issue is really that Django is missing to avoid masking other + # exceptions on Python 2. + try: + import django + except ImportError: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) + raise + execute_from_command_line(sys.argv) diff --git a/tests/test_project_fixtures/test_project_ignore_migration/test_app/__init__.py b/tests/test_project_fixtures/test_project_ignore_migration/test_app/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_project_fixtures/test_project_ignore_migration/test_app/admin.py b/tests/test_project_fixtures/test_project_ignore_migration/test_app/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/tests/test_project_fixtures/test_project_ignore_migration/test_app/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/tests/test_project_fixtures/test_project_ignore_migration/test_app/apps.py b/tests/test_project_fixtures/test_project_ignore_migration/test_app/apps.py new file mode 100644 index 0000000..fc04070 --- /dev/null +++ b/tests/test_project_fixtures/test_project_ignore_migration/test_app/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class TestAppConfig(AppConfig): + name = 'test_app' diff --git a/tests/test_project_fixtures/test_project_ignore_migration/test_app/migrations/0001_create_table.py b/tests/test_project_fixtures/test_project_ignore_migration/test_app/migrations/0001_create_table.py new file mode 100644 index 0000000..d847af6 --- /dev/null +++ b/tests/test_project_fixtures/test_project_ignore_migration/test_app/migrations/0001_create_table.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.6 on 2017-10-25 14:15 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='A', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('null_field', models.IntegerField(null=True)), + ], + ), + ] diff --git a/tests/test_project_fixtures/test_project_ignore_migration/test_app/migrations/0002_rename_table.py b/tests/test_project_fixtures/test_project_ignore_migration/test_app/migrations/0002_rename_table.py new file mode 100644 index 0000000..d521e87 --- /dev/null +++ b/tests/test_project_fixtures/test_project_ignore_migration/test_app/migrations/0002_rename_table.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.6 on 2017-10-25 14:15 +from __future__ import unicode_literals + +from django.db import migrations + +import django_migration_linter as linter + +class Migration(migrations.Migration): + + dependencies = [ + ('test_app', '0001_create_table'), + ] + + operations = [ + linter.IgnoreMigration(), + migrations.RenameModel( + old_name='A', + new_name='B', + ), + ] diff --git a/tests/test_project_fixtures/test_project_ignore_migration/test_app/migrations/__init__.py b/tests/test_project_fixtures/test_project_ignore_migration/test_app/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_project_fixtures/test_project_ignore_migration/test_app/models.py b/tests/test_project_fixtures/test_project_ignore_migration/test_app/models.py new file mode 100644 index 0000000..2633c55 --- /dev/null +++ b/tests/test_project_fixtures/test_project_ignore_migration/test_app/models.py @@ -0,0 +1,4 @@ +from django.db import models + +class B(models.Model): + null_field = models.IntegerField(null=True) diff --git a/tests/test_project_fixtures/test_project_ignore_migration/test_app/tests.py b/tests/test_project_fixtures/test_project_ignore_migration/test_app/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/tests/test_project_fixtures/test_project_ignore_migration/test_app/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/tests/test_project_fixtures/test_project_ignore_migration/test_app/views.py b/tests/test_project_fixtures/test_project_ignore_migration/test_app/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/tests/test_project_fixtures/test_project_ignore_migration/test_app/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/tests/test_project_fixtures/test_project_ignore_migration/test_project_ignore_migration/__init__.py b/tests/test_project_fixtures/test_project_ignore_migration/test_project_ignore_migration/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_project_fixtures/test_project_ignore_migration/test_project_ignore_migration/settings.py b/tests/test_project_fixtures/test_project_ignore_migration/test_project_ignore_migration/settings.py new file mode 100644 index 0000000..39bfb6c --- /dev/null +++ b/tests/test_project_fixtures/test_project_ignore_migration/test_project_ignore_migration/settings.py @@ -0,0 +1,121 @@ +""" +Django settings for test_project_ignore_migration project. + +Generated by 'django-admin startproject' using Django 1.11.6. + +For more information on this file, see +https://docs.djangoproject.com/en/1.11/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/1.11/ref/settings/ +""" + +import os + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'gtb+mohs%gf0+#fr89vw7e&#edmv=q8!iv+n&j_soawk$tkj3^' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'test_app' +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'test_project_ignore_migration.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'test_project_ignore_migration.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/1.11/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + } +} + + +# Password validation +# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/1.11/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/1.11/howto/static-files/ + +STATIC_URL = '/static/' diff --git a/tests/test_project_fixtures/test_project_ignore_migration/test_project_ignore_migration/urls.py b/tests/test_project_fixtures/test_project_ignore_migration/test_project_ignore_migration/urls.py new file mode 100644 index 0000000..735de5d --- /dev/null +++ b/tests/test_project_fixtures/test_project_ignore_migration/test_project_ignore_migration/urls.py @@ -0,0 +1,21 @@ +"""linter_test_project URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/1.11/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.conf.urls import url, include + 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) +""" +from django.conf.urls import url +from django.contrib import admin + +urlpatterns = [ + url(r'^admin/', admin.site.urls), +] diff --git a/tests/test_project_fixtures/test_project_ignore_migration/test_project_ignore_migration/wsgi.py b/tests/test_project_fixtures/test_project_ignore_migration/test_project_ignore_migration/wsgi.py new file mode 100644 index 0000000..f3abf75 --- /dev/null +++ b/tests/test_project_fixtures/test_project_ignore_migration/test_project_ignore_migration/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for linter_test_project project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/1.11/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "test_project_ignore_migration.settings") + +application = get_wsgi_application() diff --git a/tests/unit/test_linter.py b/tests/unit/test_linter.py index 0a4e47e..25d1a65 100644 --- a/tests/unit/test_linter.py +++ b/tests/unit/test_linter.py @@ -1,4 +1,4 @@ -# Copyright 2018 3YOURMIND GmbH +# Copyright 2019 3YOURMIND GmbH # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -13,8 +13,10 @@ # limitations under the License. import unittest +import os from django_migration_linter import MigrationLinter +from django_migration_linter.migration import Migration from tests import fixtures @@ -32,13 +34,16 @@ class TestLinterFunctions(unittest.TestCase): linter = MigrationLinter(project_path) self.assertFalse(linter.has_errors) - linter.lint_migration('test_app', '0001') + m = Migration(os.path.join(project_path, 'test_app/migrations/0001_create_table.py')) + linter.lint_migration(m) self.assertFalse(linter.has_errors) - linter.lint_migration('test_app', '0002') + m = Migration(os.path.join(project_path, 'test_app/migrations/0002_add_new_not_null_field.py')) + linter.lint_migration(m) self.assertTrue(linter.has_errors) - linter.lint_migration('test_app', '0001') + m = Migration(os.path.join(project_path, 'test_app/migrations/0001_create_table.py')) + linter.lint_migration(m) self.assertTrue(linter.has_errors) def test_linter_creation(self): @@ -49,24 +54,6 @@ class TestLinterFunctions(unittest.TestCase): with self.assertRaises(ValueError): MigrationLinter(fixtures.NOT_DJANGO_GIT_PROJECT) - def test_split_migration_long_path(self): - input_path = 'apps/the_app/migrations/0001_stuff.py' - app, mig = MigrationLinter._split_migration_path(input_path) - self.assertEqual(app, 'the_app') - self.assertEqual(mig, '0001_stuff') - - def test_split_migration_path(self): - input_path = 'the_app/migrations/0001_stuff.py' - app, mig = MigrationLinter._split_migration_path(input_path) - self.assertEqual(app, 'the_app') - self.assertEqual(mig, '0001_stuff') - - def test_split_migration_full_path(self): - input_path = '/home/user/djangostuff/apps/the_app/migrations/0001_stuff.py' - app, mig = MigrationLinter._split_migration_path(input_path) - self.assertEqual(app, 'the_app') - self.assertEqual(mig, '0001_stuff') - def test_ignore_migration_include_apps(self): linter = MigrationLinter( fixtures.ADD_NOT_NULL_COLUMN_PROJECT, @@ -98,10 +85,13 @@ class TestLinterFunctions(unittest.TestCase): def test_gather_all_migrations(self): linter = MigrationLinter(fixtures.CORRECT_PROJECT) migrations = linter._gather_all_migrations() - self.assertEqual(len(migrations), 3) - self.assertEqual(migrations[0][0], 'test_app1') - self.assertEqual(migrations[0][1], '0001_initial') - self.assertEqual(migrations[1][0], 'test_app1') - self.assertEqual(migrations[1][1], '0002_a_new_null_field') - self.assertEqual(migrations[2][0], 'test_app2') - self.assertEqual(migrations[2][1], '0001_foo') + self.assertEqual(len(migrations), 4) + self.assertEqual( + sorted([(m.app_name, m.name) for m in migrations]), + sorted([ + ("test_app1", "0001_initial"), + ("test_app1", "0002_a_new_null_field"), + ("test_app2", "0001_foo"), + ("test_app3", "0001_initial"), + ]) + ) diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py index 88d20af..6998413 100644 --- a/tests/unit/test_utils.py +++ b/tests/unit/test_utils.py @@ -1,4 +1,4 @@ -# Copyright 2018 3YOURMIND GmbH +# Copyright 2019 3YOURMIND GmbH # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,24 +16,11 @@ import os import unittest from tests import fixtures -from django_migration_linter.utils import is_django_project, is_git_project, is_directory, find_project_settings_module, split_path +from django_migration_linter.utils import is_django_project, is_directory, find_project_settings_module, \ + split_path, split_migration_path class UtilityFunctionTest(unittest.TestCase): - def tearDown(self, *args, **kwargs): - fixtures.clear_all_git_projects() - super( - UtilityFunctionTest, - self).tearDown(*args, **kwargs) - - def test_detect_not_git_project(self): - self.assertFalse(is_git_project(fixtures.NOT_GIT_DJANGO_PROJECT)) - - def test_detect_git_project(self): - project_path = fixtures.MULTI_COMMIT_PROJECT - fixtures.prepare_git_project(project_path) - self.assertTrue(is_git_project(project_path)) - def test_detect_django_project(self): self.assertTrue(is_django_project(fixtures.ADD_NOT_NULL_COLUMN_PROJECT)) @@ -70,3 +57,27 @@ class UtilityFunctionTest(unittest.TestCase): self.assertEqual(splitted[0], 'foo') self.assertEqual(splitted[1], 'bar') self.assertEqual(splitted[2], 'fuz.py') + + def test_split_folder_path(self): + splitted = split_path('/foo/bar') + self.assertEqual(len(splitted), 2) + self.assertEqual(splitted[0], 'foo') + self.assertEqual(splitted[1], 'bar') + + def test_split_migration_long_path(self): + input_path = 'apps/the_app/migrations/0001_stuff.py' + app, mig = split_migration_path(input_path) + self.assertEqual(app, 'the_app') + self.assertEqual(mig, '0001_stuff') + + def test_split_migration_path(self): + input_path = 'the_app/migrations/0001_stuff.py' + app, mig = split_migration_path(input_path) + self.assertEqual(app, 'the_app') + self.assertEqual(mig, '0001_stuff') + + def test_split_migration_full_path(self): + input_path = '/home/user/djangostuff/apps/the_app/migrations/0001_stuff.py' + app, mig = split_migration_path(input_path) + self.assertEqual(app, 'the_app') + self.assertEqual(mig, '0001_stuff') diff --git a/tox.ini b/tox.ini index ac72378..81a15c9 100644 --- a/tox.ini +++ b/tox.ini @@ -1,8 +1,8 @@ [tox] envlist = - py{27,34,35}-django110 - py{27,34,35,36}-django111 - py{34,35,36}-django20 + py{27,34,35,36,37}-django111 + py{34,35,36,37}-django20 + py{35,36,37}-django21 lint [testenv] @@ -10,13 +10,17 @@ commands = py.test {posargs} extras = test pip_pre = true deps = - django110: django>=1.10,<1.11 django111: django>=1.11,<2.0 - django20: django>=2.0 + django20: django>=2.0,<2.1 + django21: django>=2.1 + appdirs==1.4.3 + py27: mock==2.0.0 [testenv:lint] basepython = python3.6 deps = flake8 + black commands = - flake8 django_migration_linter + flake8 --max-line-length=88 django_migration_linter + black --check django_migration_linter