wbcore 2.2.1__py2.py3-none-any.whl → 2.2.4__py2.py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- wbcore/contrib/agenda/locale/de/LC_MESSAGES/django.po +113 -0
- wbcore/contrib/agenda/static/agenda/markdown/documentation/building.md +11 -0
- wbcore/contrib/agenda/static/agenda/markdown/documentation/conferenceroom.md +20 -0
- wbcore/contrib/authentication/fixtures/authentication.json +62 -0
- wbcore/contrib/authentication/locale/de/LC_MESSAGES/django.po +610 -0
- wbcore/contrib/authentication/templates/activate_confirm.html +12 -0
- wbcore/contrib/authentication/templates/base.html +135 -0
- wbcore/contrib/authentication/templates/email_base_template.html +335 -0
- wbcore/contrib/authentication/templates/password_reset_done.html +13 -0
- wbcore/contrib/authentication/templates/password_reset_email.html +11 -0
- wbcore/contrib/authentication/templates/password_reset_email_html.html +43 -0
- wbcore/contrib/authentication/templates/password_reset_form.html +23 -0
- wbcore/contrib/authentication/templates/password_reset_sent.html +11 -0
- wbcore/contrib/authentication/templates/reset_password.html +15 -0
- wbcore/contrib/authentication/templates/user_registration_email.html +37 -0
- wbcore/contrib/color/admin.py +28 -0
- wbcore/contrib/color/apps.py +5 -0
- wbcore/contrib/color/enums.py +17 -0
- wbcore/contrib/color/factories.py +10 -0
- wbcore/contrib/color/fields.py +29 -0
- wbcore/contrib/color/forms.py +13 -0
- wbcore/contrib/color/models.py +62 -0
- wbcore/contrib/color/tests/conftest.py +10 -0
- wbcore/contrib/color/tests/test_color_models.py +61 -0
- wbcore/contrib/color/tests/test_fields.py +25 -0
- wbcore/contrib/currency/fixtures/currency.yaml +1014 -0
- wbcore/contrib/currency/fixtures/currency_fx_rate.yaml +73585 -0
- wbcore/contrib/directory/fixtures/directory.json +3924 -0
- wbcore/contrib/directory/locale/de/LC_MESSAGES/django.po +1686 -0
- wbcore/contrib/directory/static/directory/markdown/documentation/address.md +38 -0
- wbcore/contrib/directory/static/directory/markdown/documentation/banking.md +54 -0
- wbcore/contrib/directory/static/directory/markdown/documentation/bankingentry.md +38 -0
- wbcore/contrib/directory/static/directory/markdown/documentation/clientmanagerrelationship.md +42 -0
- wbcore/contrib/directory/static/directory/markdown/documentation/company.md +52 -0
- wbcore/contrib/directory/static/directory/markdown/documentation/companytype.md +2 -0
- wbcore/contrib/directory/static/directory/markdown/documentation/customerstatus.md +2 -0
- wbcore/contrib/directory/static/directory/markdown/documentation/email.md +20 -0
- wbcore/contrib/directory/static/directory/markdown/documentation/employeecompany.md +34 -0
- wbcore/contrib/directory/static/directory/markdown/documentation/employerperson.md +43 -0
- wbcore/contrib/directory/static/directory/markdown/documentation/person.md +61 -0
- wbcore/contrib/directory/static/directory/markdown/documentation/position.md +2 -0
- wbcore/contrib/directory/static/directory/markdown/documentation/relationshiptype.md +2 -0
- wbcore/contrib/directory/static/directory/markdown/documentation/socialmedia.md +23 -0
- wbcore/contrib/directory/static/directory/markdown/documentation/specialization.md +2 -0
- wbcore/contrib/directory/static/directory/markdown/documentation/systememployee.md +31 -0
- wbcore/contrib/directory/static/directory/markdown/documentation/telephone.md +23 -0
- wbcore/contrib/directory/static/directory/markdown/documentation/telephonesearch.md +26 -0
- wbcore/contrib/directory/static/directory/markdown/documentation/userisclient.md +14 -0
- wbcore/contrib/directory/static/directory/markdown/documentation/userismanager.md +28 -0
- wbcore/contrib/directory/static/directory/markdown/documentation/website.md +20 -0
- wbcore/contrib/documents/fixtures/docments.json +135 -0
- wbcore/contrib/documents/locale/de/LC_MESSAGES/django.po +272 -0
- wbcore/contrib/documents/static/documents/markdown/documentation/document_types.md +21 -0
- wbcore/contrib/documents/static/documents/markdown/documentation/documents.md +18 -0
- wbcore/contrib/documents/static/documents/markdown/documentation/shareablelink.md +28 -0
- wbcore/contrib/documents/static/documents/markdown/documentation/shareablelinkaccess.md +20 -0
- wbcore/contrib/documents/tests/conftest.py +30 -0
- wbcore/contrib/documents/tests/test_models.py +144 -0
- wbcore/contrib/example_app/fixtures/example_app.json +7425 -0
- wbcore/contrib/example_app/tests/test_models/test_event.py +87 -0
- wbcore/contrib/example_app/tests/test_models/test_match.py +210 -0
- wbcore/contrib/example_app/tests/test_models/test_others.py +159 -0
- wbcore/contrib/example_app/tests/test_serializers/test_league_serializer.py +34 -0
- wbcore/contrib/example_app/tests/test_serializers/test_match_serializer.py +134 -0
- wbcore/contrib/example_app/tests/test_serializers/test_role_serializer.py +13 -0
- wbcore/contrib/example_app/tests/test_serializers/test_sport_serializer.py +14 -0
- wbcore/contrib/example_app/tests/test_serializers/test_stadium_serializer.py +14 -0
- wbcore/contrib/example_app/tests/test_serializers/test_team_result_serializer.py +30 -0
- wbcore/contrib/example_app/tests/test_serializers/test_team_serializer.py +70 -0
- wbcore/contrib/example_app/tests/test_viewsets/test_event_viewset.py +162 -0
- wbcore/contrib/example_app/tests/test_viewsets/test_league_viewset.py +84 -0
- wbcore/contrib/example_app/tests/test_viewsets/test_match_viewset.py +65 -0
- wbcore/contrib/example_app/tests/test_viewsets/test_person_viewset.py +166 -0
- wbcore/contrib/example_app/tests/test_viewsets/test_role_viewset.py +75 -0
- wbcore/contrib/example_app/tests/test_viewsets/test_sport_viewset.py +75 -0
- wbcore/contrib/example_app/tests/test_viewsets/test_stadium_viewset.py +75 -0
- wbcore/contrib/example_app/tests/test_viewsets/test_team_viewset.py +92 -0
- wbcore/contrib/example_app/tests/test_viewsets/test_teamresult_viewset.py +58 -0
- wbcore/contrib/example_app/tests/test_viewsets/test_utils_viewsets.py +124 -0
- wbcore/contrib/geography/fixtures/geography.json +13454 -0
- wbcore/contrib/geography/static/geography/markdown/documentation/geography.md +16 -0
- wbcore/contrib/guardian/apps.py +6 -0
- wbcore/contrib/guardian/configurations.py +3 -0
- wbcore/contrib/guardian/filters.py +21 -0
- wbcore/contrib/guardian/tasks.py +10 -0
- wbcore/contrib/guardian/urls.py +12 -0
- wbcore/contrib/guardian/utils.py +124 -0
- wbcore/contrib/io/fixtures/io.json +145 -0
- wbcore/contrib/io/locale/de/LC_MESSAGES/django.po +52 -0
- wbcore/contrib/notifications/locale/de/LC_MESSAGES/django.po +60 -0
- wbcore/contrib/notifications/static/notifications/service-worker.js +1 -0
- wbcore/contrib/notifications/templates/notifications/notification_template.html +43 -0
- wbcore/contrib/notifications/viewsets/configs/notification_types.py +27 -0
- wbcore/contrib/notifications/viewsets/configs/notifications.py +85 -0
- wbcore/contrib/workflow/fixtures/workflow.json +612 -0
- wbcore/contrib/workflow/locale/de/LC_MESSAGES/django.po +1289 -0
- wbcore/contrib/workflow/static/workflow/markdown/documentation/assignedprocessstep.md +33 -0
- wbcore/contrib/workflow/static/workflow/markdown/documentation/condition.md +24 -0
- wbcore/contrib/workflow/static/workflow/markdown/documentation/decisionstep.md +30 -0
- wbcore/contrib/workflow/static/workflow/markdown/documentation/emailstep.md +45 -0
- wbcore/contrib/workflow/static/workflow/markdown/documentation/finishstep.md +33 -0
- wbcore/contrib/workflow/static/workflow/markdown/documentation/joinstep.md +33 -0
- wbcore/contrib/workflow/static/workflow/markdown/documentation/process.md +33 -0
- wbcore/contrib/workflow/static/workflow/markdown/documentation/processstep.md +51 -0
- wbcore/contrib/workflow/static/workflow/markdown/documentation/scriptstep.md +33 -0
- wbcore/contrib/workflow/static/workflow/markdown/documentation/splitstep.md +30 -0
- wbcore/contrib/workflow/static/workflow/markdown/documentation/startstep.md +27 -0
- wbcore/contrib/workflow/static/workflow/markdown/documentation/transition.md +27 -0
- wbcore/contrib/workflow/static/workflow/markdown/documentation/userstep.md +42 -0
- wbcore/contrib/workflow/static/workflow/markdown/documentation/workflow.md +32 -0
- wbcore/contrib/workflow/templates/Test_Templates.txt +25 -0
- wbcore/contrib/workflow/tests/test_models/step/test_decision_step.py +79 -0
- wbcore/contrib/workflow/tests/test_models/step/test_email_step.py +45 -0
- wbcore/contrib/workflow/tests/test_models/step/test_finish_step.py +105 -0
- wbcore/contrib/workflow/tests/test_models/step/test_join_step.py +127 -0
- wbcore/contrib/workflow/tests/test_models/step/test_script_step.py +24 -0
- wbcore/contrib/workflow/tests/test_models/step/test_split_step.py +49 -0
- wbcore/contrib/workflow/tests/test_models/step/test_step.py +621 -0
- wbcore/contrib/workflow/tests/test_models/step/test_user_step.py +225 -0
- wbcore/contrib/workflow/tests/test_models/test_condition.py +103 -0
- wbcore/contrib/workflow/tests/test_models/test_data.py +134 -0
- wbcore/contrib/workflow/tests/test_models/test_process.py +98 -0
- wbcore/contrib/workflow/tests/test_models/test_transition.py +128 -0
- wbcore/contrib/workflow/tests/test_models/test_workflow.py +358 -0
- wbcore/locale/de/LC_MESSAGES/django.po +667 -0
- wbcore/templates/errors/404.html +134 -0
- wbcore/templates/errors/500.html +138 -0
- wbcore/templates/errors/503.html +132 -0
- wbcore/templates/errors/custom.html +132 -0
- wbcore/templates/forms.py +0 -0
- wbcore/templates/notifications/email_template.html +43 -0
- wbcore/templates/wbcore/admin/change_list.html +8 -0
- wbcore/templates/wbcore/admin/csv_form.html +15 -0
- wbcore/templates/wbcore/dynamic_color_array.html +29 -0
- wbcore/templates/wbcore/email_base_template.html +335 -0
- wbcore/templates/wbcore/email_notification_template.html +10 -0
- wbcore/templates/wbcore/frontend.html +51 -0
- wbcore/test/e2e_helpers_methods/e2e_checks.py +121 -0
- wbcore/test/e2e_helpers_methods/e2e_helper_methods.py +395 -0
- wbcore/tests/test_permissions/test_backend.py +29 -0
- {wbcore-2.2.1.dist-info → wbcore-2.2.4.dist-info}/METADATA +1 -1
- {wbcore-2.2.1.dist-info → wbcore-2.2.4.dist-info}/RECORD +143 -3
- {wbcore-2.2.1.dist-info → wbcore-2.2.4.dist-info}/WHEEL +0 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
from django.test import Client, TestCase
|
|
3
|
+
from django.urls import reverse
|
|
4
|
+
from wbcore.contrib.authentication.factories import SuperUserFactory
|
|
5
|
+
from wbcore.contrib.example_app.factories import SportFactory
|
|
6
|
+
from wbcore.contrib.example_app.models import Sport
|
|
7
|
+
from wbcore.contrib.example_app.serializers import SportModelSerializer
|
|
8
|
+
from wbcore.contrib.example_app.tests.test_viewsets.test_utils_viewsets import (
|
|
9
|
+
get_create_view,
|
|
10
|
+
get_delete_view,
|
|
11
|
+
get_detail_view,
|
|
12
|
+
get_partial_view,
|
|
13
|
+
get_update_view,
|
|
14
|
+
)
|
|
15
|
+
from wbcore.contrib.example_app.viewsets import SportModelViewSet
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@pytest.mark.django_db
|
|
19
|
+
class TestSportModelViewSet(TestCase):
|
|
20
|
+
def setUp(self):
|
|
21
|
+
self.user = SuperUserFactory()
|
|
22
|
+
self.client = Client()
|
|
23
|
+
self.client.force_login(user=self.user)
|
|
24
|
+
self.list_url = reverse("example_app:sport-list")
|
|
25
|
+
self.detail_url_str = "example_app:sport-detail"
|
|
26
|
+
|
|
27
|
+
def test_list_view(self):
|
|
28
|
+
response = self.client.get(self.list_url)
|
|
29
|
+
self.assertEqual(response.status_code, 200)
|
|
30
|
+
|
|
31
|
+
def test_create_view(self):
|
|
32
|
+
sport = SportFactory()
|
|
33
|
+
response = get_create_view(self.client, sport, self.user, self.list_url, SportModelViewSet)
|
|
34
|
+
self.assertEqual(response.status_code, 201)
|
|
35
|
+
self.assertTrue(Sport.objects.filter(name=sport.name).exists())
|
|
36
|
+
|
|
37
|
+
def test_detail_view(self):
|
|
38
|
+
instance = SportFactory()
|
|
39
|
+
response = get_detail_view(self.client, instance.pk, self.detail_url_str)
|
|
40
|
+
self.assertEqual(response.status_code, 200)
|
|
41
|
+
self.assertEqual(response.data["instance"]["name"], instance.name)
|
|
42
|
+
|
|
43
|
+
def test_update_view(self):
|
|
44
|
+
instance = SportFactory()
|
|
45
|
+
instance.name = "Updated Instance"
|
|
46
|
+
response = get_update_view(self.client, instance, SportModelSerializer, self.detail_url_str)
|
|
47
|
+
instance.refresh_from_db()
|
|
48
|
+
self.assertEqual(response.status_code, 200)
|
|
49
|
+
self.assertEqual(response.data["instance"]["name"], instance.name)
|
|
50
|
+
|
|
51
|
+
def test_partial_update_view(self):
|
|
52
|
+
instance = SportFactory()
|
|
53
|
+
response = get_partial_view(self.client, instance.id, {"name": "Patched name"}, self.detail_url_str)
|
|
54
|
+
instance.refresh_from_db()
|
|
55
|
+
self.assertEqual(response.status_code, 200)
|
|
56
|
+
self.assertEqual(response.data["instance"]["name"], instance.name)
|
|
57
|
+
|
|
58
|
+
def test_delete_view(self):
|
|
59
|
+
instance = SportFactory()
|
|
60
|
+
response = get_delete_view(self.client, self.detail_url_str, instance.pk)
|
|
61
|
+
self.assertEqual(response.status_code, 204)
|
|
62
|
+
self.assertFalse(Sport.objects.filter(pk=instance.pk).exists())
|
|
63
|
+
|
|
64
|
+
def test_ordering_fields(self):
|
|
65
|
+
first_name, second_name, third_name = "Team A", "Team B", "Team C"
|
|
66
|
+
SportFactory(name=second_name)
|
|
67
|
+
SportFactory(name=first_name)
|
|
68
|
+
SportFactory(name=third_name)
|
|
69
|
+
|
|
70
|
+
response = self.client.get(self.list_url)
|
|
71
|
+
self.assertEqual(response.status_code, 200)
|
|
72
|
+
self.assertEqual(response.data["count"], Sport.objects.count())
|
|
73
|
+
self.assertEqual(response.data["results"][0]["name"], first_name)
|
|
74
|
+
self.assertEqual(response.data["results"][1]["name"], second_name)
|
|
75
|
+
self.assertEqual(response.data["results"][2]["name"], third_name)
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
from django.test import Client, TestCase
|
|
3
|
+
from django.urls import reverse
|
|
4
|
+
from wbcore.contrib.authentication.factories import SuperUserFactory
|
|
5
|
+
from wbcore.contrib.example_app.factories import StadiumFactory
|
|
6
|
+
from wbcore.contrib.example_app.models import Stadium
|
|
7
|
+
from wbcore.contrib.example_app.serializers import StadiumModelSerializer
|
|
8
|
+
from wbcore.contrib.example_app.tests.test_viewsets.test_utils_viewsets import (
|
|
9
|
+
get_create_view,
|
|
10
|
+
get_delete_view,
|
|
11
|
+
get_detail_view,
|
|
12
|
+
get_partial_view,
|
|
13
|
+
get_update_view,
|
|
14
|
+
)
|
|
15
|
+
from wbcore.contrib.example_app.viewsets import StadiumModelViewSet
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@pytest.mark.django_db
|
|
19
|
+
class TestStadiumModelViewSet(TestCase):
|
|
20
|
+
def setUp(self):
|
|
21
|
+
self.user = SuperUserFactory()
|
|
22
|
+
self.client = Client()
|
|
23
|
+
self.client.force_login(user=self.user)
|
|
24
|
+
self.list_url = reverse("example_app:stadium-list")
|
|
25
|
+
self.detail_url_str = "example_app:stadium-detail"
|
|
26
|
+
|
|
27
|
+
def test_list_view(self):
|
|
28
|
+
response = self.client.get(self.list_url)
|
|
29
|
+
self.assertEqual(response.status_code, 200)
|
|
30
|
+
|
|
31
|
+
def test_create_view(self):
|
|
32
|
+
stadium = StadiumFactory()
|
|
33
|
+
response = get_create_view(self.client, stadium, self.user, self.list_url, StadiumModelViewSet)
|
|
34
|
+
self.assertEqual(response.status_code, 201)
|
|
35
|
+
self.assertTrue(Stadium.objects.filter(name=stadium.name).exists())
|
|
36
|
+
|
|
37
|
+
def test_detail_view(self):
|
|
38
|
+
instance = StadiumFactory()
|
|
39
|
+
response = get_detail_view(self.client, instance.pk, self.detail_url_str)
|
|
40
|
+
self.assertEqual(response.status_code, 200)
|
|
41
|
+
self.assertEqual(response.data["instance"]["name"], instance.name)
|
|
42
|
+
|
|
43
|
+
def test_update_view(self):
|
|
44
|
+
instance = StadiumFactory()
|
|
45
|
+
instance.name = "Updated Instance"
|
|
46
|
+
response = get_update_view(self.client, instance, StadiumModelSerializer, self.detail_url_str)
|
|
47
|
+
instance.refresh_from_db()
|
|
48
|
+
self.assertEqual(response.status_code, 200)
|
|
49
|
+
self.assertEqual(response.data["instance"]["name"], instance.name)
|
|
50
|
+
|
|
51
|
+
def test_partial_update_view(self):
|
|
52
|
+
instance = StadiumFactory()
|
|
53
|
+
response = get_partial_view(self.client, instance.id, {"name": "Updated Instance"}, self.detail_url_str)
|
|
54
|
+
instance.refresh_from_db()
|
|
55
|
+
self.assertEqual(response.status_code, 200)
|
|
56
|
+
self.assertEqual(response.data["instance"]["name"], instance.name)
|
|
57
|
+
|
|
58
|
+
def test_delete_view(self):
|
|
59
|
+
instance = StadiumFactory()
|
|
60
|
+
response = get_delete_view(self.client, self.detail_url_str, instance.pk)
|
|
61
|
+
self.assertEqual(response.status_code, 204)
|
|
62
|
+
self.assertFalse(Stadium.objects.filter(pk=instance.pk).exists())
|
|
63
|
+
|
|
64
|
+
def test_ordering_fields(self):
|
|
65
|
+
first_name, second_name, third_name = "Stadium A", "Stadium B", "Stadium C"
|
|
66
|
+
StadiumFactory(name=second_name)
|
|
67
|
+
StadiumFactory(name=first_name)
|
|
68
|
+
StadiumFactory(name=third_name)
|
|
69
|
+
|
|
70
|
+
response = self.client.get(self.list_url)
|
|
71
|
+
self.assertEqual(response.status_code, 200)
|
|
72
|
+
self.assertEqual(response.data["count"], Stadium.objects.count())
|
|
73
|
+
self.assertEqual(response.data["results"][0]["name"], first_name)
|
|
74
|
+
self.assertEqual(response.data["results"][1]["name"], second_name)
|
|
75
|
+
self.assertEqual(response.data["results"][2]["name"], third_name)
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
from django.test import Client, TestCase
|
|
3
|
+
from django.urls import reverse
|
|
4
|
+
from wbcore.contrib.authentication.factories import SuperUserFactory
|
|
5
|
+
from wbcore.contrib.example_app.factories import TeamFactory
|
|
6
|
+
from wbcore.contrib.example_app.models import Team
|
|
7
|
+
from wbcore.contrib.example_app.serializers import TeamModelSerializer
|
|
8
|
+
from wbcore.contrib.example_app.tests.test_viewsets.test_utils_viewsets import ( # get_update_view,
|
|
9
|
+
find_instances_in_response,
|
|
10
|
+
get_create_view,
|
|
11
|
+
get_delete_view,
|
|
12
|
+
get_detail_view,
|
|
13
|
+
get_partial_view,
|
|
14
|
+
get_update_view,
|
|
15
|
+
)
|
|
16
|
+
from wbcore.contrib.example_app.viewsets import TeamModelViewSet
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@pytest.mark.django_db
|
|
20
|
+
class TestTeamModelViewSet(TestCase):
|
|
21
|
+
def setUp(self):
|
|
22
|
+
self.user = SuperUserFactory()
|
|
23
|
+
self.client = Client()
|
|
24
|
+
self.client.force_login(user=self.user)
|
|
25
|
+
self.list_url = reverse("example_app:team-list")
|
|
26
|
+
self.detail_url_str = "example_app:team-detail"
|
|
27
|
+
|
|
28
|
+
def test_list_view(self):
|
|
29
|
+
response = self.client.get(self.list_url)
|
|
30
|
+
self.assertEqual(response.status_code, 200)
|
|
31
|
+
|
|
32
|
+
def test_create_view(self):
|
|
33
|
+
team = TeamFactory()
|
|
34
|
+
response = get_create_view(self.client, team, self.user, self.list_url, TeamModelViewSet)
|
|
35
|
+
self.assertEqual(response.status_code, 201)
|
|
36
|
+
self.assertTrue(Team.objects.filter(name=team.name).exists())
|
|
37
|
+
|
|
38
|
+
def test_detail_view(self):
|
|
39
|
+
team = TeamFactory()
|
|
40
|
+
response = get_detail_view(self.client, team.pk, self.detail_url_str)
|
|
41
|
+
self.assertEqual(response.status_code, 200)
|
|
42
|
+
self.assertEqual(response.data["instance"]["name"], team.name)
|
|
43
|
+
|
|
44
|
+
def test_update_view(self):
|
|
45
|
+
instance = TeamFactory()
|
|
46
|
+
instance.name = "Updated Instance"
|
|
47
|
+
response = get_update_view(self.client, instance, TeamModelSerializer, self.detail_url_str)
|
|
48
|
+
self.assertEqual(response.status_code, 200)
|
|
49
|
+
self.assertEqual(response.data["instance"]["name"], instance.name)
|
|
50
|
+
|
|
51
|
+
def test_partial_update_view(self):
|
|
52
|
+
instance = TeamFactory()
|
|
53
|
+
response = get_partial_view(self.client, instance.id, {"name": "Updated Instance"}, self.detail_url_str)
|
|
54
|
+
instance.refresh_from_db()
|
|
55
|
+
self.assertEqual(response.status_code, 200)
|
|
56
|
+
self.assertEqual(response.data["instance"]["name"], instance.name)
|
|
57
|
+
|
|
58
|
+
def test_delete_view(self):
|
|
59
|
+
team = TeamFactory()
|
|
60
|
+
response = get_delete_view(self.client, self.detail_url_str, team.pk)
|
|
61
|
+
self.assertEqual(response.status_code, 204)
|
|
62
|
+
self.assertFalse(Team.objects.filter(pk=team.pk).exists())
|
|
63
|
+
|
|
64
|
+
def test_ordering_fields(self):
|
|
65
|
+
team_a = TeamFactory(name="BBB", order=1)
|
|
66
|
+
team_b = TeamFactory(name="AAA", order=0)
|
|
67
|
+
team_c = TeamFactory(name="CCC", order=2)
|
|
68
|
+
|
|
69
|
+
response = self.client.get(self.list_url)
|
|
70
|
+
self.assertEqual(response.status_code, 200)
|
|
71
|
+
self.assertEqual(response.data["count"], Team.objects.count())
|
|
72
|
+
self.assertEqual(response.data["results"][0]["id"], team_b.id)
|
|
73
|
+
self.assertEqual(response.data["results"][1]["id"], team_a.id)
|
|
74
|
+
self.assertEqual(response.data["results"][2]["id"], team_c.id)
|
|
75
|
+
|
|
76
|
+
def test_team_stadium(self):
|
|
77
|
+
team_a = TeamFactory()
|
|
78
|
+
team_b = TeamFactory(home_stadium=team_a.home_stadium)
|
|
79
|
+
team_c = TeamFactory()
|
|
80
|
+
expected_number_of_teams = Team.objects.filter(home_stadium=team_a.home_stadium).count()
|
|
81
|
+
team_stadium_url = reverse("example_app:team-stadium-list", args=[team_a.home_stadium.id])
|
|
82
|
+
response = self.client.get(team_stadium_url)
|
|
83
|
+
team_a_found, team_b_found, team_c_found = find_instances_in_response([team_a, team_b, team_c], response)
|
|
84
|
+
self.assertEqual(
|
|
85
|
+
response.data["count"],
|
|
86
|
+
expected_number_of_teams,
|
|
87
|
+
f"The answer should contain {expected_number_of_teams} teams",
|
|
88
|
+
)
|
|
89
|
+
self.assertEqual(response.status_code, 200)
|
|
90
|
+
self.assertTrue(team_a_found, "Team A was not found in Response")
|
|
91
|
+
self.assertTrue(team_b_found, "Team B was not found in Response")
|
|
92
|
+
self.assertFalse(team_c_found, "Team C was found in Response, but should not be found")
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
from django.test import Client, TestCase
|
|
3
|
+
from django.urls import reverse
|
|
4
|
+
from wbcore.contrib.authentication.factories import SuperUserFactory
|
|
5
|
+
from wbcore.contrib.example_app.factories import TeamResultsFactory
|
|
6
|
+
from wbcore.contrib.example_app.serializers import TeamResultsModelSerializer
|
|
7
|
+
from wbcore.contrib.example_app.tests.test_viewsets.test_utils_viewsets import (
|
|
8
|
+
get_create_view,
|
|
9
|
+
get_delete_view,
|
|
10
|
+
get_detail_view,
|
|
11
|
+
get_partial_view,
|
|
12
|
+
get_update_view,
|
|
13
|
+
)
|
|
14
|
+
from wbcore.contrib.example_app.viewsets import TeamResultsModelViewSet
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@pytest.mark.django_db
|
|
18
|
+
class TestTeamResultsModelViewSet(TestCase):
|
|
19
|
+
def setUp(self):
|
|
20
|
+
self.user = SuperUserFactory()
|
|
21
|
+
self.client = Client()
|
|
22
|
+
self.client.force_login(user=self.user)
|
|
23
|
+
self.list_url = reverse("example_app:teamresults-list")
|
|
24
|
+
self.detail_url_str = "example_app:teamresults-detail"
|
|
25
|
+
|
|
26
|
+
def test_list_view(self):
|
|
27
|
+
response = self.client.get(self.list_url)
|
|
28
|
+
self.assertEqual(response.status_code, 200)
|
|
29
|
+
|
|
30
|
+
def test_create_view(self):
|
|
31
|
+
team_result = TeamResultsFactory()
|
|
32
|
+
response = get_create_view(self.client, team_result, self.user, self.list_url, TeamResultsModelViewSet)
|
|
33
|
+
# It is not possible to create an team results, since the get_endpoint_url returns None.
|
|
34
|
+
self.assertEqual(response.status_code, 405)
|
|
35
|
+
|
|
36
|
+
def test_detail_view(self):
|
|
37
|
+
instance = TeamResultsFactory()
|
|
38
|
+
response = get_detail_view(self.client, instance.pk, self.detail_url_str)
|
|
39
|
+
self.assertEqual(response.status_code, 200)
|
|
40
|
+
self.assertEqual(response.data["instance"]["id"], instance.id)
|
|
41
|
+
|
|
42
|
+
def test_update_view(self):
|
|
43
|
+
instance = TeamResultsFactory()
|
|
44
|
+
instance.points = 5
|
|
45
|
+
response = get_update_view(self.client, instance, TeamResultsModelSerializer, self.detail_url_str)
|
|
46
|
+
# It is not possible to update an team results, since the get_endpoint_url returns None.
|
|
47
|
+
self.assertEqual(response.status_code, 405)
|
|
48
|
+
|
|
49
|
+
def test_partial_update_view(self):
|
|
50
|
+
instance = TeamResultsFactory()
|
|
51
|
+
response = get_partial_view(self.client, instance.id, {"points": 5}, self.detail_url_str)
|
|
52
|
+
self.assertEqual(response.status_code, 405)
|
|
53
|
+
|
|
54
|
+
def test_delete_view(self):
|
|
55
|
+
instance = TeamResultsFactory()
|
|
56
|
+
response = get_delete_view(self.client, self.detail_url_str, instance.pk)
|
|
57
|
+
# It is not possible to delete an team results, since the get_endpoint_url returns None.
|
|
58
|
+
self.assertEqual(response.status_code, 405)
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
from django.db.models import Model
|
|
2
|
+
from django.http import HttpResponse
|
|
3
|
+
from django.test import Client
|
|
4
|
+
from django.urls import reverse
|
|
5
|
+
from wbcore.contrib.authentication.models import User
|
|
6
|
+
from wbcore.serializers import Serializer
|
|
7
|
+
from wbcore.test.utils import get_data_from_factory
|
|
8
|
+
from wbcore.viewsets import ModelViewSet
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def get_create_view(
|
|
12
|
+
client: Client,
|
|
13
|
+
instance: Model,
|
|
14
|
+
superuser: User,
|
|
15
|
+
url: str,
|
|
16
|
+
viewset: ModelViewSet,
|
|
17
|
+
) -> HttpResponse:
|
|
18
|
+
"""
|
|
19
|
+
Create a new instance through a view using the Django REST Framework client.
|
|
20
|
+
|
|
21
|
+
Parameters:
|
|
22
|
+
- client (django.test.Client): The Django test client.
|
|
23
|
+
- instance (django.db.models.Model): The model instance to be created.
|
|
24
|
+
- superuser (django.contrib.auth.models.User): The superuser for authentication.
|
|
25
|
+
- url (str): The URL endpoint for the view.
|
|
26
|
+
- viewset (wbcore.viewsets.ModelViewSet): The viewset for the model.
|
|
27
|
+
|
|
28
|
+
Returns:
|
|
29
|
+
django.http.HttpResponse: The HTTP response from the view.
|
|
30
|
+
"""
|
|
31
|
+
instance_data = get_data_from_factory(instance, viewset, delete=True, superuser=superuser)
|
|
32
|
+
return client.post(url, instance_data)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def get_detail_view(client: Client, pk: int, url: str) -> HttpResponse:
|
|
36
|
+
"""
|
|
37
|
+
Retrieve the details of a model instance through a detail view using the Django REST Framework client.
|
|
38
|
+
|
|
39
|
+
Parameters:
|
|
40
|
+
- client (django.test.Client): The Django test client.
|
|
41
|
+
- pk (int): The primary key of the model instance to retrieve.
|
|
42
|
+
- url (str): The base URL endpoint for the detail view.
|
|
43
|
+
|
|
44
|
+
Returns:
|
|
45
|
+
django.http.HttpResponse: The HTTP response from the detail view.
|
|
46
|
+
"""
|
|
47
|
+
detail_url = reverse(url, args=[pk])
|
|
48
|
+
return client.get(detail_url)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def get_update_view(client: Client, instance: Model, serializer: Serializer, url: str) -> HttpResponse:
|
|
52
|
+
"""
|
|
53
|
+
Update a model instance through an update view using the Django REST Framework client.
|
|
54
|
+
|
|
55
|
+
Parameters:
|
|
56
|
+
- client (django.test.Client): The Django test client.
|
|
57
|
+
- instance (django.db.models.Model): The model instance to be updated.
|
|
58
|
+
- serializer (Serializer): The serializer used to serialize the instance.
|
|
59
|
+
- url (str): The base URL endpoint for the update view.
|
|
60
|
+
|
|
61
|
+
Returns:
|
|
62
|
+
django.http.HttpResponse: The HTTP response from the update view.
|
|
63
|
+
"""
|
|
64
|
+
update_url = reverse(url, args=[instance.pk])
|
|
65
|
+
serialized_data = serializer(instance).data
|
|
66
|
+
return client.put(update_url, data=serialized_data, content_type="application/json")
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def get_partial_view(client: Client, instance_id: int, data: dict, url: str) -> HttpResponse:
|
|
70
|
+
"""
|
|
71
|
+
Facilitates partial updates to a specific instance of a model using the Django REST Framework client.
|
|
72
|
+
|
|
73
|
+
Parameters:
|
|
74
|
+
- client (django.test.Client): The Django test client.
|
|
75
|
+
- instance_id (int): The unique identifier (primary key) of the instance to be partially updated.
|
|
76
|
+
- data (dict): A dictionary containing the fields and their respective new values that need to be updated in the instance.
|
|
77
|
+
- url (str): The base URL endpoint for the patch view.
|
|
78
|
+
Returns:
|
|
79
|
+
django.http.HttpResponse: The HTTP response from the patch view.
|
|
80
|
+
"""
|
|
81
|
+
update_url = reverse(url, args=[instance_id])
|
|
82
|
+
return client.patch(update_url, data=data, content_type="application/json")
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def get_delete_view(client: Client, url: str, pk: int) -> HttpResponse:
|
|
86
|
+
"""
|
|
87
|
+
Delete a model instance through a delete view using the Django REST Framework client.
|
|
88
|
+
|
|
89
|
+
Parameters:
|
|
90
|
+
- client (django.test.Client): The Django test client.
|
|
91
|
+
- url (str): The base URL endpoint for the delete view.
|
|
92
|
+
- pk (int): The primary key of the model instance to delete.
|
|
93
|
+
|
|
94
|
+
Returns:
|
|
95
|
+
django.http.HttpResponse: The HTTP response from the delete view.
|
|
96
|
+
"""
|
|
97
|
+
delete_url = reverse(url, args=[pk])
|
|
98
|
+
return client.delete(delete_url)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def find_instances_in_response(instances: list[Model], response: HttpResponse) -> tuple:
|
|
102
|
+
"""
|
|
103
|
+
Find instances in the data contained in an HTTP response.
|
|
104
|
+
|
|
105
|
+
This method takes a list of instances and an HTTP response object, and it checks if each instance
|
|
106
|
+
is present in the data of the response based on their unique identifier (e.g., 'id').
|
|
107
|
+
|
|
108
|
+
Parameters:
|
|
109
|
+
- instances (list): A list of instances (models) to search for in the response data.
|
|
110
|
+
- response (HttpResponse): An HTTP response object containing data to search within.
|
|
111
|
+
|
|
112
|
+
Returns:
|
|
113
|
+
tuple: A tuple of Boolean values indicating whether each instance was found in the response.
|
|
114
|
+
Each element in the tuple corresponds to an instance in the same order as in the 'instances' list.
|
|
115
|
+
If an instance is found, the corresponding value is True; otherwise, it is False.
|
|
116
|
+
"""
|
|
117
|
+
found_instances = [False] * len(instances)
|
|
118
|
+
|
|
119
|
+
for item in response.data["results"]:
|
|
120
|
+
for index, instance in enumerate(instances):
|
|
121
|
+
if item.get("id") == instance.id:
|
|
122
|
+
found_instances[index] = True
|
|
123
|
+
|
|
124
|
+
return tuple(found_instances)
|