Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Update tests to not need internal eldarion package

  • Loading branch information...
commit 6c5e4f699cf2d1916da29936b9627377a9c8f5ac 1 parent 1901aef
@paltman paltman authored
Showing with 57 additions and 11 deletions.
  1. +53 −8 dialogos/tests.py
  2. +4 −3 runtests.py
View
61 dialogos/tests.py
@@ -1,16 +1,61 @@
-from django.conf import settings
+from django.core.urlresolvers import reverse
from django.template import Template, Context
+from django.test import TestCase
from django.contrib.auth.models import User
from django.contrib.contenttypes.models import ContentType
-from eldarion.test import TestCase
-
-from dialogos.forms import UnauthenticatedCommentForm, AuthenticatedCommentForm
+from dialogos.forms import CommentForm
from dialogos.models import Comment
-class CommentTests(TestCase):
+class login(object):
+ def __init__(self, testcase, user, password):
+ self.testcase = testcase
+ success = testcase.client.login(username=user, password=password)
+ self.testcase.assertTrue(
+ success,
+ "login with username=%r, password=%r failed" % (user, password)
+ )
+
+ def __enter__(self):
+ pass
+
+ def __exit__(self, *args):
+ self.testcase.client.logout()
+
+
+class TestCaseMixin(object):
+ def get(self, url_name, *args, **kwargs):
+ data = kwargs.pop("data", {})
+ return self.client.get(reverse(url_name, args=args, kwargs=kwargs), data)
+
+ def getajax(self, url_name, *args, **kwargs):
+ data = kwargs.pop("data", {})
+ return self.client.get(reverse(url_name, args=args, kwargs=kwargs), data,
+ HTTP_X_REQUESTED_WITH="XMLHttpRequest")
+
+ def post(self, url_name, *args, **kwargs):
+ data = kwargs.pop("data", {})
+ return self.client.post(reverse(url_name, args=args, kwargs=kwargs), data)
+
+ def postajax(self, url_name, *args, **kwargs):
+ data = kwargs.pop("data", {})
+ return self.client.post(reverse(url_name, args=args, kwargs=kwargs), data,
+ HTTP_X_REQUESTED_WITH="XMLHttpRequest")
+
+ def login(self, user, password):
+ return login(self, user, password)
+
+ def reload(self, obj):
+ return obj.__class__._default_manager.get(pk=obj.pk)
+
+ def assert_renders(self, tmpl, context, value):
+ tmpl = Template(tmpl)
+ self.assertEqual(tmpl.render(context), value)
+
+
+class CommentTests(TestCaseMixin, TestCase):
def setUp(self):
self.user = User.objects.create_user("gimli", "myaxe@dwarf.org", "gloin")
@@ -91,7 +136,7 @@ def test_ttag_comment_count(self):
})
self.assert_renders(
- "{% load dialogos_tags %}{% comment_count o %}",
+ "{% load dialogos_tags %}{% comment_count o %}",
Context({"o": g}),
"2"
)
@@ -123,7 +168,7 @@ def test_ttag_comment_form(self):
c,
""
)
- self.assertTrue(isinstance(c["comment_form"], UnauthenticatedCommentForm))
+ self.assertTrue(isinstance(c["comment_form"], CommentForm))
with self.login("gimli", "gloin"):
c = Context({"o": g, "user": self.user})
@@ -132,7 +177,7 @@ def test_ttag_comment_form(self):
c,
""
)
- self.assertTrue(isinstance(c["comment_form"], AuthenticatedCommentForm))
+ self.assertTrue(isinstance(c["comment_form"], CommentForm))
def test_ttag_comment_target(self):
g = User.objects.create(username="legolas")
View
7 runtests.py
@@ -7,7 +7,7 @@
if not settings.configured:
settings.configure(
- DATABASE_ENGINE="sqlite3",
+ DATABASES={"default": {"ENGINE": "django.db.backends.sqlite3"}},
ROOT_URLCONF="dialogos.urls",
INSTALLED_APPS=[
"django.contrib.auth",
@@ -18,7 +18,7 @@
)
-from django.test.simple import run_tests
+from django.test.simple import DjangoTestSuiteRunner
def runtests(*test_args):
@@ -26,7 +26,8 @@ def runtests(*test_args):
test_args = ["dialogos"]
parent = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, parent)
- failures = run_tests(test_args, verbosity=1, interactive=True)
+ suite = DjangoTestSuiteRunner(verbosity=1, interactive=True)
+ failures = suite.run_tests(test_args)
sys.exit(failures)
Please sign in to comment.
Something went wrong with that request. Please try again.