Skip to content

Commit

Permalink
Test for forum list
Browse files Browse the repository at this point in the history
Tried to add test for logged in user, but sinche Misago does not use Django
auth, it becomes a bit complicated to test authenticated users.

Probably I will have to extend django webtest and add cutom logic there to make
authenticated users testing work.
  • Loading branch information
sirex committed Aug 5, 2015
1 parent 119bb69 commit 6d0df1f
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ stylecop.*
~$*
*.dbmdl
Generated_Code #added for RIA/Silverlight projects
/tags

# Backup & report files from converting an old project file to a newer
# Visual Studio version. Backup files are not needed, because we have git ;-)
Expand Down
2 changes: 1 addition & 1 deletion misago/apps/threadtype/list/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,4 @@ def __call__(self, request, **kwargs):
'threads': self.threads,
'pagination': self.pagination,
}),
context_instance=RequestContext(request));
context_instance=RequestContext(request));
Empty file added misago/factories/__init__.py
Empty file.
10 changes: 10 additions & 0 deletions misago/factories/forummodel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import factory
import factory.django


class ForumFactory(factory.django.DjangoModelFactory):
slug = 'first-forum'

class Meta:
model = 'misago.Forum'
django_get_or_create = ('slug',)
Empty file.
16 changes: 16 additions & 0 deletions misago/tests/apps/threads/test_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from django.core.management import call_command

from django_webtest import WebTest

from misago.factories.forummodel import ForumFactory


class ForumListTests(WebTest):

def test_forum_list_annonymous(self):
call_command('syncfixtures', quiet=1)

forum = ForumFactory()

resp = self.app.get('/forum/%s-%d/' % (forum.slug, forum.pk))
resp.mustcontain('First Forum')
27 changes: 27 additions & 0 deletions misago/utils/factories.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import faker


class FakerFactoryBoyWrapper(object):
"""Small wrapper around faker for factory boy.
Usage:
>>> from factory import LazyAttribute
>>> from pylab.core.helpers.factories import fake
>>> LazyAttribute(fake.company()) # doctest: +ELLIPSIS
<factory.declarations.LazyAttribute object at 0x...>
"""

def __init__(self):
self.faker = faker.Factory.create()

def __getattr__(self, name):
faker_method = getattr(self.faker, name)

def wrapper(*args, **kwargs):
def func(obj=None): # pylint: disable=unused-argument
return faker_method(*args, **kwargs)
return func

return wrapper


fake = FakerFactoryBoyWrapper() # pylint: disable=invalid-name
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ whoosh<2.6
coverage
django-nose
django-webtest
factory_boy
fake-factory

0 comments on commit 6d0df1f

Please sign in to comment.