Coverage for ivatar/tools/test_views.py: 100%

45 statements  

« prev     ^ index     » next       coverage.py v7.6.9, created at 2024-12-26 00:11 +0000

1# -*- coding: utf-8 -*- 

2""" 

3Test our views in ivatar.ivataraccount.views and ivatar.views 

4""" 

5# pylint: disable=too-many-lines 

6import os 

7import django 

8from django.test import TestCase 

9from django.test import Client 

10from django.urls import reverse 

11from django.contrib.auth.models import User 

12 

13os.environ["DJANGO_SETTINGS_MODULE"] = "ivatar.settings" 

14django.setup() 

15 

16# pylint: disable=wrong-import-position 

17from ivatar.utils import random_string 

18 

19# pylint: enable=wrong-import-position 

20 

21 

22class Tester(TestCase): # pylint: disable=too-many-public-methods 

23 """ 

24 Main test class 

25 """ 

26 

27 client = Client() 

28 user = None 

29 username = random_string() 

30 password = random_string() 

31 email = "%s@%s.%s" % (username, random_string(), random_string(2)) 

32 # Dunno why random tld doesn't work, but I'm too lazy now to investigate 

33 openid = "http://%s.%s.%s/" % (username, random_string(), "org") 

34 

35 def login(self): 

36 """ 

37 Login as user 

38 """ 

39 self.client.login(username=self.username, password=self.password) 

40 

41 def setUp(self): 

42 """ 

43 Prepare for tests. 

44 - Create user 

45 """ 

46 self.user = User.objects.create_user( 

47 username=self.username, 

48 password=self.password, 

49 ) 

50 

51 def test_check_mail(self): 

52 """ 

53 Test check page 

54 """ 

55 self.login() 

56 response = self.client.get(reverse("tools_check")) 

57 self.assertEqual(response.status_code, 200, "no 200 ok?") 

58 response = self.client.post( 

59 reverse("tools_check"), 

60 data={"mail": "test@test.com", "size": "85"}, 

61 follow=True, 

62 ) 

63 

64 self.assertContains( 

65 response, 

66 'value="test@test.com"', 

67 1, 

68 200, 

69 "Value not set again!?", 

70 ) 

71 

72 self.assertContains( 

73 response, 

74 "b642b4217b34b1e8d3bd915fc65c4452", 

75 3, 

76 200, 

77 "Wrong md5 hash!?", 

78 ) 

79 self.assertContains( 

80 response, 

81 "f660ab912ec121d1b1e928a0bb4bc61b15f5ad44d5efdc4e1c92a25e99b8e44a", 

82 3, 

83 200, 

84 "Wrong sha256 hash!?", 

85 ) 

86 self.assertContains( 

87 response, 

88 'value="85"', 

89 1, 

90 200, 

91 "Size should be set based on post params!?", 

92 ) 

93 

94 def test_check_openid(self): 

95 """ 

96 Test check page 

97 """ 

98 self.login() 

99 response = self.client.get(reverse("tools_check")) 

100 self.assertEqual(response.status_code, 200, "no 200 ok?") 

101 response = self.client.post( 

102 reverse("tools_check"), 

103 data={"openid": "https://test.com", "size": "85"}, 

104 follow=True, 

105 ) 

106 

107 self.assertContains( 

108 response, 

109 'value="https://test.com"', 

110 1, 

111 200, 

112 "Value not set again!?", 

113 ) 

114 

115 self.assertContains( 

116 response, 

117 "396936bd0bf0603d6784b65d03e96dae90566c36b62661f28d4116c516524bcc", 

118 3, 

119 200, 

120 "Wrong sha256 hash!?", 

121 ) 

122 self.assertContains( 

123 response, 

124 'value="85"', 

125 1, 

126 200, 

127 "Size should be set based on post params!?", 

128 ) 

129 

130 def test_check_domain(self): 

131 """ 

132 Test check domain page 

133 """ 

134 self.login() 

135 response = self.client.get(reverse("tools_check_domain")) 

136 self.assertEqual(response.status_code, 200, "no 200 ok?") 

137 response = self.client.post( 

138 reverse("tools_check_domain"), 

139 data={"domain": "linux-kernel.at"}, 

140 follow=True, 

141 ) 

142 self.assertEqual(response.status_code, 200, "no 200 ok?") 

143 self.assertContains( 

144 response, 

145 "http://avatars.linux-kernel.at", 

146 2, 

147 200, 

148 "Not responing with right URL!?", 

149 ) 

150 self.assertContains( 

151 response, 

152 "https://avatars.linux-kernel.at", 

153 2, 

154 200, 

155 "Not responing with right URL!?", 

156 )