From 857f2cf062f48b824eefeaa538d1ea0d51284adf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Dietm=C3=BCller?= Date: Wed, 27 Jan 2021 14:09:29 +0100 Subject: [PATCH 1/4] Studydocs: Always require type and add options. We do not wish to allow studydocs without type anymore, so the `type` field is not not nullable and required. Furthermore, we wish to differentiate between spring and autumn exams for better filtering, so the previous exam type is replaced. Closes #422 --- amivapi/studydocs/model.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/amivapi/studydocs/model.py b/amivapi/studydocs/model.py index ef5397e1..1717cbc6 100644 --- a/amivapi/studydocs/model.py +++ b/amivapi/studydocs/model.py @@ -182,9 +182,9 @@ def _validate_allow_summary(self, *args, **kwargs): 'type': { 'example': 'cheat sheets', 'type': 'string', - 'nullable': True, - 'default': None, - 'allowed': ['exams', 'oral exams', + 'required': True, + 'nullable': False, + 'allowed': ['spring exams', 'autumn exams', 'oral exams', 'cheat sheets', 'study guides', 'lecture documents', 'exercises'], 'allow_summary': True, From d7cb10cbfd75ed003ab3bf4e63c1ebad30c31484 Mon Sep 17 00:00:00 2001 From: Sandro Lutz Date: Tue, 24 May 2022 18:35:26 +0200 Subject: [PATCH 2/4] Update tests for studydocs --- amivapi/tests/studydocs/test_studydocs_auth.py | 5 ++++- amivapi/tests/studydocs/test_summary.py | 11 +++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/amivapi/tests/studydocs/test_studydocs_auth.py b/amivapi/tests/studydocs/test_studydocs_auth.py index 56b9b85e..d0946ff8 100644 --- a/amivapi/tests/studydocs/test_studydocs_auth.py +++ b/amivapi/tests/studydocs/test_studydocs_auth.py @@ -14,7 +14,7 @@ class StudydocsAuthTest(WebTest): - """Studycos Test class.""" + """Studydocs Test class.""" def test_uploader_added(self): """Test that the uploader is correctly added to a document.""" @@ -25,6 +25,7 @@ def test_uploader_added(self): headers={'content-type': 'multipart/form-data'}, data={ 'title': 'test', + 'type': 'cheat sheets', 'files': [ (BytesIO(test_file_content), 'test.zip') ] @@ -41,6 +42,7 @@ def test_can_edit_own_doc(self): headers={'content-type': 'multipart/form-data'}, data={ 'title': 'test', + 'type': 'cheat sheets', 'files': [ (BytesIO(test_file_content), 'test.zip') ] @@ -65,6 +67,7 @@ def test_can_not_edit_others_docs(self): headers={'content-type': 'multipart/form-data'}, data={ 'title': 'test', + 'type': 'cheat sheets', 'files': [ (BytesIO(test_file_content), 'test.zip') ] diff --git a/amivapi/tests/studydocs/test_summary.py b/amivapi/tests/studydocs/test_summary.py index 65f40887..45dbd284 100644 --- a/amivapi/tests/studydocs/test_summary.py +++ b/amivapi/tests/studydocs/test_summary.py @@ -17,14 +17,17 @@ def _load_data(self): self.load_fixture({ 'studydocuments': [{ 'title': 'first', + 'type': 'lecture documents', 'lecture': 'a', 'professor': 'a', }, { 'title': 'second', + 'type': 'cheat sheets', 'lecture': 'a', 'professor': 'b', }, { 'title': 'third', + 'type': 'lecture documents', 'professor': 'b', }] }) @@ -38,6 +41,10 @@ def test_full_summary(self): assert '_summary' in response assert response['_summary'] == { + 'type': { + 'lecture documents': 2, + 'cheat sheets': 1, + }, 'lecture': { 'a': 2, }, @@ -57,6 +64,10 @@ def test_filtered_summary(self): assert '_summary' in response assert response['_summary'] == { + 'type': { + 'lecture documents': 1, # The document with title `third` is ignored + 'cheat sheets': 1, + }, 'lecture': { 'a': 2, }, From 770c256449b2742f4e8f7fefb2462a1a04b3846a Mon Sep 17 00:00:00 2001 From: Sandro Lutz Date: Wed, 25 May 2022 09:56:15 +0200 Subject: [PATCH 3/4] Fix flake8 issues --- amivapi/tests/studydocs/test_summary.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/amivapi/tests/studydocs/test_summary.py b/amivapi/tests/studydocs/test_summary.py index 45dbd284..bfdb213f 100644 --- a/amivapi/tests/studydocs/test_summary.py +++ b/amivapi/tests/studydocs/test_summary.py @@ -65,7 +65,8 @@ def test_filtered_summary(self): assert '_summary' in response assert response['_summary'] == { 'type': { - 'lecture documents': 1, # The document with title `third` is ignored + # The document with title `third` is ignored + 'lecture documents': 1, 'cheat sheets': 1, }, 'lecture': { From 243344dc55b45ce807bbdfb58d43b8ca3c19ed43 Mon Sep 17 00:00:00 2001 From: Sandro Lutz Date: Mon, 10 Jul 2023 19:43:02 +0200 Subject: [PATCH 4/4] Update model.py --- amivapi/studydocs/model.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/amivapi/studydocs/model.py b/amivapi/studydocs/model.py index 1717cbc6..edfc80e0 100644 --- a/amivapi/studydocs/model.py +++ b/amivapi/studydocs/model.py @@ -184,7 +184,7 @@ def _validate_allow_summary(self, *args, **kwargs): 'type': 'string', 'required': True, 'nullable': False, - 'allowed': ['spring exams', 'autumn exams', 'oral exams', + 'allowed': ['exams', 'oral exams', 'cheat sheets', 'study guides', 'lecture documents', 'exercises'], 'allow_summary': True,