rewrite Test case
@@ -10,6 +10,7 @@ from django_dynamic_fixture import get, new
from readthedocs.builds.constants import LATEST, EXTERNAL
from readthedocs.builds.models import Build, Version
from readthedocs.core.permissions import AdminPermission
+from readthedocs.core.models import UserProfile
from readthedocs.projects.forms import UpdateProjectForm
from readthedocs.projects.models import HTMLFile, Project
@@ -299,9 +300,31 @@ class BuildViewTests(TestCase):
class HomepageViewTests(TestCase):
+ def setUp(self):
+ self.homepage_url = reverse('homepage')
+
def test_projects_count(self):
- url = reverse('homepage')
- response = self.client.get(url)
+ user_1 = get(User)
+ profile_1 = get(UserProfile, user=user_1, banned=True)
+
+ user_2 = get(User)
+ profile_2 = get(UserProfile, user=user_2, banned=True)
+
+ user_3 = get(User)
+ profile_3 = get(UserProfile, user=user_3, banned=False)
+
+ project_a = get(Project, users=[user_1])
+ project_b = get(Project, users=[user_2])
+ project_c = get(Project, users=[user_3])
+
+ spam_proj_count = Project.objects.filter(users__profile__banned=True).count()
+
+ self.assertEqual(spam_proj_count, 2)
+ self.assertEqual(User.objects.all().count(), 3)
+ self.assertEqual(User.objects.filter(profile__banned=True).count(), 2)
+
+ expected_count = Project.objects.all().count() - spam_proj_count
+ response = self.client.get(self.homepage_url)
+
self.assertEqual(response.status_code, 200)
- expected_count = Project.objects.exclude(users__profile__banned=True).count()
self.assertEqual(expected_count, response.context['projects_count'])
