Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

migrations_tests.py 991B

123456789101112131415161718192021222324252627282930
  1. # -*- coding: utf-8 -*-
  2. import os
  3. from django.test import TestCase
  4. import oscar.apps
  5. class TestMigrations(TestCase):
  6. def check_for_auth_model(self, filepath):
  7. with open(filepath) as f:
  8. s = f.read()
  9. return 'auth.User' in s or 'auth.user' in s
  10. def test_dont_contain_hardcoded_user_model(self):
  11. root_path = os.path.dirname(oscar.apps.__file__)
  12. matches = []
  13. for dir, __, migrations in os.walk(root_path):
  14. if dir.endswith('migrations'):
  15. paths = [os.path.join(dir, migration) for migration in migrations
  16. if migration.endswith('.py')]
  17. matches += filter(self.check_for_auth_model, paths)
  18. if matches:
  19. pretty_matches = '\n'.join(
  20. [match.replace(root_path, '') for match in matches])
  21. self.fail('References to hardcoded User model found in the '
  22. 'following migration(s):\n' + pretty_matches)