You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

migrations_tests.py 1.7KB

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