|
10 | 10 | ] |
11 | 11 |
|
12 | 12 |
|
| 13 | +@pytest.fixture |
| 14 | +def group(mixer, course, another_course): |
| 15 | + group = mixer.blend("products.Group") |
| 16 | + |
| 17 | + course.update(group=group) |
| 18 | + another_course.update(group=group) |
| 19 | + |
| 20 | + return group |
| 21 | + |
| 22 | + |
13 | 23 | def test_ok(api, question, course): |
14 | 24 | got = api.get(f"/api/v2/homework/questions/{question.slug}/") |
15 | 25 |
|
@@ -79,6 +89,22 @@ def test_ok_for_superusers_even_when_they_did_not_purchase_the_course(api, quest |
79 | 89 | api.get(f"/api/v2/homework/questions/{question.slug}/", expected_status_code=200) |
80 | 90 |
|
81 | 91 |
|
| 92 | +@pytest.mark.usefixtures("group", "purchase_of_another_course", "_set_current_user") |
| 93 | +def test_ok_if_user_purchased_same_course_from_the_group(api, purchase, question): |
| 94 | + purchase.refund() |
| 95 | + |
| 96 | + api.get(f"/api/v2/homework/questions/{question.slug}/", expected_status_code=200) |
| 97 | + |
| 98 | + |
| 99 | +@pytest.mark.usefixtures("group", "_set_current_user") |
| 100 | +def test_fail_if_user_has_not_purchased_same_course_from_the_group(api, mixer, purchase, purchase_of_another_course, question): |
| 101 | + """Same as above, just to make sure above test works""" |
| 102 | + purchase.refund() |
| 103 | + purchase_of_another_course.course.update(group=mixer.blend("products.Group")) # another_group |
| 104 | + |
| 105 | + api.get(f"/api/v2/homework/questions/{question.slug}/", expected_status_code=404) |
| 106 | + |
| 107 | + |
82 | 108 | @pytest.mark.usefixtures("_no_purchase") |
83 | 109 | @pytest.mark.parametrize( |
84 | 110 | "permission", |
|
0 commit comments