3
3
4
4
5
5
class TestEvaluations (APITestCase ):
6
+ @property
7
+ def url_collection (self ):
8
+ return URL_EVALUATION_COLLECTION .format (contract = self .contract_name )
6
9
7
10
def test_workflow (self ):
8
11
# test creating and getting evaluations
9
12
app = self .app
10
13
11
- url_collection = URL_EVALUATION_COLLECTION .format (contract = self .contract_name )
12
-
13
14
def url_resource (evaluation_id ):
14
15
return URL_EVALUATION_RESOURCE .format (
15
16
contract = self .contract_name ,
@@ -20,39 +21,73 @@ def url_resource(evaluation_id):
20
21
user = self .contract .create_user ()
21
22
contribution = self .contract .create_contribution (user = user )
22
23
23
- # create a evaluation
24
+ # create an evaluation
24
25
response = app .post (
25
- url_collection ,
26
+ self . url_collection ,
26
27
{
27
28
'evaluator_id' : user .id ,
28
29
'contribution_id' : contribution .id ,
29
- 'value' : 10 ,
30
+ 'value' : 1 ,
30
31
}
31
32
)
32
- self .assertEqual (response .json ['value' ], 10 )
33
+ self .assertEqual (response .json ['value' ], 1 )
33
34
evaluation_id = response .json ['id' ]
34
35
35
36
# get the evaluation info
36
37
response = app .get (url_resource (evaluation_id ))
37
38
38
39
# get the evaluation collection
39
- response = app .get (url_collection )
40
+ response = app .get (self . url_collection )
40
41
self .assertEqual (response .json .get ('count' ), 1 )
41
42
42
43
def test_evaluation_data (self ):
43
44
# test that GETting an evaluation returns all expected data
44
45
user = self .contract .create_user ()
45
46
contribution = self .contract .create_contribution (user = user )
46
- value = 3.14
47
47
evaluation = self .contract .create_evaluation (
48
- contribution = contribution , value = value , user = user )
48
+ contribution = contribution , value = 1 , user = user )
49
49
50
50
url = URL_EVALUATION_RESOURCE .format (id = evaluation .id , contract = self .contract_name )
51
51
info = self .app .get (url ).json
52
- self .assertEqual (info ['value' ], value )
52
+ self .assertEqual (info ['value' ], 1 )
53
53
self .assertEqual (info ['contribution' ]['id' ], contribution .id )
54
- self .assertEqual (info ['contribution' ]['score' ], 0 .0 )
54
+ self .assertEqual (info ['contribution' ]['score' ], 1 .0 )
55
55
self .assertEqual (info ['contribution' ]['engaged_reputation' ], user .reputation )
56
56
self .assertEqual (info ['evaluator' ]['id' ], user .id )
57
- self .assertEqual (info ['evaluator' ]['tokens' ], 49 )
57
+ self .assertEqual (info ['evaluator' ]['tokens' ], 99 )
58
58
self .assertEqual (info ['evaluator' ]['reputation' ], 1 )
59
+
60
+ def test_evaluation_collection_get (self ):
61
+ # add some data
62
+ user0 = self .contract .create_user ()
63
+ user1 = self .contract .create_user ()
64
+ contribution0 = self .contract .create_contribution (user = user0 )
65
+ contribution1 = self .contract .create_contribution (user = user1 )
66
+ self .contract .create_evaluation (contribution = contribution0 , value = 1 , user = user0 )
67
+ self .contract .create_evaluation (contribution = contribution0 , value = 1 , user = user1 )
68
+ self .contract .create_evaluation (contribution = contribution1 , value = 1 , user = user0 )
69
+
70
+ response = self .app .get (self .url_collection )
71
+ self .assertEqual (response .json .get ('count' ), 3 )
72
+ response = self .app .get (self .url_collection , {'contribution_id' : contribution0 .id })
73
+ self .assertEqual (response .json .get ('count' ), 2 )
74
+ response = self .app .get (self .url_collection , {'contributor_id' : user0 .id })
75
+ self .assertEqual (response .json .get ('count' ), 2 )
76
+ response = self .app .get (self .url_collection , {'contributor_id' : user1 .id })
77
+ self .assertEqual (response .json .get ('count' ), 1 )
78
+
79
+ def test_evaluation_errors (self ):
80
+ user = self .contract .create_user ()
81
+ contribution = self .contract .create_contribution (user = user )
82
+
83
+ # try to create an evaluation with an illegal value
84
+ response = self .app .post (
85
+ self .url_collection ,
86
+ {
87
+ 'evaluator_id' : user .id ,
88
+ 'contribution_id' : contribution .id ,
89
+ 'value' : 10000 ,
90
+ },
91
+ expect_errors = True ,
92
+ )
93
+ self .assertTrue (response .status , 'xx' )
0 commit comments