Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

migrations_tests.py 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # -*- coding: utf-8 -*-
  2. import os
  3. import re
  4. from django.test import TestCase
  5. import oscar.apps
  6. class TestMigrations(TestCase):
  7. def setUp(self):
  8. self.root_path = os.path.dirname(oscar.apps.__file__)
  9. self.migration_filenames = []
  10. for path, __, migrations in os.walk(self.root_path):
  11. if path.endswith('migrations'):
  12. paths = [
  13. os.path.join(path, migration) for migration in migrations
  14. if migration.endswith('.py') and migration != '__init__.py']
  15. self.migration_filenames += paths
  16. def test_dont_contain_hardcoded_user_model(self):
  17. def check_for_auth_model(filepath):
  18. with open(filepath) as f:
  19. s = f.read()
  20. return 'auth.User' in s or 'auth.user' in s
  21. matches = filter(check_for_auth_model, self.migration_filenames)
  22. if matches:
  23. pretty_matches = '\n'.join(
  24. [match.replace(self.root_path, '') for match in matches])
  25. self.fail('References to hardcoded User model found in the '
  26. 'following migration(s):\n' + pretty_matches)
  27. def test_no_duplicate_migration_numbers(self):
  28. # pull app name and migration number
  29. regexp = re.compile(r'^.+oscar/apps/([\w/]+)/migrations/(\d{4}).+$')
  30. keys = []
  31. for migration in self.migration_filenames:
  32. match = regexp.match(migration)
  33. keys.append(match.group(1) + match.group(2))
  34. self.assertEqual(len(keys), len(set(keys)))