/
tests.py
120 lines (94 loc) · 2.89 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import unittest
import sqlite3
from indiegogo import (
get_individual,
get_username,
get_activities,
get_category,
get_activity_links,
verify,
verify_contribution,
store_valid_user
)
# globals
BASE_URL = "http://www.indiegogo.com/"
INDIVIDUAL = BASE_URL + "individuals/{0}"
ACTIVITIES = INDIVIDUAL + "/activities"
def db_init():
db = sqlite3.connect("test_db.db")
cursor = db.cursor()
cursor.execute("""
DROP TABLE IF EXISTS test_user""")
cursor.execute("""
CREATE TABLE test_user
(id real, username text)
""")
cursor.close()
# globals
support_user = get_individual(100)
support_activities = get_activities(support_user)
actual_user = get_individual(101)
actual_activities = get_activities(actual_user)
contributions = verify_contribution(actual_activities)
links = get_activity_links(actual_activities)
class TestIndieGoGo(unittest.TestCase):
def setUp(self):
# test_db implementation
# valid user logic
#self.support_user = get_individual(100)
# set this up later
#db_init()
pass
def test_individuals(self):
observed = support_user.status_code
expected = 200
self.assertEqual(observed, expected, "Status code other than 200")
def test_get_username(self):
observed = get_username(support_user)
expected = "GoGo Support"
self.assertEqual(observed, expected)
def test_verify(self):
failure = verify(get_individual(1))
success = verify(support_user)
self.assertFalse(failure)
self.assertTrue(success)
def test_activities(self):
observed = get_activities(support_user)
expected = 46
self.assertEqual(len(observed), expected)
def test_financial_activities(self):
# user 100 is a support user and does not
# financially contribute. Thus all should be false
support_contributions = verify_contribution(support_activities)
support_observed = True in support_contributions
support_expected = False # DIFF: support is not expected to contribute
# whereas user 101 is an actual contributor
# and is very likely to to have contributions
actual_contributions = verify_contribution(actual_activities)
actual_observed = True in actual_contributions
actual_expected = True
# verify the difference
self.assertEqual(support_observed, support_expected)
self.assertEqual(actual_observed, actual_expected)
def test_get_activity_links(self):
links = get_activity_links(actual_activities)
expected = 'projects/1317959'
self.assertEqual(links[0], expected, "This test may fail from time to time")
def test_get_category(self):
"""
looks for 'i-glyph-icon-30-film' in class tree
of each project
"""
# see globals
link = "projects/star-trek-axanar"
observed = get_category(link)
expected = True
self.assertEqual(observed, expected)
def test_store_user(self):
id = 101
username = "GoGo Support"
url = INDIVIDUAL.format(id)
contribs = 5
store_valid_user(id, username, url, contribs)
if __name__ == '__main__':
unittest.main()