-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
63 lines (57 loc) · 3.53 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
import common
import main,redis
# Various tests to make sure any future changes don't break core functionality. Also see tests_network.py
# GRC address checker
assert main.valid_grc_address('SDeLtAzzaNkvom9HzVgdHHGToEjZ7sYipp')==True
assert main.valid_grc_address('SDeLtAzzaNkvom9HzVgdHHGToEjZ7sYip')==False
assert main.valid_grc_address('')==False
# common UID & CPID functions
pool = redis.ConnectionPool(host='localhost', port=6379, db=0)
redis_connection = redis.Redis(connection_pool=pool)
## ban NFS user
standardized_url=common.standardize_project_url('https://escatter11.fullerton.edu/nfs/')
common.ban_uid(redis=redis_connection,uid='testing',standardized_project_url=standardized_url)
assert common.is_uid_banned(redis=redis_connection,uid='testing',standardized_project_url=standardized_url)
common.unban_uid(redis=redis_connection,uid='testing',standardized_project_url=standardized_url)
assert not common.is_uid_banned(redis=redis_connection,uid='testing',standardized_project_url=standardized_url)
## ban WCG user
standardized_url=common.standardize_project_url('https://worldcommunitygrid.org/boinc/show_user.php?userid=1156028')
common.ban_uid(redis=redis_connection,uid='testing',standardized_project_url=standardized_url)
assert common.is_uid_banned(redis=redis_connection,uid='testing',standardized_project_url=standardized_url)
common.unban_uid(redis=redis_connection,uid='testing',standardized_project_url=standardized_url)
assert not common.is_uid_banned(redis=redis_connection,uid='testing',standardized_project_url=standardized_url)
#
common.ban_cpid(redis=redis_connection,cpid='testing')
assert common.is_cpid_banned(redis=redis_connection,cpid='testing')
common.unban_cpid(redis=redis_connection,cpid='testing')
assert not common.is_cpid_banned(redis=redis_connection,cpid='testing')
standardized_url=common.standardize_project_url('https://escatter11.fullerton.edu/nfs/')
assert not common.uid_to_cpid(redis=redis_connection,uid='THISUIDDOESNOTEXIST',standardized_project_url=standardized_url)
#
assert common.uid_from_url('https://worldcommunitygrid.org/boinc/show_user.php?userid=1156028')=='1156028'
assert common.uid_from_url('https://escatter11.fullerton.edu/nfs/show_user.php?userid=21405')=='21405'
# Sanitizing code
assert common.sanitize_url("<a href='https://escatter11.fullerton.edu/nfs/show_user.php?userid=21405'\n\n>")=='ahref=https://escatter11.fullerton.edu/nfs/show_user.php?userid=21405'
assert common.sanitize_address("<a href='https://escatter11.fullerton.edu/nfs/show_user.php?userid=21405'\n\n>")=='ahrefhttpsescatter11fullertonedunfsshowuserphpuserid2145'
# URL address checker
assert main.valid_profile_url('ESCATTER11.FULLERTON.EDU/NFS/SHOW_USER.PHP?USERID=21405')==True
assert main.valid_profile_url('https://escatter11.fullerton.edu/nfs/show_user.php?userid=21405')==True
assert main.valid_profile_url('https://worldcommunitygrid.org/boinc/show_user.php?userid=1156028')==True
assert main.valid_profile_url('')==False
assert main.valid_profile_url('google.com')==False
# URL standardizer
assert 'ESCATTER11.FULLERTON.EDUNFS'==common.standardize_project_url('https://escatter11.fullerton.edu/nfs/')
assert 'ESCATTER11.FULLERTON.EDUNFS'==common.standardize_project_url('https://escatter11.fullerton.edu/nfs/show_user.php?userid=21405')
# JSON encoding/decoding
test_dict={
'A':'A',
'B':1,
'C':['A','B'],
'D':True,
'E':False,
'F':2.144
}
my_json=common.dict_to_json(test_dict)
assert my_json=='{"A": "A", "B": 1, "C": ["A", "B"], "D": true, "E": false, "F": 2.144}'
dict_output=common.json_to_dict(my_json)
assert test_dict==dict_output