Skip to content

Commit 8b50d06

Browse files
committed
tdd initial tests
1 parent da36c84 commit 8b50d06

File tree

1 file changed

+199
-0
lines changed

1 file changed

+199
-0
lines changed
Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
def test_create_submission_async():
2+
# WHEN an evaluation is retrieved
3+
evaluation = Evaluation(id=evaluation_id).get()
4+
5+
# AND an entity is retrieved
6+
file = File(name="test.txt", parentId=project.id).get()
7+
8+
# THEN the entity can be submitted to the evaluation
9+
submission = Submission(
10+
name="Test Submission",
11+
entity_id=file.id,
12+
evaluation_id=evaluation.id,
13+
version_number=1
14+
).store()
15+
16+
def test_get_submission_async():
17+
# GIVEN a submission has been created
18+
submission = Submission(
19+
name="Test Submission",
20+
entity_id=file.id,
21+
evaluation_id=evaluation.id,
22+
version_number=1
23+
).store()
24+
25+
# WHEN the submission is retrieved by ID
26+
retrieved_submission = Submission(id=submission.id).get()
27+
28+
# THEN the retrieved submission matches the created one
29+
assert retrieved_submission.id == submission.id
30+
assert retrieved_submission.name == submission.name
31+
32+
# AND the user_id matches the current user
33+
current_user = syn.getUserProfile()().id
34+
assert retrieved_submission.user_id == current_user
35+
36+
def test_get_evaluation_submissions_async():
37+
# GIVEN an evaluation has submissions
38+
evaluation = Evaluation(id=evaluation_id).get()
39+
40+
# WHEN submissions are retrieved for the evaluation
41+
submissions = Submission.get_evaluation_submissions(evaluation.id)
42+
43+
# THEN the submissions list is not empty
44+
assert len(submissions) > 0
45+
46+
# AND each submission belongs to the evaluation
47+
for submission in submissions:
48+
assert submission.evaluation_id == evaluation.id
49+
50+
def test_get_user_submissions_async():
51+
# GIVEN a user has made submissions
52+
current_user = syn.getUserProfile()().id
53+
54+
# WHEN submissions are retrieved for the user
55+
submissions = Submission.get_user_submissions(current_user)
56+
57+
# THEN the submissions list is not empty
58+
assert len(submissions) > 0
59+
60+
# AND each submission belongs to the user
61+
for submission in submissions:
62+
assert submission.user_id == current_user
63+
64+
def test_get_submission_count_async():
65+
# GIVEN an evaluation has submissions
66+
evaluation = Evaluation(id=evaluation_id).get()
67+
68+
# WHEN the submission count is retrieved for the evaluation
69+
count = Submission.get_submission_count(evaluation.id)
70+
71+
# THEN the count is greater than zero
72+
assert count > 0
73+
74+
def test_delete_submission_async():
75+
# GIVEN a submission has been created
76+
submission = Submission(
77+
name="Test Submission",
78+
entity_id=file.id,
79+
evaluation_id=evaluation.id,
80+
version_number=1
81+
).store()
82+
83+
# WHEN the submission is deleted
84+
submission.delete()
85+
86+
# THEN retrieving the submission should raise an error
87+
try:
88+
Submission(id=submission.id).get()
89+
assert False, "Expected an error when retrieving a deleted submission"
90+
except SynapseError as e:
91+
assert e.response.status_code == 404
92+
93+
def test_cancel_submission_async():
94+
# GIVEN a submission has been created
95+
submission = Submission(
96+
name="Test Submission",
97+
entity_id=file.id,
98+
evaluation_id=evaluation.id,
99+
version_number=1
100+
).store()
101+
102+
# WHEN the submission is canceled
103+
submission.cancel()
104+
105+
# THEN the submission status should be 'CANCELED'
106+
updated_submission = Submission(id=submission.id).get()
107+
assert updated_submission.status == 'CANCELED'
108+
109+
def test_get_submission_status_async():
110+
# GIVEN a submission has been created
111+
submission = Submission(
112+
name="Test Submission",
113+
entity_id=file.id,
114+
evaluation_id=evaluation.id,
115+
version_number=1
116+
).store()
117+
118+
# WHEN the submission status is retrieved
119+
status = submission.get_status()
120+
121+
# THEN the status should be 'RECEIVED'
122+
assert status == 'RECEIVED'
123+
124+
def test_update_submission_status_async():
125+
# GIVEN a submission has been created
126+
submission = Submission(
127+
name="Test Submission",
128+
entity_id=file.id,
129+
evaluation_id=evaluation.id,
130+
version_number=1
131+
).store()
132+
133+
# WHEN the submission status is retrieved
134+
status = submission.get_status()
135+
assert status != 'SCORED'
136+
137+
# AND the submission status is updated to 'SCORED'
138+
submission.update_status('SCORED')
139+
140+
# THEN the submission status should be 'SCORED'
141+
updated_submission = Submission(id=submission.id).get()
142+
assert updated_submission.status == 'SCORED'
143+
144+
def test_get_evaluation_submission_statuses_async():
145+
# GIVEN an evaluation has submissions
146+
evaluation = Evaluation(id=evaluation_id).get()
147+
148+
# WHEN the submission statuses are retrieved for the evaluation
149+
statuses = Submission.get_evaluation_submission_statuses(evaluation.id)
150+
151+
# THEN the statuses list is not empty
152+
assert len(statuses) > 0
153+
154+
def test_batch_update_statuses_async():
155+
# GIVEN multiple submissions have been created
156+
submission1 = Submission(
157+
name="Test Submission 1",
158+
entity_id=file.id,
159+
evaluation_id=evaluation.id,
160+
version_number=1
161+
).store()
162+
submission2 = Submission(
163+
name="Test Submission 2",
164+
entity_id=file.id,
165+
evaluation_id=evaluation.id,
166+
version_number=1
167+
).store()
168+
169+
# WHEN the statuses of the submissions are batch updated to 'SCORED'
170+
Submission.batch_update_statuses(
171+
[submission1.id, submission2.id],
172+
'SCORED'
173+
)
174+
175+
# THEN each submission status should be 'SCORED'
176+
updated_submission1 = Submission(id=submission1.id).get()
177+
updated_submission2 = Submission(id=submission2.id).get()
178+
assert updated_submission1.status == 'SCORED'
179+
assert updated_submission2.status == 'SCORED'
180+
181+
def test_get_evaluation_submission_bundles_async():
182+
# GIVEN an evaluation has submissions
183+
evaluation = Evaluation(id=evaluation_id).get()
184+
185+
# WHEN the submission bundles are retrieved for the evaluation
186+
bundles = Submission.get_evaluation_submission_bundles(evaluation.id)
187+
188+
# THEN the bundles list is not empty
189+
assert len(bundles) > 0
190+
191+
def test_get_user_submission_bundles_async():
192+
# GIVEN a user has made submissions
193+
current_user = syn.getUserProfile()().id
194+
195+
# WHEN the submission bundles are retrieved for the user
196+
bundles = Submission.get_user_submission_bundles(current_user)
197+
198+
# THEN the bundles list is not empty
199+
assert len(bundles) > 0

0 commit comments

Comments
 (0)