This repository has been archived by the owner on Sep 4, 2022. It is now read-only.
forked from popen2/djangopypi2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
55 lines (46 loc) · 2.31 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from django.contrib.auth import login
from django.contrib.auth.models import User
from django.core.urlresolvers import resolve, reverse
from django.test import Client, TestCase
from . import views
class ListViewTest(TestCase):
fixtures = ["test_pypi_users"]
list_user_url = reverse("djangopypi2-users")
def test_handler(self):
self.assertEqual(resolve(self.list_user_url).func.func_name, views.Index.as_view().func_name)
def test_list(self):
client = Client()
client.login(username="user1", password="password")
response = client.get(self.list_user_url)
self.assertEqual(response.status_code, 200)
self.assertIn("user1", response.content)
self.assertIn("user2", response.content)
def test_list_not_logged_in(self):
client = Client()
response = client.get(self.list_user_url)
self.assertEqual(response.status_code, 302)
class UserDetailTest(TestCase):
fixtures = ["test_pypi_users"]
def test_handler(self):
user_profile_url = reverse("djangopypi2-user-profile", kwargs = {"username": "anyUser"})
self.assertEqual(resolve(user_profile_url).func.func_name, views.UserDetails.as_view().func_name)
def test_user_detail(self):
user_profile_url = reverse("djangopypi2-user-profile", kwargs = {"username": "user2"})
client = Client()
result = client.login(username="user1", password="password")
response = client.get(user_profile_url, follow = True)
self.assertEqual(response.status_code, 200)
# Make sure user2's details are shown, not user1's
self.assertIn("user2@user.com", response.content)
self.assertNotIn("user1@user.com", response.content)
def test_user_detail_user_not_exist(self):
user_profile_url = reverse("djangopypi2-user-profile", kwargs = {"username": "notExistUser"})
client = Client()
result = client.login(username="user1", password="password")
response = client.get(user_profile_url, follow = True)
self.assertEqual(response.status_code, 404)
def test_user_detail_not_logged_in(self):
user_profile_url = reverse("djangopypi2-user-profile", kwargs = {"username": "user2"})
client = Client()
response = client.get(user_profile_url)
self.assertEqual(response.status_code, 302)