Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

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

56

57

58

59

60

61

62

63

64

65

66

from django.shortcuts import get_object_or_404 

from django.test import TestCase, Client 

from django.contrib.auth.models import User 

from .models import Issues 

 

 

class TestViews(TestCase): 

 

def setUp(self): 

self.user = User.objects.create( 

username='admin', 

password='asdfg', 

is_active=True, 

is_staff=True, 

is_superuser=True 

) 

self.user.set_password("asdfg") 

self.user.save() 

 

self.user = User.objects.create( 

username='John', 

password='asdfg', 

is_active=True, 

is_staff=True, 

is_superuser=False 

) 

self.user.set_password("asdfg") 

self.user.save() 

 

self.client = Client() 

self.issue = Issues.objects.create( 

title='test', 

content='this is a test', 

username=self.user 

) 

self.issue.save() 

 

def test_upvote_issue(self): 

self.client.login(username='admin', password='asdfg') 

response = self.client.get('/issues/{0}/upvote/'.format(self.issue.id)) 

item = get_object_or_404(Issues, pk=1) 

 

self.assertEqual(response.status_code, 302) 

self.assertEqual(item.content, "this is a test") 

self.assertEqual(item.upvotes, 1) 

 

def test_upvoting_same_issue_using_2_different_users(self): 

 

# So john logged to the site 

self.client.login(username='John', password='asdfg') 

# And he decided to upvote issue number 1 

response = self.client.get('/issues/{0}/upvote/'.format(self.issue.id)) 

# And after that he logout and go out for smoke 

self.client.get('/accounts/logout/') 

# Then admin came in and logged as normal user 

response2 = self.client.post('/accounts/login/', { 

'username': "admin", 

'password': 'asdfg'} 

) 

# He navigate to the same issue as John and upvoted same issue 

response = self.client.get('/issues/{0}/upvote/'.format(self.issue.id)) 

item = get_object_or_404(Issues, pk=1) 

 

self.assertEqual(response.status_code, 302) 

self.assertEqual("admin", str(response2.wsgi_request.user)) 

self.assertEqual(item.upvotes, 2)