From 66db910583fd70acf9e3cce9b6d0aa6c41f01f23 Mon Sep 17 00:00:00 2001 From: volpino Date: Sat, 14 Jul 2012 16:22:02 +0200 Subject: [PATCH] euscanwww: Tests for watch packages/categories/maintainers/herds Signed-off-by: volpino --- euscanwww/djeuscan/tests/test_views.py | 82 +++++++++++++++++++++++++- euscanwww/runtests.py | 12 +++- setup.py | 2 +- 3 files changed, 90 insertions(+), 6 deletions(-) diff --git a/euscanwww/djeuscan/tests/test_views.py b/euscanwww/djeuscan/tests/test_views.py index bb55faa..5b6f30d 100644 --- a/euscanwww/djeuscan/tests/test_views.py +++ b/euscanwww/djeuscan/tests/test_views.py @@ -9,7 +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 +from djeuscan.models import PackageAssociation, CategoryAssociation, \ + HerdAssociation, MaintainerAssociation class PagesTest(SystemTestCase): @@ -48,6 +49,30 @@ class PackageTests(SystemTestCase): package=self.package.name) 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): def _check_table(self, response, items, attr=None): @@ -87,21 +112,28 @@ 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 + def test_favourite(self): category = self.categories[0] self.assertEqual(CategoryAssociation.objects.count(), 0) response = self.get("category", category=category) + self.assertEqual(response.status_code, 200) self.assertNotIn("Watch", response.content) with self.login(): response = self.get("category", category=category) + self.assertEqual(response.status_code, 200) + self.assertIn("Watch", response.content) self.post("favourite_category", category=category) 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): def setUp(self): @@ -126,6 +158,28 @@ class HerdsTests(SectionTests): response = self.get("herd_feed", herd=herd.herd) 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): def setUp(self): @@ -150,6 +204,28 @@ class MaintainersTests(SectionTests): response = self.get("maintainer_feed", maintainer_id=maintainer.pk) 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): def setUp(self): diff --git a/euscanwww/runtests.py b/euscanwww/runtests.py index a8cd2b7..3721076 100644 --- a/euscanwww/runtests.py +++ b/euscanwww/runtests.py @@ -13,8 +13,16 @@ settings.configure( DATABASES={ 'default': {'ENGINE': 'django.db.backends.sqlite3', 'NAME': ':memory:'} }, - INSTALLED_APPS=['euscanwww.euscanwww', 'djeuscan', 'django.contrib.auth', - 'django.contrib.contenttypes'], + INSTALLED_APPS=[ + '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', EUSCAN_ROOT=EUSCAN_ROOT, RRD_ROOT=os.path.join(EUSCAN_ROOT, 'var', 'rrd'), diff --git a/setup.py b/setup.py index dcc2779..85856aa 100755 --- a/setup.py +++ b/setup.py @@ -90,7 +90,7 @@ setup( install_requires=[ '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-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', ], package_dir={'': 'pym'},