From 83df16366941db89a57aae1999b88f996e67b17b Mon Sep 17 00:00:00 2001 From: Or Ronai Date: Tue, 5 Oct 2021 12:24:14 +0300 Subject: [PATCH 01/10] feat: post delete and post save usercourse - Change user`s last course viewed depending on the saving and deleting of usercourses instances - Added a test --- lms/lmsdb/models.py | 25 ++++++++++++++++++++++++- tests/test_users.py | 18 ++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/lms/lmsdb/models.py b/lms/lmsdb/models.py index cf3c8bc1..f2521917 100644 --- a/lms/lmsdb/models.py +++ b/lms/lmsdb/models.py @@ -16,7 +16,9 @@ BooleanField, Case, CharField, Check, DateTimeField, ForeignKeyField, IntegerField, JOIN, ManyToManyField, TextField, UUIDField, fn, ) -from playhouse.signals import Model, post_save, pre_save # type: ignore +from playhouse.signals import ( # type: ignore + Model, post_delete, post_save, pre_save, +) from werkzeug.security import ( check_password_hash, generate_password_hash, ) @@ -265,6 +267,27 @@ def is_user_registered(cls, user_id: int, course_id: int) -> bool: ) +@post_save(sender=UserCourse) +def on_save_user_course(model_class, instance, created): + """Changes user's last course viewed.""" + + if instance.user.last_course_viewed is None: + instance.user.last_course_viewed = instance.course + instance.user.save() + + +@post_delete(sender=UserCourse) +def on_delete_user_course(model_class, instance): + """Changes user's last course viewed.""" + + if instance.user.last_course_viewed == instance.course: + if new_last_course_viewed := Course.fetch(instance.user).limit(1): + instance.user.last_course_viewed = new_last_course_viewed + else: + instance.user.last_course_viewed = None + instance.user.save() + + class Notification(BaseModel): ID_FIELD_NAME = 'id' MAX_PER_USER = 10 diff --git a/tests/test_users.py b/tests/test_users.py index 18ae9c1c..8cf183a6 100644 --- a/tests/test_users.py +++ b/tests/test_users.py @@ -185,3 +185,21 @@ def test_user_registered_to_course(student_user: User, course: Course): course2 = conftest.create_course(index=1) assert not course2.has_user(student_user) + @staticmethod + def test_usercourse_on_save(student_user: User, course: Course): + course2 = conftest.create_course(index=1) + usercourse2 = conftest.create_usercourse(student_user, course2) + assert student_user.last_course_viewed == course2 + + usercourse2.delete_instance() + print(student_user.last_course_viewed) + assert student_user.last_course_viewed is None + + usercourse = conftest.create_usercourse(student_user, course) + assert student_user.last_course_viewed == course + + conftest.create_usercourse(student_user, course2) + assert student_user.last_course_viewed == course + + usercourse.delete_instance() + assert student_user.last_course_viewed == course2 From 7d51028cad79d1ca7ab4dccd9b69e2d1733ef141 Mon Sep 17 00:00:00 2001 From: Or Ronai Date: Tue, 5 Oct 2021 12:29:03 +0300 Subject: [PATCH 02/10] splitted a test --- tests/test_users.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tests/test_users.py b/tests/test_users.py index 8cf183a6..63823ee5 100644 --- a/tests/test_users.py +++ b/tests/test_users.py @@ -186,15 +186,16 @@ def test_user_registered_to_course(student_user: User, course: Course): assert not course2.has_user(student_user) @staticmethod - def test_usercourse_on_save(student_user: User, course: Course): - course2 = conftest.create_course(index=1) - usercourse2 = conftest.create_usercourse(student_user, course2) - assert student_user.last_course_viewed == course2 + def test_usercourse_on_delete(student_user: User, course: Course): + usercourse = conftest.create_usercourse(student_user, course) + assert student_user.last_course_viewed == course - usercourse2.delete_instance() - print(student_user.last_course_viewed) + usercourse.delete_instance() assert student_user.last_course_viewed is None + @staticmethod + def test_usercourse_on_save(student_user: User, course: Course): + course2 = conftest.create_course(index=1) usercourse = conftest.create_usercourse(student_user, course) assert student_user.last_course_viewed == course From bb224f2c839ccba0359c542c976bd9cb257fbce5 Mon Sep 17 00:00:00 2001 From: Or Ronai Date: Wed, 6 Oct 2021 10:01:43 +0300 Subject: [PATCH 03/10] Changed post-delete usercourse and added a constraint --- lms/lmsdb/bootstrap.py | 12 ++++++++++++ lms/lmsdb/models.py | 12 ++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/lms/lmsdb/bootstrap.py b/lms/lmsdb/bootstrap.py index 740c1f20..9331ba52 100644 --- a/lms/lmsdb/bootstrap.py +++ b/lms/lmsdb/bootstrap.py @@ -287,6 +287,15 @@ def _add_exercise_course_id_and_number_columns_constraint() -> bool: db_config.database.commit() +def _add_user_course_constaint() -> bool: + migrator = db_config.get_migrator_instance() + with db_config.database.transaction(): + migrate( + migrator.add_index('usercourse', ('user_id', 'course_id'), True), + ) + db_config.database.commit() + + def _last_status_view_migration() -> bool: Solution = models.Solution _migrate_column_in_table_if_needed(Solution, Solution.last_status_view) @@ -312,6 +321,9 @@ def main(): _last_course_viewed_migration() _uuid_migration() + if models.database.table_exists(models.UserCourse.__name__.lower()): + _add_user_course_constaint() + models.database.create_tables(models.ALL_MODELS, safe=True) if models.Role.select().count() == 0: diff --git a/lms/lmsdb/models.py b/lms/lmsdb/models.py index f2521917..bb5acf3e 100644 --- a/lms/lmsdb/models.py +++ b/lms/lmsdb/models.py @@ -254,6 +254,11 @@ class UserCourse(BaseModel): course = ForeignKeyField(Course, backref='usercourses') date = DateTimeField(default=datetime.now) + class Meta: + indexes = ( + (('user_id', 'course_id'), True), + ) + @classmethod def is_user_registered(cls, user_id: int, course_id: int) -> bool: return ( @@ -270,7 +275,6 @@ def is_user_registered(cls, user_id: int, course_id: int) -> bool: @post_save(sender=UserCourse) def on_save_user_course(model_class, instance, created): """Changes user's last course viewed.""" - if instance.user.last_course_viewed is None: instance.user.last_course_viewed = instance.course instance.user.save() @@ -279,12 +283,8 @@ def on_save_user_course(model_class, instance, created): @post_delete(sender=UserCourse) def on_delete_user_course(model_class, instance): """Changes user's last course viewed.""" - if instance.user.last_course_viewed == instance.course: - if new_last_course_viewed := Course.fetch(instance.user).limit(1): - instance.user.last_course_viewed = new_last_course_viewed - else: - instance.user.last_course_viewed = None + instance.user.last_course_viewed = Course.fetch(instance.user).limit(1) instance.user.save() From 0405a24236902524eee1cc63d206ffbfd5026433 Mon Sep 17 00:00:00 2001 From: Or Ronai Date: Wed, 6 Oct 2021 10:55:08 +0300 Subject: [PATCH 04/10] fixed post-save usercourse instances --- lms/lmsdb/models.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lms/lmsdb/models.py b/lms/lmsdb/models.py index bb5acf3e..f7efa8b2 100644 --- a/lms/lmsdb/models.py +++ b/lms/lmsdb/models.py @@ -284,7 +284,9 @@ def on_save_user_course(model_class, instance, created): def on_delete_user_course(model_class, instance): """Changes user's last course viewed.""" if instance.user.last_course_viewed == instance.course: - instance.user.last_course_viewed = Course.fetch(instance.user).limit(1) + instance.user.last_course_viewed = ( + Course.fetch(instance.user).limit(1).scalar() + ) instance.user.save() From e443abb75a870c5e975c5163013ee69fa9a7bfbf Mon Sep 17 00:00:00 2001 From: Or Ronai Date: Wed, 6 Oct 2021 15:19:57 +0300 Subject: [PATCH 05/10] feat: Add public courses registeration page - Added the html template page - Added a test - Added translations - Added in the backend the logics of the pages and the public courses --- lms/lmsdb/bootstrap.py | 14 ++++-- lms/lmsdb/models.py | 10 +++- .../translations/he/LC_MESSAGES/messages.po | 50 ++++++++++++------- lms/lmsweb/views.py | 32 +++++++++++- lms/models/errors.py | 2 +- lms/models/users.py | 18 ++++++- lms/static/my.css | 11 ++-- lms/templates/public-courses.html | 19 +++++++ lms/templates/user.html | 3 ++ tests/test_registration.py | 20 +++++++- 10 files changed, 147 insertions(+), 32 deletions(-) create mode 100644 lms/templates/public-courses.html diff --git a/lms/lmsdb/bootstrap.py b/lms/lmsdb/bootstrap.py index 9331ba52..3731c871 100644 --- a/lms/lmsdb/bootstrap.py +++ b/lms/lmsdb/bootstrap.py @@ -290,9 +290,17 @@ def _add_exercise_course_id_and_number_columns_constraint() -> bool: def _add_user_course_constaint() -> bool: migrator = db_config.get_migrator_instance() with db_config.database.transaction(): - migrate( - migrator.add_index('usercourse', ('user_id', 'course_id'), True), - ) + try: + migrate( + migrator.add_index( + 'usercourse', ('user_id', 'course_id'), True, + ), + ) + except OperationalError as e: + if 'already exists' in str(e): + log.info(f'index usercourse already exists: {e}') + else: + raise db_config.database.commit() diff --git a/lms/lmsdb/models.py b/lms/lmsdb/models.py index f7efa8b2..bea5a71c 100644 --- a/lms/lmsdb/models.py +++ b/lms/lmsdb/models.py @@ -155,6 +155,14 @@ def fetch(cls, user: 'User') -> Iterable['Course']: .order_by(Course.name.desc()) ) + @classmethod + def public_courses(cls): + return cls.select().where(cls.is_public) + + @classmethod + def public_course_exists(cls): + return cls.public_courses().exists() + def __str__(self): return f'{self.name}: {self.date} - {self.end_date}' @@ -275,7 +283,7 @@ def is_user_registered(cls, user_id: int, course_id: int) -> bool: @post_save(sender=UserCourse) def on_save_user_course(model_class, instance, created): """Changes user's last course viewed.""" - if instance.user.last_course_viewed is None: + if instance.user.last_course_viewed is None or instance.course.is_public: instance.user.last_course_viewed = instance.course instance.user.save() diff --git a/lms/lmsweb/translations/he/LC_MESSAGES/messages.po b/lms/lmsweb/translations/he/LC_MESSAGES/messages.po index bffb9c09..404272c8 100644 --- a/lms/lmsweb/translations/he/LC_MESSAGES/messages.po +++ b/lms/lmsweb/translations/he/LC_MESSAGES/messages.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: 1.0\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2021-10-01 10:15+0300\n" +"POT-Creation-Date: 2021-10-06 15:07+0300\n" "PO-Revision-Date: 2021-09-29 11:30+0300\n" "Last-Translator: Or Ronai\n" "Language: he\n" @@ -18,7 +18,7 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Generated-By: Babel 2.9.1\n" -#: lmsdb/models.py:815 +#: lmsdb/models.py:864 msgid "Fatal error" msgstr "כישלון חמור" @@ -116,14 +116,19 @@ msgstr "%(checker)s הגיב לך על תרגיל \"%(subject)s\"." msgid "Your solution for the \"%(subject)s\" exercise has been checked." msgstr "הפתרון שלך לתרגיל \"%(subject)s\" נבדק." -#: models/users.py:28 +#: models/users.py:29 msgid "Invalid username or password" msgstr "שם המשתמש או הסיסמה שהוזנו לא תקינים" -#: models/users.py:31 +#: models/users.py:32 msgid "You have to confirm your registration with the link sent to your email" msgstr "עליך לאשר את מייל האימות" +#: models/users.py:50 +#, python-format +msgid "You are already registered to %(course_name)s course." +msgstr "אתה כבר רשום לקורס %(course_name)s." + #: templates/banned.html:8 templates/login.html:7 #: templates/recover-password.html:8 templates/reset-password.html:8 #: templates/signup.html:8 @@ -248,6 +253,11 @@ msgstr "בדוק תרגילים" msgid "Logout" msgstr "התנתקות" +#: templates/public-courses.html:6 +#, fuzzy +msgid "Public Courses List" +msgstr "רשימת קורסים פתוחים" + #: templates/recover-password.html:9 templates/recover-password.html:17 #: templates/reset-password.html:9 msgid "Reset Password" @@ -294,7 +304,7 @@ msgstr "חמ\"ל תרגילים" msgid "Name" msgstr "שם" -#: templates/status.html:13 templates/user.html:43 +#: templates/status.html:13 templates/user.html:46 msgid "Checked" msgstr "נבדק/ו" @@ -342,56 +352,60 @@ msgstr "פרטי משתמש" msgid "Actions" msgstr "פעולות" -#: templates/user.html:24 +#: templates/user.html:21 +msgid "Join Courses" +msgstr "הירשם לקורסים" + +#: templates/user.html:27 msgid "Exercises Submitted" msgstr "תרגילים שהוגשו" -#: templates/user.html:29 +#: templates/user.html:32 #, fuzzy msgid "Course name" msgstr "שם קורס" -#: templates/user.html:30 +#: templates/user.html:33 msgid "Exercise name" msgstr "שם תרגיל" -#: templates/user.html:31 +#: templates/user.html:34 msgid "Submission status" msgstr "מצב הגשה" -#: templates/user.html:32 +#: templates/user.html:35 msgid "Submission" msgstr "הגשה" -#: templates/user.html:33 +#: templates/user.html:36 msgid "Checker" msgstr "בודק" -#: templates/user.html:43 +#: templates/user.html:46 msgid "Submitted" msgstr "הוגש" -#: templates/user.html:43 +#: templates/user.html:46 msgid "Not submitted" msgstr "לא הוגש" -#: templates/user.html:54 +#: templates/user.html:57 msgid "Notes" msgstr "פתקיות" -#: templates/user.html:59 templates/user.html:61 +#: templates/user.html:62 templates/user.html:64 msgid "New Note" msgstr "פתקית חדשה" -#: templates/user.html:65 +#: templates/user.html:68 msgid "Related Exercise" msgstr "תרגיל משויך" -#: templates/user.html:74 +#: templates/user.html:77 msgid "Privacy Level" msgstr "רמת פרטיות" -#: templates/user.html:80 +#: templates/user.html:83 msgid "Add Note" msgstr "הוסף פתקית" diff --git a/lms/lmsweb/views.py b/lms/lmsweb/views.py index cc5c9689..945b539b 100644 --- a/lms/lmsweb/views.py +++ b/lms/lmsweb/views.py @@ -34,10 +34,10 @@ PERMISSIVE_CORS, get_next_url, login_manager, ) from lms.models import ( - comments, notes, notifications, share_link, solutions, upload, + comments, notes, notifications, share_link, solutions, upload, users, ) from lms.models.errors import ( - FileSizeError, ForbiddenPermission, LmsError, + AlreadyExists, FileSizeError, ForbiddenPermission, LmsError, UnauthorizedError, UploadError, fail, ) from lms.models.users import SERIALIZER, auth, retrieve_salt @@ -504,9 +504,37 @@ def user(user_id): user=target_user, is_manager=is_manager, notes_options=Note.get_note_options(), + public_course_exists=Course.public_course_exists(), ) +@webapp.route('/courses-list') +@login_required +def public_courses(): + return render_template( + 'public-courses.html', + courses=Course.public_courses(), + ) + + +@webapp.route('/join-course/') +@login_required +def join_public_course(course_id: int): + course = Course.get_or_none(course_id) + if course is None: + return fail(404, 'There is no such course.') + if not course.is_public: + return fail(403, "You aren't allowed to do this method.") + + try: + users.join_public_course(course, current_user) + except AlreadyExists as e: + error_message, status_code = e.args + return fail(status_code, error_message) + + return redirect(url_for('exercises_page')) + + @webapp.route('/send/', methods=['GET']) @login_required def send_(course_id: int): diff --git a/lms/models/errors.py b/lms/models/errors.py index 1a2ec15d..f3a38184 100644 --- a/lms/models/errors.py +++ b/lms/models/errors.py @@ -5,7 +5,7 @@ class LmsError(Exception): pass -class AlreadyExists(LmsError): +class AlreadyExists(LmsError): # Error 409 pass diff --git a/lms/models/users.py b/lms/models/users.py index afdb1de8..e4d9848e 100644 --- a/lms/models/users.py +++ b/lms/models/users.py @@ -3,10 +3,11 @@ from flask_babel import gettext as _ # type: ignore from itsdangerous import URLSafeTimedSerializer -from lms.lmsdb.models import User +from lms.lmsdb.models import Course, User, UserCourse from lms.lmsweb import config from lms.models.errors import ( - ForbiddenPermission, UnauthorizedError, UnhashedPasswordError, + AlreadyExists, ForbiddenPermission, UnauthorizedError, + UnhashedPasswordError, ) @@ -38,3 +39,16 @@ def auth(username: str, password: str) -> User: def generate_user_token(user: User) -> str: return SERIALIZER.dumps(user.mail_address, salt=retrieve_salt(user)) + + +def join_public_course(course: Course, user: User) -> None: + __, created = UserCourse.get_or_create(**{ + UserCourse.user.name: user, UserCourse.course.name: course, + }) + if not created: + raise AlreadyExists( + _( + 'You are already registered to %(course_name)s course.', + course_name=course.name, + ), 409, + ) diff --git a/lms/static/my.css b/lms/static/my.css index a637d906..e2cc2c45 100644 --- a/lms/static/my.css +++ b/lms/static/my.css @@ -811,16 +811,18 @@ code .grader-add .fa { } /* User's page */ -#user { +#user, #public-courses { text-align: right; } -#user h1 { +#user h1, +#public-courses h1 { margin: 5vh 0; text-align: center; } -#user .body { +#user .body, +#public-courses .body { width: 80vw; margin: auto; } @@ -829,7 +831,8 @@ code .grader-add .fa { width: 80vw; } -#user .user-actions { +#user .user-actions, +#public-courses .public-courses-links { margin-bottom: 5em; } diff --git a/lms/templates/public-courses.html b/lms/templates/public-courses.html new file mode 100644 index 00000000..0991a43b --- /dev/null +++ b/lms/templates/public-courses.html @@ -0,0 +1,19 @@ +{% extends 'base.html' %} + +{% block page_content %} +
+
+

{{ _('Public Courses List') }}

+
+ +
+
+
+ +{% endblock %} diff --git a/lms/templates/user.html b/lms/templates/user.html index aa523e15..c8f4ba3b 100644 --- a/lms/templates/user.html +++ b/lms/templates/user.html @@ -17,6 +17,9 @@

{{ _('Actions') }}:

diff --git a/tests/test_registration.py b/tests/test_registration.py index 572feae2..810b927a 100644 --- a/tests/test_registration.py +++ b/tests/test_registration.py @@ -4,7 +4,7 @@ from flask.testing import FlaskClient from lms.lmsweb.config import CONFIRMATION_TIME -from lms.lmsdb.models import User +from lms.lmsdb.models import Course, User from lms.models.users import generate_user_token from tests import conftest @@ -146,3 +146,21 @@ def test_registartion_closed(client: FlaskClient, captured_templates): template, _ = captured_templates[-1] assert template.name == 'login.html' assert '/signup' not in response.get_data(as_text=True) + + @staticmethod + def test_register_public_course( + student_user: User, course: Course, captured_templates, + ): + client = conftest.get_logged_user(username=student_user.username) + not_public_course_response = client.get(f'/join-course/{course.id}') + assert not_public_course_response.status_code == 403 + + unknown_course_response = client.get('/join-course/123456') + assert unknown_course_response.status_code == 404 + + course.is_public = True + course.save() + course = Course.get_by_id(course.id) + client.get(f'/join-course/{course.id}') + template, _ = captured_templates[-1] + assert template.name == 'exercises.html' From 495de80cf463b9fdde26430a3225607dac2bbccf Mon Sep 17 00:00:00 2001 From: Or Ronai Date: Wed, 6 Oct 2021 15:26:35 +0300 Subject: [PATCH 06/10] Fixed a test --- tests/test_registration.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/test_registration.py b/tests/test_registration.py index 810b927a..5aee0b68 100644 --- a/tests/test_registration.py +++ b/tests/test_registration.py @@ -164,3 +164,6 @@ def test_register_public_course( client.get(f'/join-course/{course.id}') template, _ = captured_templates[-1] assert template.name == 'exercises.html' + + already_registered_response = client.get(f'/join-course/{course.id}') + assert already_registered_response.status_code == 409 From 1bdbfa9ddad0403dc86899ca4bd567f9fa245cbe Mon Sep 17 00:00:00 2001 From: Or Ronai Date: Fri, 8 Oct 2021 16:09:05 +0300 Subject: [PATCH 07/10] Changed a logic in bootstrap.py file --- lms/lmsdb/bootstrap.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lms/lmsdb/bootstrap.py b/lms/lmsdb/bootstrap.py index 5fa885e5..78c3f7c0 100644 --- a/lms/lmsdb/bootstrap.py +++ b/lms/lmsdb/bootstrap.py @@ -278,12 +278,17 @@ def _add_exercise_course_id_and_number_columns_constraint() -> bool: Exercise = models.Exercise migrator = db_config.get_migrator_instance() with db_config.database.transaction(): - course_not_exists = _add_not_null_column(Exercise, Exercise.course) - number_not_exists = _add_not_null_column(Exercise, Exercise.number) - if course_not_exists and number_not_exists: + _add_not_null_column(Exercise, Exercise.course) + _add_not_null_column(Exercise, Exercise.number) + try: migrate( migrator.add_index('exercise', ('course_id', 'number'), True), ) + except OperationalError as e: + if 'already exists' in str(e): + log.info(f'index usercourse already exists: {e}') + else: + raise db_config.database.commit() From e91f7303fb8ce6eff255cd67a3bd1ce28e48ce00 Mon Sep 17 00:00:00 2001 From: Or Ronai Date: Fri, 8 Oct 2021 16:37:16 +0300 Subject: [PATCH 08/10] fixed logger info text --- lms/lmsdb/bootstrap.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lms/lmsdb/bootstrap.py b/lms/lmsdb/bootstrap.py index 78c3f7c0..cc21bd20 100644 --- a/lms/lmsdb/bootstrap.py +++ b/lms/lmsdb/bootstrap.py @@ -286,7 +286,7 @@ def _add_exercise_course_id_and_number_columns_constraint() -> bool: ) except OperationalError as e: if 'already exists' in str(e): - log.info(f'index usercourse already exists: {e}') + log.info(f'index exercise already exists: {e}') else: raise db_config.database.commit() From a21a29599b3c43bda65517f3404ac047b70c068a Mon Sep 17 00:00:00 2001 From: Or Ronai Date: Sun, 10 Oct 2021 09:12:09 +0300 Subject: [PATCH 09/10] Fixed 2 routes --- lms/lmsweb/views.py | 4 ++-- tests/test_registration.py | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lms/lmsweb/views.py b/lms/lmsweb/views.py index b12bc5eb..05b934d3 100644 --- a/lms/lmsweb/views.py +++ b/lms/lmsweb/views.py @@ -509,7 +509,7 @@ def user(user_id): ) -@webapp.route('/courses-list') +@webapp.route('/course') @login_required def public_courses(): return render_template( @@ -518,7 +518,7 @@ def public_courses(): ) -@webapp.route('/join-course/') +@webapp.route('/course/join/') @login_required def join_public_course(course_id: int): course = Course.get_or_none(course_id) diff --git a/tests/test_registration.py b/tests/test_registration.py index 5aee0b68..28021fae 100644 --- a/tests/test_registration.py +++ b/tests/test_registration.py @@ -152,18 +152,18 @@ def test_register_public_course( student_user: User, course: Course, captured_templates, ): client = conftest.get_logged_user(username=student_user.username) - not_public_course_response = client.get(f'/join-course/{course.id}') + not_public_course_response = client.get(f'/course/join/{course.id}') assert not_public_course_response.status_code == 403 - unknown_course_response = client.get('/join-course/123456') + unknown_course_response = client.get('/course/join/123456') assert unknown_course_response.status_code == 404 course.is_public = True course.save() course = Course.get_by_id(course.id) - client.get(f'/join-course/{course.id}') + client.get(f'/course/join/{course.id}') template, _ = captured_templates[-1] assert template.name == 'exercises.html' - already_registered_response = client.get(f'/join-course/{course.id}') + already_registered_response = client.get(f'/course/join/{course.id}') assert already_registered_response.status_code == 409 From df95c99a4f4a1d67af2def9578956fc42d356c26 Mon Sep 17 00:00:00 2001 From: Or Ronai Date: Mon, 11 Oct 2021 09:08:06 +0300 Subject: [PATCH 10/10] fixed a comment --- lms/models/errors.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lms/models/errors.py b/lms/models/errors.py index f3a38184..ac961326 100644 --- a/lms/models/errors.py +++ b/lms/models/errors.py @@ -5,7 +5,7 @@ class LmsError(Exception): pass -class AlreadyExists(LmsError): # Error 409 +class AlreadyExists(LmsError): # Usually a 409 HTTP Error pass