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.
Files changed (143) hide show
  1. wbcore/contrib/agenda/locale/de/LC_MESSAGES/django.po +113 -0
  2. wbcore/contrib/agenda/static/agenda/markdown/documentation/building.md +11 -0
  3. wbcore/contrib/agenda/static/agenda/markdown/documentation/conferenceroom.md +20 -0
  4. wbcore/contrib/authentication/fixtures/authentication.json +62 -0
  5. wbcore/contrib/authentication/locale/de/LC_MESSAGES/django.po +610 -0
  6. wbcore/contrib/authentication/templates/activate_confirm.html +12 -0
  7. wbcore/contrib/authentication/templates/base.html +135 -0
  8. wbcore/contrib/authentication/templates/email_base_template.html +335 -0
  9. wbcore/contrib/authentication/templates/password_reset_done.html +13 -0
  10. wbcore/contrib/authentication/templates/password_reset_email.html +11 -0
  11. wbcore/contrib/authentication/templates/password_reset_email_html.html +43 -0
  12. wbcore/contrib/authentication/templates/password_reset_form.html +23 -0
  13. wbcore/contrib/authentication/templates/password_reset_sent.html +11 -0
  14. wbcore/contrib/authentication/templates/reset_password.html +15 -0
  15. wbcore/contrib/authentication/templates/user_registration_email.html +37 -0
  16. wbcore/contrib/color/admin.py +28 -0
  17. wbcore/contrib/color/apps.py +5 -0
  18. wbcore/contrib/color/enums.py +17 -0
  19. wbcore/contrib/color/factories.py +10 -0
  20. wbcore/contrib/color/fields.py +29 -0
  21. wbcore/contrib/color/forms.py +13 -0
  22. wbcore/contrib/color/models.py +62 -0
  23. wbcore/contrib/color/tests/conftest.py +10 -0
  24. wbcore/contrib/color/tests/test_color_models.py +61 -0
  25. wbcore/contrib/color/tests/test_fields.py +25 -0
  26. wbcore/contrib/currency/fixtures/currency.yaml +1014 -0
  27. wbcore/contrib/currency/fixtures/currency_fx_rate.yaml +73585 -0
  28. wbcore/contrib/directory/fixtures/directory.json +3924 -0
  29. wbcore/contrib/directory/locale/de/LC_MESSAGES/django.po +1686 -0
  30. wbcore/contrib/directory/static/directory/markdown/documentation/address.md +38 -0
  31. wbcore/contrib/directory/static/directory/markdown/documentation/banking.md +54 -0
  32. wbcore/contrib/directory/static/directory/markdown/documentation/bankingentry.md +38 -0
  33. wbcore/contrib/directory/static/directory/markdown/documentation/clientmanagerrelationship.md +42 -0
  34. wbcore/contrib/directory/static/directory/markdown/documentation/company.md +52 -0
  35. wbcore/contrib/directory/static/directory/markdown/documentation/companytype.md +2 -0
  36. wbcore/contrib/directory/static/directory/markdown/documentation/customerstatus.md +2 -0
  37. wbcore/contrib/directory/static/directory/markdown/documentation/email.md +20 -0
  38. wbcore/contrib/directory/static/directory/markdown/documentation/employeecompany.md +34 -0
  39. wbcore/contrib/directory/static/directory/markdown/documentation/employerperson.md +43 -0
  40. wbcore/contrib/directory/static/directory/markdown/documentation/person.md +61 -0
  41. wbcore/contrib/directory/static/directory/markdown/documentation/position.md +2 -0
  42. wbcore/contrib/directory/static/directory/markdown/documentation/relationshiptype.md +2 -0
  43. wbcore/contrib/directory/static/directory/markdown/documentation/socialmedia.md +23 -0
  44. wbcore/contrib/directory/static/directory/markdown/documentation/specialization.md +2 -0
  45. wbcore/contrib/directory/static/directory/markdown/documentation/systememployee.md +31 -0
  46. wbcore/contrib/directory/static/directory/markdown/documentation/telephone.md +23 -0
  47. wbcore/contrib/directory/static/directory/markdown/documentation/telephonesearch.md +26 -0
  48. wbcore/contrib/directory/static/directory/markdown/documentation/userisclient.md +14 -0
  49. wbcore/contrib/directory/static/directory/markdown/documentation/userismanager.md +28 -0
  50. wbcore/contrib/directory/static/directory/markdown/documentation/website.md +20 -0
  51. wbcore/contrib/documents/fixtures/docments.json +135 -0
  52. wbcore/contrib/documents/locale/de/LC_MESSAGES/django.po +272 -0
  53. wbcore/contrib/documents/static/documents/markdown/documentation/document_types.md +21 -0
  54. wbcore/contrib/documents/static/documents/markdown/documentation/documents.md +18 -0
  55. wbcore/contrib/documents/static/documents/markdown/documentation/shareablelink.md +28 -0
  56. wbcore/contrib/documents/static/documents/markdown/documentation/shareablelinkaccess.md +20 -0
  57. wbcore/contrib/documents/tests/conftest.py +30 -0
  58. wbcore/contrib/documents/tests/test_models.py +144 -0
  59. wbcore/contrib/example_app/fixtures/example_app.json +7425 -0
  60. wbcore/contrib/example_app/tests/test_models/test_event.py +87 -0
  61. wbcore/contrib/example_app/tests/test_models/test_match.py +210 -0
  62. wbcore/contrib/example_app/tests/test_models/test_others.py +159 -0
  63. wbcore/contrib/example_app/tests/test_serializers/test_league_serializer.py +34 -0
  64. wbcore/contrib/example_app/tests/test_serializers/test_match_serializer.py +134 -0
  65. wbcore/contrib/example_app/tests/test_serializers/test_role_serializer.py +13 -0
  66. wbcore/contrib/example_app/tests/test_serializers/test_sport_serializer.py +14 -0
  67. wbcore/contrib/example_app/tests/test_serializers/test_stadium_serializer.py +14 -0
  68. wbcore/contrib/example_app/tests/test_serializers/test_team_result_serializer.py +30 -0
  69. wbcore/contrib/example_app/tests/test_serializers/test_team_serializer.py +70 -0
  70. wbcore/contrib/example_app/tests/test_viewsets/test_event_viewset.py +162 -0
  71. wbcore/contrib/example_app/tests/test_viewsets/test_league_viewset.py +84 -0
  72. wbcore/contrib/example_app/tests/test_viewsets/test_match_viewset.py +65 -0
  73. wbcore/contrib/example_app/tests/test_viewsets/test_person_viewset.py +166 -0
  74. wbcore/contrib/example_app/tests/test_viewsets/test_role_viewset.py +75 -0
  75. wbcore/contrib/example_app/tests/test_viewsets/test_sport_viewset.py +75 -0
  76. wbcore/contrib/example_app/tests/test_viewsets/test_stadium_viewset.py +75 -0
  77. wbcore/contrib/example_app/tests/test_viewsets/test_team_viewset.py +92 -0
  78. wbcore/contrib/example_app/tests/test_viewsets/test_teamresult_viewset.py +58 -0
  79. wbcore/contrib/example_app/tests/test_viewsets/test_utils_viewsets.py +124 -0
  80. wbcore/contrib/geography/fixtures/geography.json +13454 -0
  81. wbcore/contrib/geography/static/geography/markdown/documentation/geography.md +16 -0
  82. wbcore/contrib/guardian/apps.py +6 -0
  83. wbcore/contrib/guardian/configurations.py +3 -0
  84. wbcore/contrib/guardian/filters.py +21 -0
  85. wbcore/contrib/guardian/tasks.py +10 -0
  86. wbcore/contrib/guardian/urls.py +12 -0
  87. wbcore/contrib/guardian/utils.py +124 -0
  88. wbcore/contrib/io/fixtures/io.json +145 -0
  89. wbcore/contrib/io/locale/de/LC_MESSAGES/django.po +52 -0
  90. wbcore/contrib/notifications/locale/de/LC_MESSAGES/django.po +60 -0
  91. wbcore/contrib/notifications/static/notifications/service-worker.js +1 -0
  92. wbcore/contrib/notifications/templates/notifications/notification_template.html +43 -0
  93. wbcore/contrib/notifications/viewsets/configs/notification_types.py +27 -0
  94. wbcore/contrib/notifications/viewsets/configs/notifications.py +85 -0
  95. wbcore/contrib/workflow/fixtures/workflow.json +612 -0
  96. wbcore/contrib/workflow/locale/de/LC_MESSAGES/django.po +1289 -0
  97. wbcore/contrib/workflow/static/workflow/markdown/documentation/assignedprocessstep.md +33 -0
  98. wbcore/contrib/workflow/static/workflow/markdown/documentation/condition.md +24 -0
  99. wbcore/contrib/workflow/static/workflow/markdown/documentation/decisionstep.md +30 -0
  100. wbcore/contrib/workflow/static/workflow/markdown/documentation/emailstep.md +45 -0
  101. wbcore/contrib/workflow/static/workflow/markdown/documentation/finishstep.md +33 -0
  102. wbcore/contrib/workflow/static/workflow/markdown/documentation/joinstep.md +33 -0
  103. wbcore/contrib/workflow/static/workflow/markdown/documentation/process.md +33 -0
  104. wbcore/contrib/workflow/static/workflow/markdown/documentation/processstep.md +51 -0
  105. wbcore/contrib/workflow/static/workflow/markdown/documentation/scriptstep.md +33 -0
  106. wbcore/contrib/workflow/static/workflow/markdown/documentation/splitstep.md +30 -0
  107. wbcore/contrib/workflow/static/workflow/markdown/documentation/startstep.md +27 -0
  108. wbcore/contrib/workflow/static/workflow/markdown/documentation/transition.md +27 -0
  109. wbcore/contrib/workflow/static/workflow/markdown/documentation/userstep.md +42 -0
  110. wbcore/contrib/workflow/static/workflow/markdown/documentation/workflow.md +32 -0
  111. wbcore/contrib/workflow/templates/Test_Templates.txt +25 -0
  112. wbcore/contrib/workflow/tests/test_models/step/test_decision_step.py +79 -0
  113. wbcore/contrib/workflow/tests/test_models/step/test_email_step.py +45 -0
  114. wbcore/contrib/workflow/tests/test_models/step/test_finish_step.py +105 -0
  115. wbcore/contrib/workflow/tests/test_models/step/test_join_step.py +127 -0
  116. wbcore/contrib/workflow/tests/test_models/step/test_script_step.py +24 -0
  117. wbcore/contrib/workflow/tests/test_models/step/test_split_step.py +49 -0
  118. wbcore/contrib/workflow/tests/test_models/step/test_step.py +621 -0
  119. wbcore/contrib/workflow/tests/test_models/step/test_user_step.py +225 -0
  120. wbcore/contrib/workflow/tests/test_models/test_condition.py +103 -0
  121. wbcore/contrib/workflow/tests/test_models/test_data.py +134 -0
  122. wbcore/contrib/workflow/tests/test_models/test_process.py +98 -0
  123. wbcore/contrib/workflow/tests/test_models/test_transition.py +128 -0
  124. wbcore/contrib/workflow/tests/test_models/test_workflow.py +358 -0
  125. wbcore/locale/de/LC_MESSAGES/django.po +667 -0
  126. wbcore/templates/errors/404.html +134 -0
  127. wbcore/templates/errors/500.html +138 -0
  128. wbcore/templates/errors/503.html +132 -0
  129. wbcore/templates/errors/custom.html +132 -0
  130. wbcore/templates/forms.py +0 -0
  131. wbcore/templates/notifications/email_template.html +43 -0
  132. wbcore/templates/wbcore/admin/change_list.html +8 -0
  133. wbcore/templates/wbcore/admin/csv_form.html +15 -0
  134. wbcore/templates/wbcore/dynamic_color_array.html +29 -0
  135. wbcore/templates/wbcore/email_base_template.html +335 -0
  136. wbcore/templates/wbcore/email_notification_template.html +10 -0
  137. wbcore/templates/wbcore/frontend.html +51 -0
  138. wbcore/test/e2e_helpers_methods/e2e_checks.py +121 -0
  139. wbcore/test/e2e_helpers_methods/e2e_helper_methods.py +395 -0
  140. wbcore/tests/test_permissions/test_backend.py +29 -0
  141. {wbcore-2.2.1.dist-info → wbcore-2.2.4.dist-info}/METADATA +1 -1
  142. {wbcore-2.2.1.dist-info → wbcore-2.2.4.dist-info}/RECORD +143 -3
  143. {wbcore-2.2.1.dist-info → wbcore-2.2.4.dist-info}/WHEEL +0 -0
@@ -0,0 +1,87 @@
1
+ import pytest
2
+ from django.db import IntegrityError
3
+ from wbcore.contrib.example_app.factories import (
4
+ EventFactory,
5
+ EventTypeFactory,
6
+ PlayerFactory,
7
+ )
8
+
9
+
10
+ @pytest.mark.django_db
11
+ class TestEvent:
12
+ def test_str(self):
13
+ event = EventFactory(
14
+ minute=69,
15
+ person__first_name="Test",
16
+ person__last_name="Person",
17
+ event_type__name="Test Event Type",
18
+ match__sport__match_duration=90,
19
+ )
20
+ assert event.__str__() == "Test Event Type (69.) - Test Person"
21
+
22
+ @pytest.mark.parametrize(
23
+ "home, away, points, home_score, away_score", [(2, 1, 5, 7, 1), (0, 3, 2, 2, 3), (1, 1, 0, 1, 1)]
24
+ )
25
+ def test_save_home_scored(self, home, away, points, home_score, away_score):
26
+ person = PlayerFactory()
27
+ event = EventFactory(
28
+ person=person,
29
+ match__home=person.current_team,
30
+ match__score_home=home,
31
+ match__score_away=away,
32
+ event_type__points=points,
33
+ )
34
+ assert event.match.score_home == home_score
35
+ assert event.match.score_away == away_score
36
+
37
+ @pytest.mark.parametrize(
38
+ "home, away, points, home_score, away_score", [(41, 27, 4, 41, 31), (19, 0, 2, 19, 2), (22, 23, 0, 22, 23)]
39
+ )
40
+ def test_save_away_scored(self, home, away, points, home_score, away_score):
41
+ person = PlayerFactory()
42
+ event = EventFactory(
43
+ person=person,
44
+ match__away=person.current_team,
45
+ match__score_home=home,
46
+ match__score_away=away,
47
+ event_type__points=points,
48
+ )
49
+ assert event.match.score_home == home_score
50
+ assert event.match.score_away == away_score
51
+
52
+ def test_save_no_team(self):
53
+ person = PlayerFactory()
54
+ event = EventFactory(
55
+ person=person,
56
+ match__score_home=2,
57
+ match__score_away=1,
58
+ event_type__points=4,
59
+ )
60
+ assert event.match.score_home == 2
61
+ assert event.match.score_away == 1
62
+
63
+ def test_save_no_player(self):
64
+ event = EventFactory(
65
+ match__score_home=2,
66
+ match__score_away=1,
67
+ event_type__points=4,
68
+ )
69
+ assert event.match.score_home == 2
70
+ assert event.match.score_away == 1
71
+
72
+ def test_unique_constraint(self):
73
+ event = EventFactory()
74
+ with pytest.raises(IntegrityError):
75
+ EventFactory(person=event.person, minute=event.minute, event_type=event.event_type, match=event.match)
76
+
77
+
78
+ @pytest.mark.django_db
79
+ class TestEventType:
80
+ def test_str(self):
81
+ event_type = EventTypeFactory(name="Test Event Type")
82
+ assert event_type.__str__() == "Test Event Type"
83
+
84
+ def test_unique_constraint(self):
85
+ event_type = EventTypeFactory()
86
+ with pytest.raises(IntegrityError):
87
+ EventTypeFactory(name=event_type.name, sport=event_type.sport)
@@ -0,0 +1,210 @@
1
+ from datetime import datetime
2
+ from unittest.mock import patch
3
+
4
+ import pytest
5
+ import pytz
6
+ from django.db import IntegrityError
7
+ from django.db.models import Q
8
+ from faker import Faker
9
+ from wbcore.contrib.authentication.factories import SuperUserFactory, UserFactory
10
+ from wbcore.contrib.directory.models import Person
11
+ from wbcore.contrib.example_app.factories import (
12
+ LeagueFactory,
13
+ MatchFactory,
14
+ TeamFactory,
15
+ )
16
+ from wbcore.contrib.example_app.models import (
17
+ Match,
18
+ SportPerson,
19
+ TeamResults,
20
+ start_match,
21
+ )
22
+
23
+
24
+ @pytest.mark.django_db
25
+ class TestMatch:
26
+ def test_has_permissions_superuser(self):
27
+ user = SuperUserFactory()
28
+ match = MatchFactory()
29
+ assert match.has_permissions(user) is True
30
+
31
+ def test_has_permissions_custom_perm(self):
32
+ match = MatchFactory()
33
+ user = UserFactory(user_permissions=["wbcore.change_match_status"])
34
+ assert match.has_permissions(user) is True
35
+
36
+ def test_str(self):
37
+ match = MatchFactory(home__name="Home Team", away__name="Away Team")
38
+ assert match.__str__() == "Home Team vs. Away Team"
39
+
40
+ @patch("wbcore.contrib.example_app.models.start_match.apply_async")
41
+ @patch("wbcore.contrib.example_app.models.current_app.control.revoke")
42
+ def test_reschedule_existing_task(self, mock_revoke, mock_start):
43
+ user = UserFactory()
44
+ # we just need an object with a .id method
45
+ mock_start.return_value = user
46
+ match = MatchFactory()
47
+ old_task_id = match.task_id
48
+ match.reschedule_task()
49
+ assert mock_revoke.call_args.args == (old_task_id,)
50
+ assert mock_revoke.call_args.kwargs == {"terminate": True}
51
+ assert mock_start.call_args.kwargs == {"eta": match.date_time, "args": [match.pk]}
52
+ assert match.task_id == user.pk
53
+
54
+ @patch("wbcore.contrib.example_app.models.start_match.apply_async")
55
+ @patch("wbcore.contrib.example_app.models.current_app.control.revoke")
56
+ def test_reschedule_new_task(self, mock_revoke, mock_start):
57
+ user = UserFactory()
58
+ # we just need an object with a .id method
59
+ mock_start.return_value = user
60
+ match = MatchFactory()
61
+ match.task_id = None
62
+ match.reschedule_task()
63
+ assert mock_revoke.call_count == 1
64
+ assert mock_start.call_args.kwargs == {"eta": match.date_time, "args": [match.pk]}
65
+ assert match.task_id == user.pk
66
+
67
+ def test_save_calendar_item(self):
68
+ match = MatchFactory(league__sport__match_duration=120, date_time=datetime(2023, 5, 20, 19, 15))
69
+
70
+ home_sport_persons = SportPerson.objects.filter(
71
+ Q(id__in=match.home.current_players.all()) | Q(coached_team=match.home)
72
+ )
73
+ away_sport_persons = SportPerson.objects.filter(
74
+ Q(id__in=match.away.current_players.all()) | Q(coached_team=match.away)
75
+ )
76
+ referee = SportPerson.objects.filter(id=match.referee.id)
77
+ match_persons = home_sport_persons.union(away_sport_persons, referee)
78
+
79
+ persons = Person.objects.filter(id__in=match_persons.values_list("profile", flat=True))
80
+ entities_id_list = list(persons.values_list("pk", flat=True))
81
+ entities_id_list.extend([match.home.id, match.away.id])
82
+
83
+ assert match.period.upper == datetime(2023, 5, 20, 21, 15)
84
+ assert set(match.entities.values_list("id", flat=True)) == set(entities_id_list)
85
+
86
+ @patch("wbcore.contrib.example_app.models.Match.reschedule_task")
87
+ def test_save_trigger_rescheduling(self, mock_reschedule):
88
+ match = MatchFactory()
89
+ match.date_time = Faker().date_time(tzinfo=pytz.utc)
90
+ match.save()
91
+ assert mock_reschedule.call_count == 2
92
+
93
+ @patch("wbcore.contrib.example_app.models.Match.reschedule_task")
94
+ def test_save_no_rescheduling(self, mock_reschedule):
95
+ match = MatchFactory()
96
+ match.title = "Test"
97
+ match.save()
98
+ assert mock_reschedule.call_count == 1
99
+
100
+ def test_save_update_teamresults(self):
101
+ league = LeagueFactory(points_per_win=5, points_per_draw=2, points_per_loss=1)
102
+ home_team = TeamFactory()
103
+ away_team = TeamFactory()
104
+
105
+ # Home win
106
+ match1 = MatchFactory(
107
+ home=home_team,
108
+ away=away_team,
109
+ status=Match.MatchStatus.FINISHED,
110
+ score_home=3,
111
+ score_away=1,
112
+ league=league,
113
+ )
114
+ assert set(TeamResults.objects.values_list("team__name", flat=True)) == {home_team.name, away_team.name}
115
+ home_results = TeamResults.objects.get(team=home_team)
116
+ away_results = TeamResults.objects.get(team=away_team)
117
+ assert home_results.wins == 1
118
+ assert home_results.draws == 0
119
+ assert home_results.losses == 0
120
+ assert home_results.form == "----W"
121
+ assert home_results.points == 5
122
+ assert home_results.match_points_for == 3
123
+ assert home_results.match_points_against == 1
124
+ assert away_results.wins == 0
125
+ assert away_results.draws == 0
126
+ assert away_results.losses == 1
127
+ assert away_results.form == "----L"
128
+ assert away_results.points == 1
129
+ assert away_results.match_points_for == 1
130
+ assert away_results.match_points_against == 3
131
+ assert match1.task_id == ""
132
+
133
+ # Home Loss
134
+ match2 = MatchFactory(
135
+ home=home_team,
136
+ away=away_team,
137
+ status=Match.MatchStatus.FINISHED,
138
+ score_home=21,
139
+ score_away=37,
140
+ league=league,
141
+ )
142
+ home_results = TeamResults.objects.get(team=home_team)
143
+ away_results = TeamResults.objects.get(team=away_team)
144
+ assert home_results.wins == 1
145
+ assert home_results.draws == 0
146
+ assert home_results.losses == 1
147
+ assert home_results.form == "---WL"
148
+ assert home_results.points == 6
149
+ assert home_results.match_points_for == 24
150
+ assert home_results.match_points_against == 38
151
+ assert away_results.wins == 1
152
+ assert away_results.draws == 0
153
+ assert away_results.losses == 1
154
+ assert away_results.form == "---LW"
155
+ assert away_results.points == 6
156
+ assert away_results.match_points_for == 38
157
+ assert away_results.match_points_against == 24
158
+ assert match2.task_id == ""
159
+
160
+ # Draw
161
+ match3 = MatchFactory(
162
+ home=home_team,
163
+ away=away_team,
164
+ status=Match.MatchStatus.FINISHED,
165
+ score_home=2,
166
+ score_away=2,
167
+ league=league,
168
+ )
169
+ home_results = TeamResults.objects.get(team=home_team)
170
+ away_results = TeamResults.objects.get(team=away_team)
171
+ assert home_results.wins == 1
172
+ assert home_results.draws == 1
173
+ assert home_results.losses == 1
174
+ assert home_results.form == "--WLD"
175
+ assert home_results.points == 8
176
+ assert home_results.match_points_for == 26
177
+ assert home_results.match_points_against == 40
178
+ assert away_results.wins == 1
179
+ assert away_results.draws == 1
180
+ assert away_results.losses == 1
181
+ assert away_results.form == "--LWD"
182
+ assert away_results.points == 8
183
+ assert away_results.match_points_for == 40
184
+ assert away_results.match_points_against == 26
185
+ assert match3.task_id == ""
186
+
187
+ @patch("wbcore.contrib.example_app.models.Match.reschedule_task")
188
+ def test_save_no_task_id(self, mock_reschedule):
189
+ MatchFactory(status=Match.MatchStatus.FINISHED, score_home=3, score_away=1, task_id="")
190
+ assert not TeamResults.objects.exists()
191
+
192
+ def test_unique_constraint(self):
193
+ match = MatchFactory()
194
+ with pytest.raises(IntegrityError):
195
+ MatchFactory(home=match.home, away=match.away, date_time=match.date_time)
196
+
197
+ def test_check_constraint(self):
198
+ team = TeamFactory()
199
+ with pytest.raises(IntegrityError):
200
+ MatchFactory(home=team, away=team)
201
+
202
+ def test_start_match_scheduled(self):
203
+ match = MatchFactory(status=Match.MatchStatus.SCHEDULED)
204
+ start_match(match.pk)
205
+ assert Match.objects.get(id=match.pk).status == Match.MatchStatus.ONGOING
206
+
207
+ def test_start_match_finished(self):
208
+ match = MatchFactory(status=Match.MatchStatus.FINISHED)
209
+ start_match(match.pk)
210
+ assert Match.objects.get(id=match.pk).status != Match.MatchStatus.ONGOING
@@ -0,0 +1,159 @@
1
+ import pytest
2
+ from django.db import IntegrityError
3
+ from wbcore.contrib.example_app.factories import (
4
+ LeagueFactory,
5
+ MatchFactory,
6
+ PlayerFactory,
7
+ RoleFactory,
8
+ SportFactory,
9
+ SportPersonFactory,
10
+ StadiumFactory,
11
+ TeamFactory,
12
+ TeamResultsFactory,
13
+ )
14
+ from wbcore.contrib.example_app.models import League, Match, Player, SportPerson
15
+
16
+
17
+ @pytest.mark.django_db
18
+ class TestPerson:
19
+ def test_str_full(self):
20
+ person = SportPersonFactory(first_name="Test", last_name="Name")
21
+ assert person.str_full() == "Test Name"
22
+
23
+ def test_str_full_coach(self):
24
+ person = SportPersonFactory(first_name="Test", last_name="Name")
25
+ TeamFactory(coach=person, name="Test Team")
26
+ assert person.str_full() == "Test Name (Coach of Test Team)"
27
+
28
+ def test_str_full_commissioner(self):
29
+ commissioner = SportPersonFactory(first_name="Test", last_name="Name")
30
+ LeagueFactory(commissioner=commissioner, name="Test League")
31
+ assert commissioner.str_full() == "Test Name (Commissioner of Test League)"
32
+
33
+ def test_get_player_fail(self):
34
+ person = SportPersonFactory()
35
+ assert person.get_player() is None
36
+
37
+ def test_get_player_sucess(self):
38
+ player = PlayerFactory()
39
+ person = SportPerson.objects.get(id=player.pk)
40
+ assert person.get_player() == player
41
+
42
+
43
+ @pytest.mark.django_db
44
+ class TestPlayer:
45
+ def test_str_full(self):
46
+ player = PlayerFactory(first_name="Test", last_name="Name", current_team=None)
47
+ assert player.str_full() == "Test Name"
48
+
49
+ def test_str_full_team(self):
50
+ player = PlayerFactory(current_team__name="Test Team", position=None, first_name="Test", last_name="Name")
51
+ assert player.str_full() == "Test Name (Test Team)"
52
+
53
+ def test_str_full_team_position(self):
54
+ player = PlayerFactory(
55
+ current_team__name="Test Team", position="Test Position", first_name="Test", last_name="Name"
56
+ )
57
+ assert player.str_full() == "Test Name (Test Position at Test Team)"
58
+
59
+
60
+ @pytest.mark.django_db
61
+ class TestRole:
62
+ def test_str(self):
63
+ role = RoleFactory(title="Test Role")
64
+ assert role.__str__() == "Test Role"
65
+
66
+
67
+ @pytest.mark.django_db
68
+ class TestSport:
69
+ def test_str(self):
70
+ sport = SportFactory(name="Test Sport")
71
+ assert sport.__str__() == "Test Sport"
72
+
73
+ def test_post_save(self):
74
+ sport = SportFactory()
75
+ league1 = LeagueFactory(sport=sport)
76
+ old_name = sport.name
77
+ new_name = "New Sport Name"
78
+ sport.name = new_name
79
+ sport.save()
80
+ new_computed_str = League.objects.get(id=league1.pk).computed_str
81
+ assert old_name not in new_computed_str
82
+ assert new_name in new_computed_str
83
+
84
+
85
+ @pytest.mark.django_db
86
+ class TestLeague:
87
+ def test_str(self):
88
+ league = LeagueFactory(name="Test League", sport__name="Test Sport")
89
+ assert league.__str__() == "Test League (Test Sport)"
90
+
91
+ def test_unique_constraint(self):
92
+ league = LeagueFactory()
93
+ with pytest.raises(IntegrityError):
94
+ LeagueFactory(name=league.name, sport=league.sport)
95
+
96
+ def test_post_save(self):
97
+ commissioner = SportPersonFactory()
98
+ league = LeagueFactory(commissioner=commissioner)
99
+ old_name = league.name
100
+ new_name = "New League Name"
101
+ league.name = new_name
102
+ league.save()
103
+ new_computed_str = SportPerson.objects.get(id=commissioner.pk).computed_str
104
+ assert old_name not in new_computed_str
105
+ assert new_name in new_computed_str
106
+
107
+
108
+ @pytest.mark.django_db
109
+ class TestTeamResults:
110
+ def test_str(self):
111
+ team_results = TeamResultsFactory(team__name="Test Team", league__name="Test League")
112
+ assert team_results.__str__() == "Test Team in Test League"
113
+
114
+ @pytest.mark.parametrize("points_for, points_against, difference", [(33, 91, -58), (252, 171, 81), (86, 86, 0)])
115
+ def test_save(self, points_for, points_against, difference):
116
+ team_results = TeamResultsFactory(match_points_for=points_for, match_points_against=points_against)
117
+ assert team_results.match_point_difference == difference
118
+
119
+ def test_unique_constraint(self):
120
+ team_results = TeamResultsFactory()
121
+ with pytest.raises(IntegrityError):
122
+ TeamResultsFactory(team=team_results.team, league=team_results.league)
123
+
124
+
125
+ @pytest.mark.django_db
126
+ class TestStadium:
127
+ def test_str(self):
128
+ stadium = StadiumFactory(name="Test Stadium")
129
+ assert stadium.__str__() == "Test Stadium"
130
+
131
+
132
+ @pytest.mark.django_db
133
+ class TestTeam:
134
+ def test_str(self):
135
+ team = TeamFactory(name="Test Team")
136
+ assert team.__str__() == "Test Team"
137
+
138
+ def test_post_save(self):
139
+ team = TeamFactory()
140
+ old_name = team.name
141
+ player1 = PlayerFactory(current_team=team)
142
+ player2 = PlayerFactory(current_team=team)
143
+ player3 = PlayerFactory(current_team=team)
144
+ match1 = MatchFactory(home=team)
145
+ match2 = MatchFactory(away=team)
146
+ new_name = "New Team Name"
147
+ team.name = new_name
148
+ team.save()
149
+ for match in [match1, match2]:
150
+ match_new_computed_str = Match.objects.get(id=match.pk).computed_str
151
+ assert old_name not in match_new_computed_str
152
+ assert new_name in match_new_computed_str
153
+ for player in [player1, player2, player3]:
154
+ player_new_computed_str = Player.objects.get(id=player.pk).computed_str
155
+ assert old_name not in player_new_computed_str
156
+ assert new_name in player_new_computed_str
157
+ coach_new_computed_str = SportPerson.objects.get(id=team.coach.pk).computed_str
158
+ assert old_name not in coach_new_computed_str
159
+ assert new_name in coach_new_computed_str
@@ -0,0 +1,34 @@
1
+ from datetime import date, datetime, timedelta
2
+
3
+ import pytest
4
+ from django.forms.models import model_to_dict
5
+ from rest_framework.exceptions import ValidationError
6
+ from rest_framework.test import APITestCase
7
+ from wbcore.contrib.example_app.factories import LeagueFactory, SportFactory
8
+ from wbcore.contrib.example_app.serializers import LeagueModelSerializer
9
+
10
+
11
+ @pytest.mark.django_db
12
+ class TestLeagueModelSerializer(APITestCase):
13
+ def test_league_serializer(self):
14
+ sport = SportFactory()
15
+ league_data: dict = model_to_dict(LeagueFactory.build(sport=sport))
16
+ league_serializer = LeagueModelSerializer(data=league_data)
17
+
18
+ self.assertTrue(league_serializer.is_valid())
19
+
20
+ def test_league_exists(self):
21
+ sport = SportFactory()
22
+ league = LeagueFactory(sport=sport)
23
+ new_league_data: dict = model_to_dict(LeagueFactory.build(sport=sport, name=league.name))
24
+
25
+ with pytest.raises(ValidationError):
26
+ LeagueModelSerializer(data=new_league_data).is_valid(raise_exception=True)
27
+
28
+ def test_league_wrong_date(self):
29
+ sport = SportFactory()
30
+ future_date: date = (datetime.now() + timedelta(days=1)).date()
31
+ league_data: dict = model_to_dict(LeagueFactory.build(sport=sport, established_date=future_date))
32
+
33
+ with pytest.raises(ValidationError):
34
+ LeagueModelSerializer(data=league_data).is_valid(raise_exception=True)
@@ -0,0 +1,134 @@
1
+ import pytest
2
+ from django.forms.models import model_to_dict
3
+ from rest_framework.exceptions import ValidationError
4
+ from rest_framework.test import APITestCase
5
+ from wbcore.contrib.example_app.factories import (
6
+ EventFactory,
7
+ EventTypeFactory,
8
+ LeagueFactory,
9
+ MatchFactory,
10
+ SportFactory,
11
+ SportPersonFactory,
12
+ StadiumFactory,
13
+ TeamFactory,
14
+ )
15
+ from wbcore.contrib.example_app.serializers import (
16
+ EventErrorMessages,
17
+ EventModelSerializer,
18
+ EventTypeModelSerializer,
19
+ LeaguePlayerStatisticsModelSerializer,
20
+ LeagueTeamStatisticsModelSerializer,
21
+ MatchErrorMessages,
22
+ MatchModelSerializer,
23
+ )
24
+
25
+
26
+ @pytest.mark.django_db
27
+ class TestMatchModelSerializer(APITestCase):
28
+ def test_match_serializer(self):
29
+ match_data: dict = model_to_dict(
30
+ MatchFactory.build(away=TeamFactory(), home=TeamFactory(), sport=SportFactory(), stadium=StadiumFactory())
31
+ )
32
+ match_serializer = MatchModelSerializer(data=match_data)
33
+ self.assertTrue(match_serializer.is_valid())
34
+
35
+ def test_match_same_teams(self):
36
+ team = TeamFactory()
37
+ match_data: dict = model_to_dict(
38
+ MatchFactory.build(away=team, home=team, sport=SportFactory(), stadium=StadiumFactory())
39
+ )
40
+ with self.assertRaisesMessage(ValidationError, MatchErrorMessages.same_teams.value):
41
+ league_serializer = MatchModelSerializer(data=match_data)
42
+ self.assertFalse(league_serializer.is_valid(raise_exception=True))
43
+
44
+ def test_match_same_date(self):
45
+ match = MatchFactory()
46
+ match_data: dict = model_to_dict(match)
47
+ with pytest.raises(ValidationError):
48
+ MatchModelSerializer(data=match_data).is_valid(raise_exception=True)
49
+
50
+ def test_match_wrong_sport(self):
51
+ match_data: dict = model_to_dict(
52
+ MatchFactory.build(
53
+ away=TeamFactory(),
54
+ home=TeamFactory(),
55
+ stadium=StadiumFactory(),
56
+ sport=SportFactory(),
57
+ league=LeagueFactory(),
58
+ )
59
+ )
60
+ with self.assertRaisesMessage(ValidationError, MatchErrorMessages.wrong_sport.value):
61
+ league_serializer = MatchModelSerializer(data=match_data)
62
+ self.assertFalse(league_serializer.is_valid(raise_exception=True))
63
+
64
+
65
+ @pytest.mark.django_db
66
+ class TestEventTypeModelSerializer(APITestCase):
67
+ def test_event_type_serializer(self):
68
+ event_type_data: dict = model_to_dict(EventTypeFactory.build(sport=SportFactory()))
69
+ event_type_serializer = EventTypeModelSerializer(data=event_type_data)
70
+ self.assertTrue(event_type_serializer.is_valid())
71
+
72
+ def test_event_type_same_name(self):
73
+ event_type = EventTypeFactory()
74
+ event_type_data: dict = model_to_dict(EventTypeFactory.build(name=event_type.name, sport=event_type.sport))
75
+ with pytest.raises(ValidationError):
76
+ EventTypeModelSerializer(data=event_type_data).is_valid(raise_exception=True)
77
+
78
+
79
+ @pytest.mark.django_db
80
+ class TestEventModelSerializer(APITestCase):
81
+ def test_event_serializer(self):
82
+ match = MatchFactory()
83
+ event_type = EventTypeFactory(sport=match.sport)
84
+ event_data: dict = model_to_dict(
85
+ EventFactory.build(person=SportPersonFactory(), event_type=event_type, match=match)
86
+ )
87
+ event_serializer = EventModelSerializer(data=event_data)
88
+ self.assertTrue(event_serializer.is_valid())
89
+
90
+ def test_event_wrong_duration(self):
91
+ sport = SportFactory(match_duration=60)
92
+ event_type = EventTypeFactory(sport=sport)
93
+ match = MatchFactory(sport=sport)
94
+ event: dict = model_to_dict(
95
+ EventFactory.build(person=SportPersonFactory(), minute=61, event_type=event_type, match=match)
96
+ )
97
+ with self.assertRaisesMessage(ValidationError, EventErrorMessages.wrong_duration.value):
98
+ event_serializer = EventModelSerializer(data=event)
99
+ self.assertFalse(event_serializer.is_valid(raise_exception=True))
100
+
101
+ def test_event_duplication(self):
102
+ event = EventFactory()
103
+ event_data = model_to_dict(event)
104
+
105
+ with pytest.raises(ValidationError):
106
+ EventModelSerializer(data=event_data).is_valid(raise_exception=True)
107
+
108
+ def test_event_wrong_type(self):
109
+ event_type = EventTypeFactory()
110
+ match = MatchFactory()
111
+ event_data: dict = model_to_dict(
112
+ EventFactory.build(person=SportPersonFactory(), event_type=event_type, match=match)
113
+ )
114
+ with self.assertRaisesMessage(
115
+ ValidationError, EventErrorMessages.wrong_event_type.value.format(match.sport.name)
116
+ ):
117
+ event_serializer = EventModelSerializer(data=event_data)
118
+ self.assertFalse(event_serializer.is_valid(raise_exception=True))
119
+
120
+
121
+ @pytest.mark.django_db
122
+ class TestLeaguePlayerStatisticsModelSerializer(APITestCase):
123
+ def test_league_player_statistics_serializer(self):
124
+ statistic_data = {"person_id": 1, "person_name": "Foo", "count": 1, "id": "id"}
125
+ statistic_serializer = LeaguePlayerStatisticsModelSerializer(data=statistic_data)
126
+ self.assertTrue(statistic_serializer.is_valid())
127
+
128
+
129
+ @pytest.mark.django_db
130
+ class TestLeagueTeamStatisticsModelSerializer(APITestCase):
131
+ def test_league_player_statistics_serializer(self):
132
+ statistic_data = {"team_id": 1, "team_name": "Foo", "count": 1, "id": "id"}
133
+ statistic_serializer = LeagueTeamStatisticsModelSerializer(data=statistic_data)
134
+ self.assertTrue(statistic_serializer.is_valid())
@@ -0,0 +1,13 @@
1
+ import pytest
2
+ from django.forms.models import model_to_dict
3
+ from rest_framework.test import APITestCase
4
+ from wbcore.contrib.example_app.factories import RoleFactory
5
+ from wbcore.contrib.example_app.serializers import RoleModelSerializer
6
+
7
+
8
+ @pytest.mark.django_db
9
+ class TestRoleModelSerializer(APITestCase):
10
+ def test_role_serializer(self):
11
+ role_data: dict = model_to_dict(RoleFactory.build())
12
+ role_serializer = RoleModelSerializer(data=role_data)
13
+ self.assertTrue(role_serializer.is_valid())
@@ -0,0 +1,14 @@
1
+ import pytest
2
+ from django.forms.models import model_to_dict
3
+ from rest_framework.test import APITestCase
4
+ from wbcore.contrib.example_app.factories import SportFactory
5
+ from wbcore.contrib.example_app.serializers import SportModelSerializer
6
+
7
+
8
+ @pytest.mark.django_db
9
+ class TestSportModelSerializer(APITestCase):
10
+ def test_sport_serializer(self):
11
+ sport_data: dict = model_to_dict(SportFactory.build())
12
+ sport_serializer = SportModelSerializer(data=sport_data)
13
+
14
+ self.assertTrue(sport_serializer.is_valid())
@@ -0,0 +1,14 @@
1
+ import pytest
2
+ from django.forms.models import model_to_dict
3
+ from rest_framework.test import APITestCase
4
+ from wbcore.contrib.example_app.factories import StadiumFactory
5
+ from wbcore.contrib.example_app.serializers import StadiumModelSerializer
6
+
7
+
8
+ @pytest.mark.django_db
9
+ class TestStadiumModelSerializer(APITestCase):
10
+ def test_stadium_serializer(self):
11
+ stadium_data: dict = model_to_dict(StadiumFactory.build())
12
+ stadium_serializer = StadiumModelSerializer(data=stadium_data)
13
+
14
+ self.assertTrue(stadium_serializer.is_valid())