mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-22 14:13:21 +00:00
Merge branch 'bugfix' into 'master'
pedagogy: fix a bug when updating an UV from a different author See merge request ae/Sith!228
This commit is contained in:
commit
2232c495be
@ -252,61 +252,64 @@ class UVUpdateTest(TestCase):
|
|||||||
call_command("populate")
|
call_command("populate")
|
||||||
self.bibou = User.objects.filter(username="root").first()
|
self.bibou = User.objects.filter(username="root").first()
|
||||||
self.tutu = User.objects.filter(username="tutu").first()
|
self.tutu = User.objects.filter(username="tutu").first()
|
||||||
self.sli = User.objects.filter(username="sli").first()
|
self.uv = UV.objects.get(code="PA00")
|
||||||
self.guy = User.objects.filter(username="guy").first()
|
|
||||||
|
|
||||||
def test_uv_update_root_success(self):
|
def test_uv_update_root_success(self):
|
||||||
self.client.login(username="root", password="plop")
|
self.client.login(username="root", password="plop")
|
||||||
self.client.post(
|
self.client.post(
|
||||||
reverse(
|
reverse("pedagogy:uv_update", kwargs={"uv_id": self.uv.id}),
|
||||||
"pedagogy:uv_update", kwargs={"uv_id": UV.objects.get(code="PA00").id}
|
|
||||||
),
|
|
||||||
create_uv_template(self.bibou.id, code="PA00"),
|
create_uv_template(self.bibou.id, code="PA00"),
|
||||||
)
|
)
|
||||||
self.assertEquals(UV.objects.get(code="PA00").credit_type, "TM")
|
self.uv.refresh_from_db()
|
||||||
|
self.assertEquals(self.uv.credit_type, "TM")
|
||||||
|
|
||||||
def test_uv_update_pedagogy_admin_success(self):
|
def test_uv_update_pedagogy_admin_success(self):
|
||||||
self.client.login(username="tutu", password="plop")
|
self.client.login(username="tutu", password="plop")
|
||||||
self.client.post(
|
self.client.post(
|
||||||
reverse(
|
reverse("pedagogy:uv_update", kwargs={"uv_id": self.uv.id}),
|
||||||
"pedagogy:uv_update", kwargs={"uv_id": UV.objects.get(code="PA00").id}
|
create_uv_template(self.bibou.id, code="PA00"),
|
||||||
),
|
)
|
||||||
|
self.uv.refresh_from_db()
|
||||||
|
self.assertEquals(self.uv.credit_type, "TM")
|
||||||
|
|
||||||
|
def test_uv_update_original_author_does_not_change(self):
|
||||||
|
self.client.login(username="tutu", password="plop")
|
||||||
|
response = self.client.post(
|
||||||
|
reverse("pedagogy:uv_update", kwargs={"uv_id": self.uv.id}),
|
||||||
create_uv_template(self.tutu.id, code="PA00"),
|
create_uv_template(self.tutu.id, code="PA00"),
|
||||||
)
|
)
|
||||||
self.assertEquals(UV.objects.get(code="PA00").credit_type, "TM")
|
|
||||||
|
self.uv.refresh_from_db()
|
||||||
|
self.assertEquals(response.status_code, 200)
|
||||||
|
self.assertEquals(self.uv.author, self.bibou)
|
||||||
|
|
||||||
def test_uv_update_pedagogy_unauthorized_fail(self):
|
def test_uv_update_pedagogy_unauthorized_fail(self):
|
||||||
# Anonymous user
|
# Anonymous user
|
||||||
response = self.client.post(
|
response = self.client.post(
|
||||||
reverse(
|
reverse("pedagogy:uv_update", kwargs={"uv_id": self.uv.id}),
|
||||||
"pedagogy:uv_update", kwargs={"uv_id": UV.objects.get(code="PA00").id}
|
create_uv_template(self.bibou.id, code="PA00"),
|
||||||
),
|
|
||||||
create_uv_template(0, code="PA00"),
|
|
||||||
)
|
)
|
||||||
self.assertEquals(response.status_code, 403)
|
self.assertEquals(response.status_code, 403)
|
||||||
|
|
||||||
# Not subscribed user
|
# Not subscribed user
|
||||||
self.client.login(username="guy", password="plop")
|
self.client.login(username="guy", password="plop")
|
||||||
response = self.client.post(
|
response = self.client.post(
|
||||||
reverse(
|
reverse("pedagogy:uv_update", kwargs={"uv_id": self.uv.id}),
|
||||||
"pedagogy:uv_update", kwargs={"uv_id": UV.objects.get(code="PA00").id}
|
create_uv_template(self.bibou.id, code="PA00"),
|
||||||
),
|
|
||||||
create_uv_template(self.guy.id, code="PA00"),
|
|
||||||
)
|
)
|
||||||
self.assertEquals(response.status_code, 403)
|
self.assertEquals(response.status_code, 403)
|
||||||
|
|
||||||
# Simply subscribed user
|
# Simply subscribed user
|
||||||
self.client.login(username="sli", password="plop")
|
self.client.login(username="sli", password="plop")
|
||||||
response = self.client.post(
|
response = self.client.post(
|
||||||
reverse(
|
reverse("pedagogy:uv_update", kwargs={"uv_id": self.uv.id}),
|
||||||
"pedagogy:uv_update", kwargs={"uv_id": UV.objects.get(code="PA00").id}
|
create_uv_template(self.bibou.id, code="PA00"),
|
||||||
),
|
|
||||||
create_uv_template(self.sli.id, code="PA00"),
|
|
||||||
)
|
)
|
||||||
self.assertEquals(response.status_code, 403)
|
self.assertEquals(response.status_code, 403)
|
||||||
|
|
||||||
# Check that the UV has not changed
|
# Check that the UV has not changed
|
||||||
self.assertEquals(UV.objects.get(code="PA00").credit_type, "OM")
|
self.uv.refresh_from_db()
|
||||||
|
self.assertEquals(self.uv.credit_type, "OM")
|
||||||
|
|
||||||
|
|
||||||
# UVComment class tests
|
# UVComment class tests
|
||||||
|
@ -328,7 +328,8 @@ class UVUpdateView(CanEditPropMixin, UpdateView):
|
|||||||
|
|
||||||
def get_form_kwargs(self):
|
def get_form_kwargs(self):
|
||||||
kwargs = super(UVUpdateView, self).get_form_kwargs()
|
kwargs = super(UVUpdateView, self).get_form_kwargs()
|
||||||
kwargs["author_id"] = self.request.user.id
|
obj = self.get_object()
|
||||||
|
kwargs["author_id"] = obj.author.id
|
||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
def get_success_url(self):
|
def get_success_url(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user