Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update views to class based #205

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Conversation

ZuluPro
Copy link

@ZuluPro ZuluPro commented Jun 16, 2024

I converted views to class based ones: FormView, RedirectView, TemplateView and View.
This will help developer to re-use the views and modifiy only part of them.

Function based views are still available through their path.

@adamspd
Copy link
Owner

adamspd commented Jun 19, 2024

Hi @ZuluPro,

To be honest, I'm not a great fan of class-based view, but putting my feelings aside, have you been able to run the tests ? It seems like they aren't working here.

You can run them locally with python manage.py test appointment.tests --parallel=10 --shuffle --verbosity=1

Just to satisfy my curiosity, do you have use-cases of reusing the views ?

Thanks

dependabot bot and others added 4 commits July 7, 2024 00:36
Bumps [phonenumbers](https://github.com/daviddrysdale/python-phonenumbers) from 8.13.38 to 8.13.39.
- [Commits](daviddrysdale/python-phonenumbers@v8.13.38...v8.13.39)

---
updated-dependencies:
- dependency-name: phonenumbers
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Bumps [pillow](https://github.com/python-pillow/Pillow) from 10.3.0 to 10.4.0.
- [Release notes](https://github.com/python-pillow/Pillow/releases)
- [Changelog](https://github.com/python-pillow/Pillow/blob/main/CHANGES.rst)
- [Commits](python-pillow/Pillow@10.3.0...10.4.0)

---
updated-dependencies:
- dependency-name: pillow
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Bumps [setuptools](https://github.com/pypa/setuptools) from 70.0.0 to 70.2.0.
- [Release notes](https://github.com/pypa/setuptools/releases)
- [Changelog](https://github.com/pypa/setuptools/blob/main/NEWS.rst)
- [Commits](pypa/setuptools@v70.0.0...v70.2.0)

---
updated-dependencies:
- dependency-name: setuptools
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
@github-actions github-actions bot added dependencies Pull requests that update a dependency file github-actions labels Jul 6, 2024
@ZuluPro
Copy link
Author

ZuluPro commented Jul 6, 2024

Hi @adamspd
Sorry for my late reply

The tests work perfectly:

Ran 433 tests in 36.554s
OK

I've updated the branch to the latest version.

About the why I suggest class based-views, here's a clear example:
I'm not satisfied by how the user are created.
So I would to rewrite a part of appointment_client_information,
But just the user creation.

Thank you

@adamspd
Copy link
Owner

adamspd commented Jul 15, 2024

Hi @ZuluPro,

Sorry for my late response as well, I just tried to run the test but one of them is failing.
I don't know why, but I'll try to see why before merging and also will try to keep the style of the code to maintain readability.

See below the output of the tests when I ran them:

pm test appointment.tests --parallel 10 --shuffle                                                                                                                                                                                              ─╯
Using shuffle seed: 5198731217 (generated)
Found 433 test(s).
Creating test database for alias 'default'...
Cloning test database for alias 'default'...
Cloning test database for alias 'default'...
Cloning test database for alias 'default'...
Cloning test database for alias 'default'...
Cloning test database for alias 'default'...
Cloning test database for alias 'default'...
Cloning test database for alias 'default'...
Cloning test database for alias 'default'...
Cloning test database for alias 'default'...
Cloning test database for alias 'default'...
System check identified no issues (0 silenced).
...............2024-07-15 00:01:02,789 - appointment.logger_config - INFO - New appointment created: {'id': 1, 'client_name': 'Georges', 'client_email': '[email protected]', 'start_time': '1900-01-01 09:00', 'end_time': '1900-01-01 10:00', 'service_name': 'Stargate Activation', 'address': '123, Stargate Command, Cheyenne Mountain, Colorado, USA', 'want_reminder': True, 'additional_info': 'Please bring a Zat gun.', 'paid': False, 'amount_to_pay': 100000, 'id_request': '17210016627886331b04a943dea074addbb50c3aacb5c7665'}
Missing conf: []
2024-07-15 00:01:02,816 - appointment.logger_config - INFO - Scheduling email reminder for appointment 1 at 2024-07-14 09:00:00+00:00
2024-07-15 00:01:02,825 - appointment.logger_config - INFO - Scheduling email reminder for appointment 1 at 2024-07-14 09:00:00+00:00
........................2024-07-15 00:01:03,489 - appointment.logger_config - INFO - Reminder for appointment 1 is not scheduled per user's preference or past datetime.
.2024-07-15 00:01:03,498 - appointment.logger_config - INFO - Reminder for appointment 1 is not scheduled per user's preference or past datetime.
response: b'{"message": "Appointment updated successfully.", "success": true, "appt": {"id": 1, "client": "georges.hammond", "start_time": "2024-07-15T15:00:26", "end_time": "2024-07-15T16:00:26", "client_name": "Vala Mal Doran", "url": "http://testserver/en/app-admin/display-appointment/1/", "background_color": "rgb(195, 22, 229)", "service_name": "Stargate Activation (Daniel)", "client_email": "[email protected]", "client_phone": "+12392350345", "client_address": "456 Outer Rim, Free Jaffa Nation", "service_id": 1, "staff_id": 1, "additional_info": "", "want_reminder": false}}'
2024-07-15 00:01:03,504 - django.request - WARNING - Not Found: /en/ajax/update_appt_min_info/
........2024-07-15 00:01:03,508 - django.request - WARNING - Bad Request: /en/ajax/update_appt_min_info/
....2024-07-15 00:01:03,515 - appointment.logger_config - INFO - New appointment created: {'id': 2, 'client_name': 'Vala Doran', 'client_email': '[email protected]', 'start_time': '1900-01-01 15:00', 'end_time': '1900-01-01 16:00', 'service_name': 'Stargate Activation', 'address': '456 Outer Rim, Free Jaffa Nation', 'want_reminder': False, 'additional_info': '', 'paid': False, 'amount_to_pay': 100000, 'id_request': '17210016635150652ca6702a43fde4489a74162c09d2e1f01'}
....2024-07-15 00:01:03,520 - django.request - WARNING - Not Found: /en/ajax/update_appt_min_info/
.........response: b'{"message": "Not a working day for Daniel. Please select another date!", "success": false, "errorCode": 6, "date_chosen": "Mon, July 15, 2024", "staff_member": "Daniel", "available_slots": []}'
..2024-07-15 00:01:03,632 - appointment.logger_config - INFO - Email verified successfully for user daniel.jackson
..........F.......................................2024-07-15 00:01:04,607 - appointment.logger_config - INFO - Reminder for appointment 1 is not scheduled per user's preference or past datetime.
..................Missing conf: []
.........................2024-07-15 00:01:05,169 - appointment.logger_config - INFO - Rescheduling is allowed for service Stargate Activation -> Reschedule count: 0, Reschedule limit: 0
2024-07-15 00:01:05,169 - appointment.logger_config - ERROR - Appointment with id_request 17210016651455281c47719dfd89c4a5bbe0e4f99a1e5f7c8 cannot be rescheduled
2024-07-15 00:01:05,173 - django.request - WARNING - Forbidden: /en/appointment/17210016651455281c47719dfd89c4a5bbe0e4f99a1e5f7c8/reschedule/
2024-07-15 00:01:05,176 - appointment.logger_config - INFO - Rescheduling is allowed but no specific limit set for service Stargate Activation -> Reschedule count: 0, Reschedule limit: 3
2024-07-15 00:01:05,185 - appointment.logger_config - INFO - Rescheduling is allowed but no specific limit set for service Stargate Activation -> Reschedule count: 0, Reschedule limit: 3
.........Missing conf: []
00:01:05 [Q] INFO Enqueued [DjangORM] 1
Missing conf: []
00:01:05 [Q] INFO Enqueued [DjangORM] 2
Missing conf: []
00:01:05 [Q] INFO Enqueued [DjangORM] 1
Missing conf: []
00:01:05 [Q] INFO Enqueued [DjangORM] 2
Missing conf: []
00:01:05 [Q] INFO Enqueued [DjangORM] 3
2024-07-15 00:01:05,731 - django.request - WARNING - Not Found: /en/confirm-reschedule/unique_id_request/
2024-07-15 00:01:05,738 - django.request - WARNING - Not Found: /en/confirm-reschedule/unique_id_request/
.....2024-07-15 00:01:05,776 - appointment.logger_config - INFO - date_f 2024-07-15 start_time 09:00:00 end_time 10:00:00 service Stargate Activation staff Daniel
.........00:01:05 [Q] INFO Enqueued [DjangORM] 1
...................................................2024-07-15 00:01:07,194 - django.request - WARNING - Not Found: /en/app-admin/delete-day-off/99999/
..2024-07-15 00:01:07,203 - django.request - WARNING - Not Found: /en/app-admin/update-day-off/99999/
.2024-07-15 00:01:07,364 - django.request - WARNING - Forbidden: /en/app-admin/delete-day-off/1/
2024-07-15 00:01:07,491 - django.request - WARNING - Unauthorized: /en/app-admin/display-appointment/1/
2024-07-15 00:01:07,507 - django.request - WARNING - Forbidden: /en/app-admin/add-day-off/2/
2024-07-15 00:01:07,521 - django.request - WARNING - Not Found: /en/app-admin/display-appointment/99999/
2024-07-15 00:01:07,521 - django.request - WARNING - Unauthorized: /en/app-admin/add-day-off/1/
....2024-07-15 00:01:07,657 - django.request - WARNING - Forbidden: /en/app-admin/update-day-off/1/
..........2024-07-15 00:01:07,659 - django.request - WARNING - Forbidden: /en/app-admin/display-appointment/1/
...............................2024-07-15 00:01:07,966 - django.request - WARNING - Not Found: /en/appointment-reschedule-submit/
........2024-07-15 00:01:08,391 - django.request - WARNING - Forbidden: /en/ajax/delete_appointment/
2024-07-15 00:01:08,397 - django.request - WARNING - Forbidden: /en/app-admin/delete-appointment/2/
..........................................2024-07-15 00:01:09,054 - django.request - WARNING - Not Found: /en/ajax/fetch_service_list_for_staff/
2024-07-15 00:01:09,057 - django.request - WARNING - Forbidden: /en/app-admin/delete-service/1/
2024-07-15 00:01:09,061 - django.request - WARNING - Not Found: /en/app-admin/delete-service/99999/
.......................Missing conf: []
00:01:09 [Q] INFO Enqueued [DjangORM] 1
........2024-07-15 00:01:09,386 - appointment.logger_config - INFO - Sending reminder to [email protected] for appointment 1
..........................2024-07-15 00:01:09,971 - appointment.logger_config - INFO - Email already in database, saving info in session and redirecting to enter verification code
.......Missing conf: []
00:01:10 [Q] INFO Enqueued [DjangORM] 1
2024-07-15 00:01:10,465 - django.request - WARNING - Forbidden: /en/app-admin/make-superuser-staff-member/
2024-07-15 00:01:10,469 - django.request - WARNING - Forbidden: /en/app-admin/remove-superuser-staff-member/
2024-07-15 00:01:10,474 - appointment.logger_config - INFO - Rescheduling is allowed but no specific limit set for service Stargate Activation -> Reschedule count: 0, Reschedule limit: 3
2024-07-15 00:01:10,478 - appointment.logger_config - INFO - Rescheduling is allowed but no specific limit set for service Stargate Activation -> Reschedule count: 2, Reschedule limit: 3
2024-07-15 00:01:10,479 - appointment.logger_config - INFO - Rescheduling is allowed but no specific limit set for service Stargate Activation -> Reschedule count: 3, Reschedule limit: 3
2024-07-15 00:01:10,482 - appointment.logger_config - INFO - Rescheduling is allowed for service Stargate Activation -> Reschedule count: 0, Reschedule limit: 0
2024-07-15 00:01:10,486 - appointment.logger_config - INFO - Rescheduling is allowed for service Stargate Activation -> Reschedule count: 4, Reschedule limit: 3
....................2024-07-15 00:01:10,721 - django.request - WARNING - Forbidden: /en/app-admin/add-staff-member-info/
.................
======================================================================
FAIL: test_exclude_with_pending_reschedules_within_last_5_minutes (appointment.tests.utils.test_db_helpers.ExcludePendingReschedulesTests)
Slots overlapping with pending rescheduling within the last 5 minutes should be excluded.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/unittest/case.py", line 59, in testPartExecutor
    yield
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/unittest/case.py", line 591, in run
    self._callTestMethod(testMethod)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/unittest/case.py", line 549, in _callTestMethod
    method()
  File "/Users/adamspierredavid/developer/PycharmProjects/django-appointment/appointment/tests/utils/test_db_helpers.py", line 1063, in test_exclude_with_pending_reschedules_within_last_5_minutes
    self.assertEqual(len(filtered_slots), len(self.slots) - 1)  # Assuming only one slot overlaps
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/unittest/case.py", line 845, in assertEqual
    assertion_func(first, second, msg=msg)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/unittest/case.py", line 838, in _baseAssertEqual
    raise self.failureException(msg)
AssertionError: 2 != 1

----------------------------------------------------------------------
Ran 433 tests in 10.920s

FAILED (failures=1)
Used shuffle seed: 5198731217 (generated)
Destroying test database for alias 'default'...
Destroying test database for alias 'default'...
Destroying test database for alias 'default'...
Destroying test database for alias 'default'...
Destroying test database for alias 'default'...
Destroying test database for alias 'default'...
Destroying test database for alias 'default'...
Destroying test database for alias 'default'...
Destroying test database for alias 'default'...
Destroying test database for alias 'default'...
Destroying test database for alias 'default'...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file github-actions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants