Instantly share code, notes, and snippets.

What would you like to do?
Unit test to validate fixtures
class FixturesTest(TestCase):
def test_num_fixtures(self):
"""All fixtures on the project are tested"""
apps = [app.replace('.', '/')
for app in settings.INSTALLED_APPS if app.startswith('rh2')]
fixtures = []
for app in apps:
fixture_dir = path.join(path.dirname(settings.PROJECT_ROOT),
fixtures += glob.glob(fixture_dir + '/*.json')
# If this test fails, it's because a fixture was added but the number
# of tests here wasn't changed.
# While you're at it, please add a test for the new fixture.
self.assertEqual(len(fixtures), 7, "Did you add or remove a fixture "
"without testing it and modifying "
"this test?")
def _load_fixture(self, app_name, fixture_name):
"""Load a fixture and return the error message if any"""
stderr = StringIO()
fixture = path.join('apps', app_name, 'fixtures', fixture_name)
return stderr.getvalue()
def test_load_fixtures(self):
self.assertEqual(self._load_fixture('some_app', 'somefixture.json'), '')
self.assertEqual(self._load_fixture('other_app', 'otherfixture.json'), '')
# add a test for each fixture
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment