Mise à jour d'avril (#643)

This commit is contained in:
Julien Constant
2023-05-10 11:56:33 +02:00
committed by GitHub
parent 910a6f8b34
commit 288764b551
201 changed files with 1746 additions and 1144 deletions

View File

@ -9,7 +9,6 @@ import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [migrations.swappable_dependency(settings.AUTH_USER_MODEL)]

View File

@ -45,7 +45,6 @@ def remove_multiples_comments_from_same_user(apps, schema_editor):
class Migration(migrations.Migration):
dependencies = [("pedagogy", "0001_initial")]
operations = [

View File

@ -147,7 +147,7 @@ class UV(models.Model):
"""
Can be created by superuser, root or pedagogy admin user
"""
return user.is_in_group(settings.SITH_GROUP_PEDAGOGY_ADMIN_ID)
return user.is_in_group(pk=settings.SITH_GROUP_PEDAGOGY_ADMIN_ID)
def can_be_viewed_by(self, user):
"""

View File

@ -83,12 +83,12 @@ class UVCreation(TestCase):
Test uv creation
"""
def setUp(self):
call_command("populate")
self.bibou = User.objects.filter(username="root").first()
self.tutu = User.objects.filter(username="tutu").first()
self.sli = User.objects.filter(username="sli").first()
self.guy = User.objects.filter(username="guy").first()
@classmethod
def setUp(cls):
cls.bibou = User.objects.get(username="root")
cls.tutu = User.objects.get(username="tutu")
cls.sli = User.objects.get(username="sli")
cls.guy = User.objects.get(username="guy")
def test_create_uv_admin_success(self):
self.client.login(username="root", password="plop")
@ -157,9 +157,6 @@ class UVListTest(TestCase):
Test guide display rights
"""
def setUp(self):
call_command("populate")
def test_uv_list_display_success(self):
# Display for root
self.client.login(username="root", password="plop")
@ -192,9 +189,6 @@ class UVDeleteTest(TestCase):
Test UV deletion rights
"""
def setUp(self):
call_command("populate")
def test_uv_delete_root_success(self):
self.client.login(username="root", password="plop")
self.client.post(
@ -250,7 +244,6 @@ class UVUpdateTest(TestCase):
"""
def setUp(self):
call_command("populate")
self.bibou = User.objects.filter(username="root").first()
self.tutu = User.objects.filter(username="tutu").first()
self.uv = UV.objects.get(code="PA00")
@ -341,13 +334,13 @@ class UVCommentCreationAndDisplay(TestCase):
Display and creation are the same view
"""
def setUp(self):
call_command("populate")
self.bibou = User.objects.filter(username="root").first()
self.tutu = User.objects.filter(username="tutu").first()
self.sli = User.objects.filter(username="sli").first()
self.guy = User.objects.filter(username="guy").first()
self.uv = UV.objects.get(code="PA00")
@classmethod
def setUpTestData(cls):
cls.bibou = User.objects.get(username="root")
cls.tutu = User.objects.get(username="tutu")
cls.sli = User.objects.get(username="sli")
cls.guy = User.objects.get(username="guy")
cls.uv = UV.objects.get(code="PA00")
def test_create_uv_comment_admin_success(self):
self.client.login(username="root", password="plop")
@ -473,7 +466,6 @@ class UVCommentDeleteTest(TestCase):
"""
def setUp(self):
call_command("populate")
comment_kwargs = create_uv_comment_template(
User.objects.get(username="krophil").id
)
@ -533,11 +525,11 @@ class UVCommentUpdateTest(TestCase):
Test UVComment update rights
"""
@classmethod
def setUpTestData(cls):
cls.krophil = User.objects.get(username="krophil")
def setUp(self):
call_command("populate")
self.krophil = User.objects.get(username="krophil")
# Prepare a comment
comment_kwargs = create_uv_comment_template(self.krophil.id)
comment_kwargs["author"] = self.krophil
@ -624,7 +616,6 @@ class UVSearchTest(TestCase):
"""
def setUp(self):
call_command("populate")
call_command("update_index", "pedagogy")
def test_get_page_authorized_success(self):
@ -758,7 +749,6 @@ class UVSearchTest(TestCase):
)
def test_search_pa00_fail(self):
# Search with UV code
response = self.client.get(reverse("pedagogy:guide"), {"search": "IFC"})
self.assertNotContains(response, text="PA00")
@ -795,8 +785,6 @@ class UVModerationFormTest(TestCase):
"""
def setUp(self):
call_command("populate")
self.krophil = User.objects.get(username="krophil")
# Prepare a comment
@ -1024,8 +1012,6 @@ class UVCommentReportCreateTest(TestCase):
"""
def setUp(self):
call_command("populate")
self.krophil = User.objects.get(username="krophil")
self.tutu = User.objects.get(username="tutu")
@ -1087,7 +1073,7 @@ class UVCommentReportCreateTest(TestCase):
# Check that only pedagogy admins recieves this notification
for notif in Notification.objects.filter(type="PEDAGOGY_MODERATION").all():
self.assertTrue(
notif.user.is_in_group(settings.SITH_GROUP_PEDAGOGY_ADMIN_ID)
notif.user.is_in_group(pk=settings.SITH_GROUP_PEDAGOGY_ADMIN_ID)
)
# Check that notifications are not duplicated if not viewed

View File

@ -206,7 +206,9 @@ class UVListView(CanViewMixin, CanCreateUVFunctionMixin, ListView):
except TypeError:
return self.model.objects.none()
return queryset.filter(id__in=([o.object.id for o in qs]))
return queryset.filter(
id__in=([o.object.id for o in qs if o.object is not None])
)
class UVCommentReportCreateView(CanCreateMixin, CreateView):