diff --git a/smash/web/api_views/worker.py b/smash/web/api_views/worker.py index ece5fc05954e7a2423e2c71164b237143efc1f5e..5183e3cd3fa5ae515102ed8e8d860f27f52c0c7f 100644 --- a/smash/web/api_views/worker.py +++ b/smash/web/api_views/worker.py @@ -24,7 +24,6 @@ def units(request): @login_required def workers_for_daily_planning(request): workers = get_workers_for_daily_planning(request) - print workers workers_list_for_json = [] for worker in workers: worker_dict_for_json = { diff --git a/smash/web/models/subject.py b/smash/web/models/subject.py index c0a0b4b86d55c2054a3e2ddd6d6839ffddd2cb04..756cb960ea2bbf9ec58382fefe724bce9d4c8c7e 100644 --- a/smash/web/models/subject.py +++ b/smash/web/models/subject.py @@ -168,16 +168,6 @@ class Subject(models.Model): editable=True ) - def latest_visit(self): - visits = self.visit_set.all() - if len(visits) == 0: - return None - result = visits[0] - for visit in visits: - if visit.datetime_begin > result.datetime_begin: - result = visit - return result - def __str__(self): return "%s %s" % (self.first_name, self.last_name) diff --git a/smash/web/tests/test_api_appointment.py b/smash/web/tests/api_views/test_appointment.py similarity index 100% rename from smash/web/tests/test_api_appointment.py rename to smash/web/tests/api_views/test_appointment.py diff --git a/smash/web/tests/test_api_appointment_type.py b/smash/web/tests/api_views/test_appointment_type.py similarity index 100% rename from smash/web/tests/test_api_appointment_type.py rename to smash/web/tests/api_views/test_appointment_type.py diff --git a/smash/web/tests/test_api_configuration_item.py b/smash/web/tests/api_views/test_configuration_item.py similarity index 98% rename from smash/web/tests/test_api_configuration_item.py rename to smash/web/tests/api_views/test_configuration_item.py index 102e3a5b6d2451e3d9238400affa0034171526a7..d4becf7cf6bf7b12b93de0a747e21e903c0e4eed 100644 --- a/smash/web/tests/test_api_configuration_item.py +++ b/smash/web/tests/api_views/test_configuration_item.py @@ -4,9 +4,9 @@ from django.urls import reverse from web.models import ConfigurationItem -from web.tests.functions import create_configuration_item -from . import LoggedInTestCase from web.models.constants import CANCELLED_APPOINTMENT_COLOR_CONFIGURATION_TYPE +from web.tests import LoggedInTestCase +from web.tests.functions import create_configuration_item class TestConfigurationItemApi(LoggedInTestCase): diff --git a/smash/web/tests/test_api_location.py b/smash/web/tests/api_views/test_location.py similarity index 100% rename from smash/web/tests/test_api_location.py rename to smash/web/tests/api_views/test_location.py diff --git a/smash/web/tests/api_views/test_subject.py b/smash/web/tests/api_views/test_subject.py index 18dea89e5beafb36befd06d1e348b90ce7182226..b96c694f54f7ed06018e760c30f8ddd9f27462a5 100644 --- a/smash/web/tests/api_views/test_subject.py +++ b/smash/web/tests/api_views/test_subject.py @@ -415,8 +415,6 @@ class TestApi(TestCase): appointment.save() visit.mark_as_finished() - print Visit.objects.all() - self.check_subject_filtered([["visit_1", "DONE"]], [subject]) self.check_subject_filtered([["visit_2", "UPCOMING"]], [subject]) diff --git a/smash/web/tests/forms/__init__.py b/smash/web/tests/forms/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/smash/web/tests/test_AppointmentAddForm.py b/smash/web/tests/forms/test_AppointmentAddForm.py similarity index 89% rename from smash/web/tests/test_AppointmentAddForm.py rename to smash/web/tests/forms/test_AppointmentAddForm.py index 7861e12f9bb24e72c016e4e3a8101e9492cfdbb6..a63675e57ba5affc5d5e7b3c70a7dfda3d5074e7 100644 --- a/smash/web/tests/test_AppointmentAddForm.py +++ b/smash/web/tests/forms/test_AppointmentAddForm.py @@ -1,9 +1,9 @@ from django.test import TestCase -from functions import create_user, create_visit, create_location -from functions import get_test_location from web.forms import AppointmentAddForm from web.models import Worker +from web.tests.functions import create_user, create_visit, create_location +from web.tests.functions import get_test_location class AppointmentAddFormTests(TestCase): diff --git a/smash/web/tests/test_AppointmentEditForm.py b/smash/web/tests/forms/test_AppointmentEditForm.py similarity index 94% rename from smash/web/tests/test_AppointmentEditForm.py rename to smash/web/tests/forms/test_AppointmentEditForm.py index eba5c6d0970e19908dd90f34a5e224d3153f34e8..0a60144efbc9916be9c6eee7f3719a2f1fa937f7 100644 --- a/smash/web/tests/test_AppointmentEditForm.py +++ b/smash/web/tests/forms/test_AppointmentEditForm.py @@ -1,9 +1,9 @@ from django.test import TestCase -from functions import get_test_location, create_user, create_visit, create_location from web.forms import AppointmentAddForm from web.forms import AppointmentEditForm from web.models import Appointment, Worker +from web.tests.functions import get_test_location, create_user, create_visit, create_location class AppointmentEditFormTests(TestCase): diff --git a/smash/web/tests/test_AvailabilityAddForm.py b/smash/web/tests/forms/test_AvailabilityAddForm.py similarity index 93% rename from smash/web/tests/test_AvailabilityAddForm.py rename to smash/web/tests/forms/test_AvailabilityAddForm.py index 85987100244f414824869bec471a1e3d4aca0143..0d8f1beec26c159dc2d6807d359222c77b4a0618 100644 --- a/smash/web/tests/test_AvailabilityAddForm.py +++ b/smash/web/tests/forms/test_AvailabilityAddForm.py @@ -1,10 +1,10 @@ from django.test import TestCase -from functions import create_user, create_visit -from functions import get_test_location -from web.models.constants import MONDAY_AS_DAY_OF_WEEK from web.forms import AvailabilityAddForm from web.models import Worker +from web.models.constants import MONDAY_AS_DAY_OF_WEEK +from web.tests.functions import create_user, create_visit +from web.tests.functions import get_test_location class AvailabilityAddFormTests(TestCase): diff --git a/smash/web/tests/test_AvailabilityEditForm.py b/smash/web/tests/forms/test_AvailabilityEditForm.py similarity index 89% rename from smash/web/tests/test_AvailabilityEditForm.py rename to smash/web/tests/forms/test_AvailabilityEditForm.py index 9d2d3bd1106c50f5626e3ebaeca788ba94ce6232..0779eabecdfaf3c93c4206a7da65fb0bec05dd3d 100644 --- a/smash/web/tests/test_AvailabilityEditForm.py +++ b/smash/web/tests/forms/test_AvailabilityEditForm.py @@ -1,10 +1,10 @@ from django.test import TestCase -from functions import create_user, create_visit -from functions import get_test_location -from web.models.constants import MONDAY_AS_DAY_OF_WEEK from web.forms import AvailabilityEditForm, AvailabilityAddForm from web.models import Worker +from web.models.constants import MONDAY_AS_DAY_OF_WEEK +from web.tests.functions import create_user, create_visit +from web.tests.functions import get_test_location class AvailabilityEditFormTests(TestCase): diff --git a/smash/web/tests/test_SubjectAddForm.py b/smash/web/tests/forms/test_SubjectAddForm.py similarity index 98% rename from smash/web/tests/test_SubjectAddForm.py rename to smash/web/tests/forms/test_SubjectAddForm.py index 77e9c6d6044ed42cc320175d7ec6e9ba98db6938..c22fee47c48f9c39f4b4a4567b5f93cf0fe73673 100644 --- a/smash/web/tests/test_SubjectAddForm.py +++ b/smash/web/tests/forms/test_SubjectAddForm.py @@ -2,9 +2,9 @@ from django.contrib.auth.models import User from django.test import Client from django.test import TestCase -from functions import get_test_location, create_subject, create_worker from web.forms import SubjectAddForm, get_new_screening_number from web.models.constants import SEX_CHOICES_MALE, SUBJECT_TYPE_CHOICES_CONTROL +from web.tests.functions import get_test_location, create_subject, create_worker class SubjectAddFormTests(TestCase): diff --git a/smash/web/tests/test_SubjectEditForm.py b/smash/web/tests/forms/test_SubjectEditForm.py similarity index 97% rename from smash/web/tests/test_SubjectEditForm.py rename to smash/web/tests/forms/test_SubjectEditForm.py index bf9fb7314eb8a5109b03ecf8efc90d249fc40663..25f2047ac34f8da86c28b130ace30aa68b3832e9 100644 --- a/smash/web/tests/test_SubjectEditForm.py +++ b/smash/web/tests/forms/test_SubjectEditForm.py @@ -1,12 +1,12 @@ from django.contrib.auth.models import User -from django.test import TestCase from django.test import Client +from django.test import TestCase -from functions import get_test_location, create_worker from web.forms import SubjectAddForm from web.forms import SubjectEditForm from web.models import Subject from web.models.constants import SEX_CHOICES_MALE, SUBJECT_TYPE_CHOICES_CONTROL +from web.tests.functions import get_test_location, create_worker class SubjectEditFormTests(TestCase): diff --git a/smash/web/tests/test_VisitAddForm.py b/smash/web/tests/forms/test_VisitAddForm.py similarity index 92% rename from smash/web/tests/test_VisitAddForm.py rename to smash/web/tests/forms/test_VisitAddForm.py index 2efa428bd1f802e54a6b32f654193beadd7982eb..b6a0d817ad2b577e83bcbf9a03fbfd71b3baf6f7 100644 --- a/smash/web/tests/test_VisitAddForm.py +++ b/smash/web/tests/forms/test_VisitAddForm.py @@ -2,9 +2,9 @@ from __future__ import print_function from django.test import TestCase -from functions import create_subject -from functions import get_test_location from web.forms import VisitAddForm +from web.tests.functions import create_subject +from web.tests.functions import get_test_location class VisitAddFormTests(TestCase): diff --git a/smash/web/tests/test_model_appointment.py b/smash/web/tests/models/test_appointment.py similarity index 87% rename from smash/web/tests/test_model_appointment.py rename to smash/web/tests/models/test_appointment.py index 36525f581b4dba2ebd12f93c49db85e1dbf4397d..a781e69c9ec36a99bd92e3cbf5616d16ee8d2b4d 100644 --- a/smash/web/tests/test_model_appointment.py +++ b/smash/web/tests/models/test_appointment.py @@ -1,6 +1,6 @@ from django.test import TestCase -from functions import create_appointment +from web.tests.functions import create_appointment class AppointmentModelTests(TestCase): diff --git a/smash/web/tests/test_model_configuration_item.py b/smash/web/tests/models/test_configuration_item.py similarity index 100% rename from smash/web/tests/test_model_configuration_item.py rename to smash/web/tests/models/test_configuration_item.py diff --git a/smash/web/tests/test_model_mail_template.py b/smash/web/tests/models/test_mail_template.py similarity index 98% rename from smash/web/tests/test_model_mail_template.py rename to smash/web/tests/models/test_mail_template.py index 0460314373a98c926c4dcabf9b725cf9949efd81..df6611fa60ba7e30d85dd82241d422b2508e3b0f 100644 --- a/smash/web/tests/test_model_mail_template.py +++ b/smash/web/tests/models/test_mail_template.py @@ -3,12 +3,12 @@ import StringIO from django.test import TestCase from docx import Document -from functions import create_language, get_resource_path, create_appointment, create_user, create_subject, \ - create_visit from web.models import MailTemplate from web.models.constants import MAIL_TEMPLATE_CONTEXT_APPOINTMENT, MAIL_TEMPLATE_CONTEXT_VISIT, \ MAIL_TEMPLATE_CONTEXT_SUBJECT from web.models.mail_template import DATE_FORMAT_SHORT +from web.tests.functions import create_language, get_resource_path, create_appointment, create_user, create_subject, \ + create_visit class MailTemplateModelTests(TestCase): diff --git a/smash/web/tests/models/test_visit.py b/smash/web/tests/models/test_visit.py index 3b30283777dd33b7638cb0b2fd57860e8ddb029c..835b7a66569ddbed84abf6212822e7dcf6ae8bee 100644 --- a/smash/web/tests/models/test_visit.py +++ b/smash/web/tests/models/test_visit.py @@ -35,3 +35,7 @@ class VisitModelTests(TestCase): visit_count = Visit.objects.filter(subject=subject).count() self.assertEquals(1, visit_count) + + def test_visit_to_string(self): + visit = create_visit(create_subject()) + self.assertIsNotNone(str(visit)) diff --git a/smash/web/tests/models/test_worker.py b/smash/web/tests/models/test_worker.py index be91b963bf4c9136f2432abf49f52a8489c1667b..9b193326f06a1cbbe7992c61ead7f00d6e8552e5 100644 --- a/smash/web/tests/models/test_worker.py +++ b/smash/web/tests/models/test_worker.py @@ -2,6 +2,7 @@ from django.contrib.auth.models import User from django.test import Client from django.test import TestCase +from web.models import Worker from web.tests.functions import create_worker @@ -29,3 +30,19 @@ class WorkerModelTests(TestCase): def test_is_active_for_invalid(self): worker = create_worker() self.assertFalse(worker.is_active()) + + def test_get_by_user_for_None(self): + worker = Worker.get_by_user(None) + self.assertIsNone(worker) + + def test_get_by_user_for_Worker(self): + worker = create_worker() + worker_2 = Worker.get_by_user(worker) + self.assertEqual(worker, worker_2) + + def test_get_by_user_for_invalid(self): + try: + Worker.get_by_user("invalid object") + self.fail("Exception expected") + except TypeError: + pass diff --git a/smash/web/tests/test_view_configuration.py b/smash/web/tests/view/test_configuration.py similarity index 87% rename from smash/web/tests/test_view_configuration.py rename to smash/web/tests/view/test_configuration.py index 4b9bbccdc61c23d13edd9b6e2906314a5c995573..23a147796de28f012dcf257e1dac12313160bcb3 100644 --- a/smash/web/tests/test_view_configuration.py +++ b/smash/web/tests/view/test_configuration.py @@ -2,7 +2,7 @@ import datetime from django.urls import reverse -from . import LoggedInTestCase +from web.tests import LoggedInTestCase class ConfigurationViewTests(LoggedInTestCase): diff --git a/smash/web/tests/test_view_contact_attempt.py b/smash/web/tests/view/test_contact_attempt.py similarity index 96% rename from smash/web/tests/test_view_contact_attempt.py rename to smash/web/tests/view/test_contact_attempt.py index 6a36fdaaaa2310d8e929e7e0440b05bd414a4197..9bb40d7191ef127995ec1a01f2a9618c91547971 100644 --- a/smash/web/tests/test_view_contact_attempt.py +++ b/smash/web/tests/view/test_contact_attempt.py @@ -4,10 +4,10 @@ from django.urls import reverse from django.utils import timezone from web.forms import ContactAttemptEditForm -from functions import create_subject, create_contact_attempt, format_form_field from web.models import ContactAttempt from web.models.constants import CONTACT_TYPES_EMAIL -from . import LoggedInWithWorkerTestCase +from web.tests import LoggedInWithWorkerTestCase +from web.tests.functions import create_subject, create_contact_attempt, format_form_field class ContactAttemptViewTests(LoggedInWithWorkerTestCase): diff --git a/smash/web/tests/test_view_export.py b/smash/web/tests/view/test_export.py similarity index 90% rename from smash/web/tests/test_view_export.py rename to smash/web/tests/view/test_export.py index f15c2cf439a9012999ff91ef88a9fc1e928a0679..f2c7850f269e95d3ddc8f051d676f2971e9d5761 100644 --- a/smash/web/tests/test_view_export.py +++ b/smash/web/tests/view/test_export.py @@ -1,8 +1,8 @@ # coding=utf-8 from django.urls import reverse -from functions import create_subject, create_appointment -from . import LoggedInTestCase +from web.tests import LoggedInTestCase +from web.tests.functions import create_subject, create_appointment class TestExportView(LoggedInTestCase): diff --git a/smash/web/tests/test_view_functions.py b/smash/web/tests/view/test_functions.py similarity index 88% rename from smash/web/tests/test_view_functions.py rename to smash/web/tests/view/test_functions.py index 7df3e0a0a13ae7b9fcb0d1dfd87c09cac5060f89..d03ab059ae136521a764883b443018f105fdc894 100644 --- a/smash/web/tests/test_view_functions.py +++ b/smash/web/tests/view/test_functions.py @@ -1,6 +1,6 @@ from django.test import TestCase -from functions import create_location, create_user, create_worker, get_test_location +from web.tests.functions import create_location, create_user, create_worker, get_test_location from web.views.notifications import get_filter_locations diff --git a/smash/web/tests/test_view_kit_request.py b/smash/web/tests/view/test_kit_request.py similarity index 97% rename from smash/web/tests/test_view_kit_request.py rename to smash/web/tests/view/test_kit_request.py index cc82b543178595e8433f7f5c26ac2aadb3090f39..f0d199b6fff21bc039695c1caa1e30e53330062a 100644 --- a/smash/web/tests/test_view_kit_request.py +++ b/smash/web/tests/view/test_kit_request.py @@ -3,11 +3,11 @@ import datetime from django.core import mail from django.urls import reverse -from functions import create_appointment_type, create_appointment, create_visit from web.models import Item, Appointment, AppointmentTypeLink +from web.tests import LoggedInTestCase +from web.tests.functions import create_appointment_type, create_appointment, create_visit from web.views.kit import get_kit_requests from web.views.notifications import get_today_midnight_date -from . import LoggedInTestCase class ViewFunctionsTests(LoggedInTestCase): diff --git a/smash/web/tests/test_view_login.py b/smash/web/tests/view/test_login.py similarity index 97% rename from smash/web/tests/test_view_login.py rename to smash/web/tests/view/test_login.py index f3fa9b05d3152c6fc7a6542e03bbaf4a8937c0d1..f66d376e1efa0d5dc7c11f6c0617f095a4b57af5 100644 --- a/smash/web/tests/test_view_login.py +++ b/smash/web/tests/view/test_login.py @@ -5,8 +5,8 @@ from django.test import Client from django.test import TestCase from django.urls import reverse -from functions import create_user from web.models import Worker +from web.tests.functions import create_user class TestLoginView(TestCase): diff --git a/smash/web/tests/test_view_notifications.py b/smash/web/tests/view/test_notifications.py similarity index 98% rename from smash/web/tests/test_view_notifications.py rename to smash/web/tests/view/test_notifications.py index 9c79dd8cbdac2dbdbfbd6e8608d659e65ddbfcd8..c2586124a76f713af2746ad99f1cf5063123c773 100644 --- a/smash/web/tests/test_view_notifications.py +++ b/smash/web/tests/view/test_notifications.py @@ -2,10 +2,11 @@ import datetime from django.contrib.auth.models import AnonymousUser -from functions import create_appointment, create_location, create_worker, create_appointment_type -from functions import create_subject -from functions import create_visit from web.models import Appointment, Location, AppointmentTypeLink +from web.tests import LoggedInTestCase +from web.tests.functions import create_appointment, create_location, create_worker, create_appointment_type +from web.tests.functions import create_subject +from web.tests.functions import create_visit from web.views.notifications import \ get_approaching_visits_for_mail_contact, \ get_approaching_visits_for_mail_contact_count, \ @@ -22,7 +23,6 @@ from web.views.notifications import \ get_unfinished_appointments, \ get_unfinished_appointments_count, \ get_unfinished_visits -from . import LoggedInTestCase class NotificationViewTests(LoggedInTestCase): diff --git a/smash/web/tests/test_view_statistics.py b/smash/web/tests/view/test_statistics.py similarity index 94% rename from smash/web/tests/test_view_statistics.py rename to smash/web/tests/view/test_statistics.py index eac349b67a9893e701d39d75606647b797e60592..795a1ed830cb1d8310daca986c651ff19e8a666b 100644 --- a/smash/web/tests/test_view_statistics.py +++ b/smash/web/tests/view/test_statistics.py @@ -3,7 +3,7 @@ from datetime import datetime from django.urls import reverse -from . import LoggedInTestCase +from web.tests import LoggedInTestCase __author__ = 'Valentin Grouès' diff --git a/smash/web/tests/test_view_visit.py b/smash/web/tests/view/test_visit.py similarity index 96% rename from smash/web/tests/test_view_visit.py rename to smash/web/tests/view/test_visit.py index b8c0a28696966ba193af9e1bba78da8d8a5e56ba..217475e6822e106079f7fc52550b706bcddd3a55 100644 --- a/smash/web/tests/test_view_visit.py +++ b/smash/web/tests/view/test_visit.py @@ -2,11 +2,11 @@ import datetime from django.urls import reverse -from functions import create_subject, create_visit, create_appointment, create_appointment_type from web.forms import VisitDetailForm, VisitAddForm from web.models import Visit +from web.tests import LoggedInTestCase +from web.tests.functions import create_subject, create_visit, create_appointment, create_appointment_type from web.views.notifications import get_today_midnight_date -from . import LoggedInTestCase class VisitViewTests(LoggedInTestCase):