euscanwww: Started writing tests for favourite stuff but login fails
Signed-off-by: volpino <fox91@anche.no>
This commit is contained in:
parent
bd2af29ff7
commit
c0aefdef29
@ -3,12 +3,16 @@ from urllib import urlencode
|
||||
from django.test import TestCase
|
||||
from django.test.client import Client
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
from djeuscan.tests.euscan_factory import UserFactory
|
||||
|
||||
|
||||
class SystemTestCase(TestCase):
|
||||
"""
|
||||
Base class for system tests
|
||||
"""
|
||||
fixtures = ["test_data.json"]
|
||||
|
||||
def setUp(self):
|
||||
self.client = Client()
|
||||
@ -27,6 +31,27 @@ class SystemTestCase(TestCase):
|
||||
url = reverse(url_name, args=args, kwargs=kwargs)
|
||||
return self.client.post(url, data)
|
||||
|
||||
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()
|
||||
|
||||
from test_models import *
|
||||
from test_views import *
|
||||
|
@ -3,11 +3,19 @@ from string import letters
|
||||
from datetime import datetime
|
||||
from collections import defaultdict
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
import factory
|
||||
|
||||
from djeuscan.models import Herd, Maintainer, Package, Version, EuscanResult
|
||||
|
||||
|
||||
class UserFactory(factory.Factory):
|
||||
FACTORY_FOR = User
|
||||
|
||||
username = factory.Sequence(lambda n: 'user' + n)
|
||||
|
||||
|
||||
def random_string(length=None):
|
||||
if length is None:
|
||||
length = random.randint(1, 30)
|
||||
|
@ -9,6 +9,8 @@ from djeuscan.tests import SystemTestCase
|
||||
from djeuscan.tests.euscan_factory import PackageFactory, setup_maintainers, \
|
||||
setup_herds, setup_categories, setup_overlays
|
||||
|
||||
from djeuscan.models import CategoryAssociation
|
||||
|
||||
|
||||
class PagesTest(SystemTestCase):
|
||||
"""
|
||||
@ -31,6 +33,10 @@ class PagesTest(SystemTestCase):
|
||||
response = self.get("global_feed")
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_api(self):
|
||||
response = self.get("api")
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
|
||||
class PackageTests(SystemTestCase):
|
||||
def setUp(self):
|
||||
@ -81,6 +87,21 @@ class CategoriesTests(SectionTests):
|
||||
response = self.get("category_feed", category=category)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def dont_test_favourite(self):
|
||||
# TODO: understand why login fails
|
||||
category = self.categories[0]
|
||||
self.assertEqual(CategoryAssociation.objects.count(), 0)
|
||||
|
||||
response = self.get("category", category=category)
|
||||
self.assertNotIn("Watch", response.content)
|
||||
|
||||
with self.login():
|
||||
response = self.get("category", category=category)
|
||||
self.assertIn("Watch", response.content)
|
||||
self.post("favourite_category", category=category)
|
||||
|
||||
self.assertEqual(CategoryAssociation.objects.count(), 1)
|
||||
|
||||
|
||||
class HerdsTests(SectionTests):
|
||||
def setUp(self):
|
||||
|
Loading…
Reference in New Issue
Block a user