euscanwww: Tests for watch packages/categories/maintainers/herds

Signed-off-by: volpino <fox91@anche.no>
This commit is contained in:
volpino 2012-07-14 16:22:02 +02:00
parent c0aefdef29
commit 66db910583
3 changed files with 90 additions and 6 deletions

View File

@ -9,7 +9,8 @@ from djeuscan.tests import SystemTestCase
from djeuscan.tests.euscan_factory import PackageFactory, setup_maintainers, \ from djeuscan.tests.euscan_factory import PackageFactory, setup_maintainers, \
setup_herds, setup_categories, setup_overlays setup_herds, setup_categories, setup_overlays
from djeuscan.models import CategoryAssociation from djeuscan.models import PackageAssociation, CategoryAssociation, \
HerdAssociation, MaintainerAssociation
class PagesTest(SystemTestCase): class PagesTest(SystemTestCase):
@ -48,6 +49,30 @@ class PackageTests(SystemTestCase):
package=self.package.name) package=self.package.name)
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
def test_favourite(self):
self.assertEqual(PackageAssociation.objects.count(), 0)
response = self.get("package", category=self.package.category,
package=self.package.name)
self.assertEqual(response.status_code, 200)
self.assertNotIn("Watch", response.content)
with self.login():
response = self.get("package", category=self.package.category,
package=self.package.name)
self.assertEqual(response.status_code, 200)
self.assertIn("Watch", response.content)
self.post("favourite_package", category=self.package.category,
package=self.package.name)
self.assertEqual(PackageAssociation.objects.count(), 1)
response = self.get("accounts_packages")
self.assertEqual(response.status_code, 200)
self.assertIn(self.package.name, response.content)
class SectionTests(SystemTestCase): class SectionTests(SystemTestCase):
def _check_table(self, response, items, attr=None): def _check_table(self, response, items, attr=None):
@ -87,21 +112,28 @@ class CategoriesTests(SectionTests):
response = self.get("category_feed", category=category) response = self.get("category_feed", category=category)
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
def dont_test_favourite(self): def test_favourite(self):
# TODO: understand why login fails
category = self.categories[0] category = self.categories[0]
self.assertEqual(CategoryAssociation.objects.count(), 0) self.assertEqual(CategoryAssociation.objects.count(), 0)
response = self.get("category", category=category) response = self.get("category", category=category)
self.assertEqual(response.status_code, 200)
self.assertNotIn("Watch", response.content) self.assertNotIn("Watch", response.content)
with self.login(): with self.login():
response = self.get("category", category=category) response = self.get("category", category=category)
self.assertEqual(response.status_code, 200)
self.assertIn("Watch", response.content) self.assertIn("Watch", response.content)
self.post("favourite_category", category=category) self.post("favourite_category", category=category)
self.assertEqual(CategoryAssociation.objects.count(), 1) self.assertEqual(CategoryAssociation.objects.count(), 1)
response = self.get("accounts_categories")
self.assertEqual(response.status_code, 200)
self._check_table(response, [category])
class HerdsTests(SectionTests): class HerdsTests(SectionTests):
def setUp(self): def setUp(self):
@ -126,6 +158,28 @@ class HerdsTests(SectionTests):
response = self.get("herd_feed", herd=herd.herd) response = self.get("herd_feed", herd=herd.herd)
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
def test_favourite(self):
herd = self.herds[0]
self.assertEqual(HerdAssociation.objects.count(), 0)
response = self.get("herd", herd=herd.herd)
self.assertEqual(response.status_code, 200)
self.assertNotIn("Watch", response.content)
with self.login():
response = self.get("herd", herd=herd.herd)
self.assertEqual(response.status_code, 200)
self.assertIn("Watch", response.content)
self.post("favourite_herd", herd=herd.herd)
self.assertEqual(HerdAssociation.objects.count(), 1)
response = self.get("accounts_herds")
self.assertEqual(response.status_code, 200)
self._check_table(response, [herd], attr="herd")
class MaintainersTests(SectionTests): class MaintainersTests(SectionTests):
def setUp(self): def setUp(self):
@ -150,6 +204,28 @@ class MaintainersTests(SectionTests):
response = self.get("maintainer_feed", maintainer_id=maintainer.pk) response = self.get("maintainer_feed", maintainer_id=maintainer.pk)
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
def test_favourite(self):
maintainer = self.maintainers[0]
self.assertEqual(MaintainerAssociation.objects.count(), 0)
response = self.get("maintainer", maintainer_id=maintainer.pk)
self.assertEqual(response.status_code, 200)
self.assertNotIn("Watch", response.content)
with self.login():
response = self.get("maintainer", maintainer_id=maintainer.pk)
self.assertEqual(response.status_code, 200)
self.assertIn("Watch", response.content)
self.post("favourite_maintainer", maintainer_id=maintainer.pk)
self.assertEqual(MaintainerAssociation.objects.count(), 1)
response = self.get("accounts_maintainers")
self.assertEqual(response.status_code, 200)
self._check_table(response, [maintainer], attr="name")
class OverlayTests(SectionTests): class OverlayTests(SectionTests):
def setUp(self): def setUp(self):

View File

@ -13,8 +13,16 @@ settings.configure(
DATABASES={ DATABASES={
'default': {'ENGINE': 'django.db.backends.sqlite3', 'NAME': ':memory:'} 'default': {'ENGINE': 'django.db.backends.sqlite3', 'NAME': ':memory:'}
}, },
INSTALLED_APPS=['euscanwww.euscanwww', 'djeuscan', 'django.contrib.auth', INSTALLED_APPS=[
'django.contrib.contenttypes'], 'euscanwww.euscanwww',
'djeuscan',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.admin',
'django.contrib.sessions',
'django.contrib.sites',
],
SITE_ID=1,
ROOT_URLCONF='euscanwww.euscanwww.urls', ROOT_URLCONF='euscanwww.euscanwww.urls',
EUSCAN_ROOT=EUSCAN_ROOT, EUSCAN_ROOT=EUSCAN_ROOT,
RRD_ROOT=os.path.join(EUSCAN_ROOT, 'var', 'rrd'), RRD_ROOT=os.path.join(EUSCAN_ROOT, 'var', 'rrd'),

View File

@ -90,7 +90,7 @@ setup(
install_requires=[ install_requires=[
'Django==1.4', 'django-annoying==0.7.6', 'South==0.7.4', 'Django==1.4', 'django-annoying==0.7.6', 'South==0.7.4',
'django-piston==0.2.3', 'BeautifulSoup==3.2.1', 'matplotlib==1.1.0', 'django-piston==0.2.3', 'BeautifulSoup==3.2.1', 'matplotlib==1.1.0',
'django-celery==3.0.0', 'django-registration==0.8', 'django-celery==3.0.1', 'django-registration==0.8',
'python-ldap==2.4.10', 'django-auth-ldap==1.1', 'python-ldap==2.4.10', 'django-auth-ldap==1.1',
], ],
package_dir={'': 'pym'}, package_dir={'': 'pym'},