2012-05-05 16:09:04 +02:00
|
|
|
from urllib import urlencode
|
|
|
|
|
2012-05-07 14:27:54 +02:00
|
|
|
from django.test import TestCase
|
2012-05-05 16:09:04 +02:00
|
|
|
from django.test.client import Client
|
|
|
|
from django.core.urlresolvers import reverse
|
2012-07-14 15:29:42 +02:00
|
|
|
from django.contrib.auth.models import User
|
|
|
|
|
|
|
|
from djeuscan.tests.euscan_factory import UserFactory
|
2012-05-05 16:09:04 +02:00
|
|
|
|
|
|
|
|
2012-05-07 14:27:54 +02:00
|
|
|
class SystemTestCase(TestCase):
|
2012-05-05 16:09:04 +02:00
|
|
|
"""
|
|
|
|
Base class for system tests
|
|
|
|
"""
|
2012-07-14 15:29:42 +02:00
|
|
|
fixtures = ["test_data.json"]
|
2012-05-05 16:09:04 +02:00
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
self.client = Client()
|
|
|
|
|
|
|
|
def get(self, url_name, *args, **kwargs):
|
|
|
|
param = kwargs.pop("param", None)
|
|
|
|
if param:
|
|
|
|
url = "%s?%s" % (reverse(url_name, args=args, kwargs=kwargs),
|
|
|
|
urlencode(param))
|
|
|
|
else:
|
|
|
|
url = reverse(url_name, args=args, kwargs=kwargs)
|
|
|
|
return self.client.get(url)
|
|
|
|
|
|
|
|
def post(self, url_name, *args, **kwargs):
|
|
|
|
data = kwargs.pop("data", {})
|
|
|
|
url = reverse(url_name, args=args, kwargs=kwargs)
|
|
|
|
return self.client.post(url, data)
|
|
|
|
|
2012-07-14 15:29:42 +02:00
|
|
|
def login(self):
|
|
|
|
user = UserFactory.build()
|
|
|
|
user.set_password("pass")
|
|
|
|
user.save()
|
|
|
|
return Login(self, user.username, "pass")
|
|
|
|
|
|
|
|
|
|
|
|
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()
|
2012-05-05 16:09:04 +02:00
|
|
|
|
|
|
|
from test_models import *
|
|
|
|
from test_views import *
|
2012-05-06 20:03:49 +02:00
|
|
|
from test_charts import *
|