forked from rafalp/Misago
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix failing tests and hardcoded fixtures
The reason why tests where failing is that user role forums fixture was hardcoded with forum ids. Since tests run on same database many times creating same objects again and again, new objects get different ids, so role fixture references wrong forums and forum roles. To fix that, added helper function load_fixtures that automaticall converts hardcoded ids to correct values. Also to not reference model instances by value, added factory classes for forums, forum roles and user roles.
- Loading branch information
Showing
7 changed files
with
136 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import factory | ||
import factory.django | ||
|
||
|
||
class FullAccessForumRole(factory.django.DjangoModelFactory): | ||
name = 'Full Access' | ||
|
||
class Meta: | ||
model = 'misago.ForumRole' | ||
django_get_or_create = ('name',) | ||
|
||
|
||
class ReadOnlyForumRole(factory.django.DjangoModelFactory): | ||
name = "Read only" | ||
|
||
class Meta: | ||
model = 'misago.ForumRole' | ||
django_get_or_create = ('name',) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import factory | ||
import factory.django | ||
|
||
|
||
class AdministratorRole(factory.django.DjangoModelFactory): | ||
name = "Administrator" | ||
|
||
class Meta: | ||
model = 'misago.Role' | ||
django_get_or_create = ('name',) | ||
|
||
|
||
class GuestRole(factory.django.DjangoModelFactory): | ||
name = "Guest" | ||
|
||
class Meta: | ||
model = 'misago.Role' | ||
django_get_or_create = ('name',) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,17 @@ | ||
from misago.settings.development import * | ||
|
||
SECRET_KEY = 'SECRET4TESTS' | ||
|
||
CACHES['default'] = { | ||
'BACKEND': 'django.core.cache.backends.dummy.DummyCache' | ||
} | ||
|
||
SKIP_SOUTH_TESTS = True | ||
|
||
MEDIA_URL = "http://media.domain.com/" | ||
|
||
HAYSTACK_CONNECTIONS = { | ||
'default': { | ||
'ENGINE': 'haystack.backends.simple_backend.SimpleEngine', | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
from django.core.management import call_command | ||
|
||
from django_webtest import WebTest | ||
|
||
from misago.utils.testing import load_fixtures | ||
|
||
|
||
class IndexPageTests(WebTest): | ||
|
||
def test_index(self): | ||
call_command('syncfixtures', quiet=1) | ||
load_fixtures() | ||
resp = self.app.get('/') | ||
self.assertEqual(resp.status_int, 200) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from django.core.management import call_command | ||
|
||
from misago.models import Forum, ForumRole, Role | ||
|
||
|
||
def fix_hardcoded_role(forums, forum_roles, role_name): | ||
role = Role.objects.get(name=role_name) | ||
perms = dict(role.permissions) | ||
perms['forums'] = { | ||
forums[forum_id]: forum_roles[forum_role_id] | ||
for forum_id, forum_role_id in perms['forums'].items() | ||
} | ||
role.permissions = perms | ||
role.save() | ||
|
||
|
||
def fix_hardoced_fixtures(): | ||
forums = { | ||
1: Forum.objects.get(slug='private').pk, | ||
2: Forum.objects.get(slug='reports').pk, | ||
3: Forum.objects.get(slug='root').pk, | ||
4: Forum.objects.get(slug='first-category').pk, | ||
5: Forum.objects.get(slug='first-forum').pk, | ||
6: Forum.objects.get(slug='project-homepage').pk, | ||
} | ||
|
||
forum_roles = { | ||
1: ForumRole.objects.get(name='Full Access').pk, | ||
2: ForumRole.objects.get(name='Standard Access and Upload').pk, | ||
3: ForumRole.objects.get(name='Standard Access').pk, | ||
4: ForumRole.objects.get(name='Read and Download').pk, | ||
5: ForumRole.objects.get(name='Threads list only').pk, | ||
6: ForumRole.objects.get(name='Read only').pk, | ||
} | ||
|
||
fix_hardcoded_role(forums, forum_roles, "Administrator") | ||
fix_hardcoded_role(forums, forum_roles, "Moderator") | ||
fix_hardcoded_role(forums, forum_roles, "Registered") | ||
fix_hardcoded_role(forums, forum_roles, "Guest") | ||
|
||
|
||
def load_fixtures(): | ||
call_command('syncfixtures', quiet=1) | ||
fix_hardoced_fixtures() |