-
Notifications
You must be signed in to change notification settings - Fork 11
/
tests.py
90 lines (79 loc) · 3.71 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/python
# coding=utf-8
from __future__ import print_function
from cleantalk import CleanTalk
import os
import unittest
import json
class TestCleanTalk(unittest.TestCase):
def setUp(self):
# Make sure you have defined system environment variable 'CLEANTALK_TEST_API_KEY'.
# Use your operating system tools or IDE tools to set this.
self.ct = CleanTalk(auth_key=os.getenv('CLEANTALK_TEST_API_KEY'))
def test_blacklisted(self):
response = self.ct.request(
message='abc', # Comment visitor to the site
sender_ip='196.19.250.114', # IP address of the visitor
sender_email='[email protected]', # Email IP of the visitor
sender_nickname='spam_bot', # Nickname of the visitor
post_info=json.dumps({'post_url': 'https://text.com/1/2/3/4.html'})
)
print(response)
# make sure that 'allow' is 0
self.assertFalse(response['allow'])
def test_correct_ip(self):
response = self.ct.request(
message='Good text.', # Comment visitor to the site
sender_ip='127.0.0.1', # IP address of the visitor
sender_email='[email protected]', # Email IP of the visitor
sender_nickname='real human', # Nickname of the visitor
post_info = json.dumps({'post_url': 'https://text.com/1/2/3/4.html'})
)
print(response)
self.assertTrue(response['allow'])
def test_incorrect_email(self):
response = self.ct.request(
message='Good text.', # Comment visitor to the site
sender_ip='127.0.0.1', # IP address of the visitor
sender_email='[email protected]', # Email IP of the visitor
sender_nickname='real human', # Nickname of the visitor
post_info=json.dumps({'post_url': 'https://text.com/1/2/3/4.html'})
)
print(response)
self.assertTrue(bool(response['codes'].find('EMAIL_DOMAIN_NOT_EXISTS')))
self.assertFalse(response['allow'])
def test_incorrect_js_and_submit_time(self):
response = self.ct.request(
message='Good text.', # Comment visitor to the site
sender_ip='127.0.0.1', # IP address of the visitor
sender_email='[email protected]', # Email IP of the visitor
sender_nickname='aa-shi', # Nickname of the visitor
post_info=json.dumps({'post_url': 'https://text.com/1/2/3/4.html'})
)
print(response)
self.assertTrue(bool(response['codes'].find('JS DISABLED')))
self.assertTrue(bool(response['codes'].find('FAST_SUBMIT')))
def test_js_null(self):
# bad user
response = self.ct.request(
message='abc', # Comment visitor to the site
sender_ip='196.19.250.114', # IP address of the visitor
sender_email='[email protected]', # Email IP of the visitor
sender_nickname='spam_bot', # Nickname of the visitor
post_info=json.dumps({'post_url': 'https://text.com/1/2/3/4.html'})
)
print(response)
self.assertTrue(bool(response['codes'].find('JS DISABLED')))
# good user
response = self.ct.request(
message='abc', # Comment visitor to the site
sender_ip='127.0.0.1', # IP address of the visitor
sender_email='[email protected]', # Email IP of the visitor
sender_nickname='aa-shi', # Nickname of the visitor
post_info=json.dumps({'post_url': 'https://text.com/1/2/3/4.html'})
)
print(response)
self.assertTrue(bool(response['codes'].find('JS DISABLED')))
self.assertFalse(response['allow'])
if __name__ == '__main__':
unittest.main()