wbcore 1.59.5rc0__py2.py3-none-any.whl → 1.59.6__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/cache/registry.py +1 -1
- wbcore/configs/__init__.py +0 -1
- wbcore/configs/configs.py +0 -5
- wbcore/configurations/configurations/wbcore.py +0 -2
- wbcore/contrib/agenda/factories/calendar_item.py +1 -0
- wbcore/contrib/authentication/factories/users.py +1 -0
- wbcore/contrib/directory/factories/entries.py +1 -0
- wbcore/contrib/directory/migrations/0014_alter_entry_relationship_managers_and_more.py +28 -0
- wbcore/contrib/example_app/factories/person.py +1 -0
- wbcore/contrib/example_app/factories/team.py +1 -0
- wbcore/contrib/example_app/models.py +7 -6
- wbcore/contrib/example_app/tests/e2e/test_league.py +2 -2
- wbcore/contrib/example_app/tests/e2e/test_person.py +1 -1
- wbcore/contrib/example_app/tests/e2e/test_teams.py +1 -1
- wbcore/contrib/example_app/tests/test_filters.py +13 -13
- wbcore/contrib/example_app/tests/test_models/test_event.py +15 -13
- wbcore/contrib/example_app/tests/test_models/test_match.py +23 -23
- wbcore/contrib/example_app/tests/test_models/test_others.py +20 -18
- wbcore/contrib/example_app/tests/test_serializers/test_league_serializer.py +4 -4
- wbcore/contrib/example_app/tests/test_serializers/test_match_serializer.py +9 -4
- wbcore/contrib/example_app/tests/test_serializers/test_team_result_serializer.py +3 -3
- wbcore/contrib/example_app/tests/test_serializers/test_team_serializer.py +10 -10
- wbcore/contrib/example_app/tests/test_utils.py +8 -8
- wbcore/contrib/example_app/tests/test_viewsets/test_event_viewset.py +167 -162
- wbcore/contrib/example_app/tests/test_viewsets/test_league_viewset.py +9 -9
- wbcore/contrib/example_app/tests/test_viewsets/test_match_viewset.py +8 -8
- wbcore/contrib/example_app/tests/test_viewsets/test_person_viewset.py +16 -16
- wbcore/contrib/example_app/tests/test_viewsets/test_role_viewset.py +9 -9
- wbcore/contrib/example_app/tests/test_viewsets/test_sport_viewset.py +9 -9
- wbcore/contrib/example_app/tests/test_viewsets/test_stadium_viewset.py +9 -9
- wbcore/contrib/example_app/tests/test_viewsets/test_team_viewset.py +12 -12
- wbcore/contrib/example_app/tests/test_viewsets/test_teamresult_viewset.py +6 -6
- wbcore/contrib/geography/migrations/0002_geography_geography_geography_tree_i739a.py +17 -0
- wbcore/contrib/guardian/tests/test_utils.py +1 -1
- wbcore/contrib/guardian/utils.py +1 -1
- wbcore/contrib/icons/icons.py +2 -2
- wbcore/contrib/io/factories.py +2 -0
- wbcore/contrib/io/models.py +3 -3
- wbcore/contrib/io/viewsets.py +2 -2
- wbcore/contrib/pandas/fields.py +8 -0
- wbcore/contrib/tags/factories.py +1 -0
- wbcore/contrib/workflow/factories/step.py +1 -0
- wbcore/contrib/workflow/models/step.py +1 -1
- wbcore/docs/__init__.py +0 -2
- wbcore/filters/mixins.py +2 -2
- wbcore/markdown/views.py +0 -17
- wbcore/metadata/configs/buttons/__init__.py +1 -1
- wbcore/metadata/configs/buttons/bases.py +1 -6
- wbcore/metadata/configs/buttons/buttons.py +1 -7
- wbcore/metadata/configs/buttons/enums.py +0 -7
- wbcore/metadata/tests/test_buttons.py +1 -13
- wbcore/pandas/__init__.py +1 -0
- wbcore/pandas/fields.py +1 -0
- wbcore/serializers/fields/fields.py +4 -2
- wbcore/serializers/fields/types.py +1 -0
- wbcore/test/tests.py +1 -1
- wbcore/tests/test_configs.py +0 -5
- wbcore/urls.py +0 -2
- wbcore/utils/figures.py +4 -8
- {wbcore-1.59.5rc0.dist-info → wbcore-1.59.6.dist-info}/METADATA +26 -27
- {wbcore-1.59.5rc0.dist-info → wbcore-1.59.6.dist-info}/RECORD +62 -60
- {wbcore-1.59.5rc0.dist-info → wbcore-1.59.6.dist-info}/WHEEL +0 -0
wbcore/cache/registry.py
CHANGED
|
@@ -14,7 +14,7 @@ from wbcore.contrib.authentication.models import User
|
|
|
14
14
|
from wbcore.filters.defaults import RequiredFilterMissing
|
|
15
15
|
|
|
16
16
|
if typing.TYPE_CHECKING:
|
|
17
|
-
from wbcore.pandas.views import PandasAPIViewSet
|
|
17
|
+
from wbcore.contrib.pandas.views import PandasAPIViewSet
|
|
18
18
|
from wbcore.viewsets import ChartViewSet
|
|
19
19
|
|
|
20
20
|
|
wbcore/configs/__init__.py
CHANGED
wbcore/configs/configs.py
CHANGED
|
@@ -25,11 +25,6 @@ def share_config(request: Request):
|
|
|
25
25
|
return "share", share_action_button(request=request).serialize(request)
|
|
26
26
|
|
|
27
27
|
|
|
28
|
-
@register_config
|
|
29
|
-
def markdown_config(request: Request) -> tuple[str, dict[str, str]]:
|
|
30
|
-
return "markdown", {"blockdiag": reverse("wbcore:blockdiag", request=request)}
|
|
31
|
-
|
|
32
|
-
|
|
33
28
|
@register_config
|
|
34
29
|
def menu_calendar_config(request: Request) -> tuple[str, str | None]:
|
|
35
30
|
menu_calendar = None
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
from configurations import values
|
|
2
2
|
from django.utils.translation import gettext_lazy as _
|
|
3
3
|
from markdown.extensions.tables import TableExtension
|
|
4
|
-
from markdown_blockdiag.extension import BlockdiagExtension
|
|
5
4
|
|
|
6
5
|
from wbcore.fsm.markdown_extensions import FSMExtension
|
|
7
6
|
|
|
@@ -25,7 +24,6 @@ class WBCore:
|
|
|
25
24
|
WBCORE_MARKDOWN_EXTENSIONS = [
|
|
26
25
|
TableExtension(),
|
|
27
26
|
FSMExtension(),
|
|
28
|
-
BlockdiagExtension(format="svg"),
|
|
29
27
|
]
|
|
30
28
|
|
|
31
29
|
WBCORE_NOTIFICATION_TEMPLATE = values.Value("notifications/email_template.html", environ_prefix=None)
|
|
@@ -14,6 +14,7 @@ class UserFactory(factory.django.DjangoModelFactory):
|
|
|
14
14
|
class Meta:
|
|
15
15
|
model = User
|
|
16
16
|
django_get_or_create = ["email"]
|
|
17
|
+
skip_postgeneration_save = True
|
|
17
18
|
|
|
18
19
|
email = factory.Sequence(lambda n: "email%d@admin.com" % n)
|
|
19
20
|
# username = factory.Faker('user_name')
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Generated by Django 5.2.9 on 2025-12-09 08:50
|
|
2
|
+
|
|
3
|
+
from django.db import migrations, models
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Migration(migrations.Migration):
|
|
7
|
+
|
|
8
|
+
dependencies = [
|
|
9
|
+
('directory', '0013_alter_clientmanagerrelationship_options'),
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
operations = [
|
|
13
|
+
migrations.AlterField(
|
|
14
|
+
model_name='entry',
|
|
15
|
+
name='relationship_managers',
|
|
16
|
+
field=models.ManyToManyField(blank=True, help_text='People in charge of this entry', related_name='clients', through='directory.ClientManagerRelationship', through_fields=('client', 'relationship_manager'), to='directory.person', verbose_name='Relationship Managers'),
|
|
17
|
+
),
|
|
18
|
+
migrations.AlterField(
|
|
19
|
+
model_name='entry',
|
|
20
|
+
name='relationships',
|
|
21
|
+
field=models.ManyToManyField(blank=True, through='directory.Relationship', through_fields=('from_entry', 'to_entry'), to='directory.entry', verbose_name="The Entry's Relationships"),
|
|
22
|
+
),
|
|
23
|
+
migrations.AlterField(
|
|
24
|
+
model_name='person',
|
|
25
|
+
name='employers',
|
|
26
|
+
field=models.ManyToManyField(blank=True, help_text="The person's employers", related_name='employees', through='directory.EmployerEmployeeRelationship', through_fields=('employee', 'employer'), to='directory.company', verbose_name='Employers'),
|
|
27
|
+
),
|
|
28
|
+
]
|
|
@@ -6,6 +6,7 @@ from wbcore.contrib.example_app.models import Player, SportPerson
|
|
|
6
6
|
class SportPersonFactory(factory.django.DjangoModelFactory):
|
|
7
7
|
class Meta:
|
|
8
8
|
model = SportPerson
|
|
9
|
+
skip_postgeneration_save = True
|
|
9
10
|
|
|
10
11
|
profile = factory.SubFactory("wbcore.contrib.directory.factories.PersonFactory")
|
|
11
12
|
profile_image = factory.django.ImageField(filename="image_profile.jpeg")
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
import datetime
|
|
4
|
+
from contextlib import suppress
|
|
4
5
|
from decimal import Decimal
|
|
5
6
|
from pathlib import Path
|
|
6
7
|
|
|
@@ -588,7 +589,7 @@ class Match(ComplexToStringMixin, CalendarItem):
|
|
|
588
589
|
verbose_name_plural = _("Matches")
|
|
589
590
|
constraints = [
|
|
590
591
|
models.UniqueConstraint(fields=["home", "away", "date_time"], name="match_home_away_date_time"),
|
|
591
|
-
models.CheckConstraint(
|
|
592
|
+
models.CheckConstraint(condition=~models.Q(home=models.F("away")), name="check_match_home_away"),
|
|
592
593
|
]
|
|
593
594
|
permissions = [("change_match_status", "Change Match Status")]
|
|
594
595
|
|
|
@@ -600,11 +601,11 @@ def start_match(match_id: int):
|
|
|
600
601
|
Args:
|
|
601
602
|
match_id (int): ID of the match in question
|
|
602
603
|
"""
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
604
|
+
with suppress(Match.DoesNotExist):
|
|
605
|
+
match = Match.objects.get(pk=match_id)
|
|
606
|
+
if match.status == Match.MatchStatus.SCHEDULED:
|
|
607
|
+
match.status = Match.MatchStatus.ONGOING
|
|
608
|
+
match.save()
|
|
608
609
|
|
|
609
610
|
|
|
610
611
|
@receiver(models.signals.post_save, sender=Match)
|
|
@@ -28,12 +28,12 @@ USER_PASSWORD = "User_Password"
|
|
|
28
28
|
class TestLeague:
|
|
29
29
|
def test_create_edit_delete_league(self, live_server, selenium):
|
|
30
30
|
# Creating a test user and login to the WB
|
|
31
|
-
user: User = SuperUserFactory(plaintext_password=USER_PASSWORD)
|
|
31
|
+
user: User = SuperUserFactory.create(plaintext_password=USER_PASSWORD)
|
|
32
32
|
actions = ActionChains(selenium, 1000)
|
|
33
33
|
set_up(selenium, live_server, user.email, USER_PASSWORD)
|
|
34
34
|
|
|
35
35
|
# -----> CREATE A NEW LEAGUE <----- #
|
|
36
|
-
sport = SportFactory()
|
|
36
|
+
sport = SportFactory.create()
|
|
37
37
|
league_a = create_new_league_instance(
|
|
38
38
|
selenium, ["name", "sport", "established_date", "points_per_win"], sport, False
|
|
39
39
|
)
|
|
@@ -26,7 +26,7 @@ USER_PASSWORD = "User_Password"
|
|
|
26
26
|
class TestPerson:
|
|
27
27
|
def test_create_edit_delete_person(self, live_server, selenium):
|
|
28
28
|
# Creating a test user and login to the WB
|
|
29
|
-
user: User = SuperUserFactory(plaintext_password=USER_PASSWORD)
|
|
29
|
+
user: User = SuperUserFactory.create(plaintext_password=USER_PASSWORD)
|
|
30
30
|
actions = ActionChains(selenium, 1000)
|
|
31
31
|
set_up(selenium, live_server, user.email, USER_PASSWORD)
|
|
32
32
|
|
|
@@ -25,7 +25,7 @@ USER_PASSWORD = "User_Password"
|
|
|
25
25
|
class TestTeam:
|
|
26
26
|
def test_create_edit_delete_team(self, live_server, selenium):
|
|
27
27
|
# Creating a test user and login to the WB
|
|
28
|
-
user: User = SuperUserFactory(plaintext_password=USER_PASSWORD) # noqa
|
|
28
|
+
user: User = SuperUserFactory.create(plaintext_password=USER_PASSWORD) # noqa
|
|
29
29
|
actions = ActionChains(selenium, 1000)
|
|
30
30
|
set_up(selenium, live_server, user.email, USER_PASSWORD)
|
|
31
31
|
|
|
@@ -25,7 +25,7 @@ from wbcore.test.utils import get_or_create_superuser
|
|
|
25
25
|
class TestEvent:
|
|
26
26
|
@patch("wbcore.contrib.example_app.models.Match.reschedule_task")
|
|
27
27
|
def test_filter_by_period(self, mock_reschedule):
|
|
28
|
-
event = EventFactory(match__date_time=timezone.now())
|
|
28
|
+
event = EventFactory.create(match__date_time=timezone.now())
|
|
29
29
|
before_event = DateRange((timezone.now() - timedelta(7)).date(), (timezone.now() - timedelta(1)).date())
|
|
30
30
|
after_event = DateRange((timezone.now() + timedelta(1)).date(), (timezone.now() + timedelta(7)).date())
|
|
31
31
|
mvs = PlayerStatisticsChartModelViewSet(kwargs={"player_id": event.person})
|
|
@@ -44,22 +44,22 @@ class TestEvent:
|
|
|
44
44
|
class TestPerson:
|
|
45
45
|
@patch("wbcore.contrib.example_app.models.Match.reschedule_task")
|
|
46
46
|
def test_filter_by_match(self, mock_reschedule):
|
|
47
|
-
ref1 = SportPersonFactory()
|
|
48
|
-
match1 = MatchFactory(referee=ref1, home__coach=None, away__coach=None)
|
|
49
|
-
ref2 = SportPersonFactory()
|
|
50
|
-
home_coach = SportPersonFactory()
|
|
51
|
-
away_coach = SportPersonFactory()
|
|
52
|
-
home_team = TeamFactory(coach=home_coach)
|
|
53
|
-
away_team = TeamFactory(coach=away_coach)
|
|
54
|
-
home_player = PlayerFactory(current_team=home_team)
|
|
55
|
-
away_player = PlayerFactory(current_team=away_team)
|
|
56
|
-
match2 = MatchFactory(
|
|
47
|
+
ref1 = SportPersonFactory.create()
|
|
48
|
+
match1 = MatchFactory.create(referee=ref1, home__coach=None, away__coach=None)
|
|
49
|
+
ref2 = SportPersonFactory.create()
|
|
50
|
+
home_coach = SportPersonFactory.create()
|
|
51
|
+
away_coach = SportPersonFactory.create()
|
|
52
|
+
home_team = TeamFactory.create(coach=home_coach)
|
|
53
|
+
away_team = TeamFactory.create(coach=away_coach)
|
|
54
|
+
home_player = PlayerFactory.create(current_team=home_team)
|
|
55
|
+
away_player = PlayerFactory.create(current_team=away_team)
|
|
56
|
+
match2 = MatchFactory.create(
|
|
57
57
|
home=home_team,
|
|
58
58
|
away=away_team,
|
|
59
59
|
referee=ref2,
|
|
60
60
|
)
|
|
61
|
-
SportPersonFactory()
|
|
62
|
-
PlayerFactory()
|
|
61
|
+
SportPersonFactory.create()
|
|
62
|
+
PlayerFactory.create()
|
|
63
63
|
mvs = SportPersonRepresentationViewSet()
|
|
64
64
|
request = APIRequestFactory().get("")
|
|
65
65
|
request.user = get_or_create_superuser()
|
|
@@ -10,7 +10,7 @@ from wbcore.contrib.example_app.factories import (
|
|
|
10
10
|
@pytest.mark.django_db
|
|
11
11
|
class TestEvent:
|
|
12
12
|
def test_str(self):
|
|
13
|
-
event = EventFactory(
|
|
13
|
+
event = EventFactory.create(
|
|
14
14
|
minute=69,
|
|
15
15
|
person__first_name="Test",
|
|
16
16
|
person__last_name="Person",
|
|
@@ -23,8 +23,8 @@ class TestEvent:
|
|
|
23
23
|
"home, away, points, home_score, away_score", [(2, 1, 5, 7, 1), (0, 3, 2, 2, 3), (1, 1, 0, 1, 1)]
|
|
24
24
|
)
|
|
25
25
|
def test_save_home_scored(self, home, away, points, home_score, away_score):
|
|
26
|
-
person = PlayerFactory()
|
|
27
|
-
event = EventFactory(
|
|
26
|
+
person = PlayerFactory.create()
|
|
27
|
+
event = EventFactory.create(
|
|
28
28
|
person=person,
|
|
29
29
|
match__home=person.current_team,
|
|
30
30
|
match__score_home=home,
|
|
@@ -38,8 +38,8 @@ class TestEvent:
|
|
|
38
38
|
"home, away, points, home_score, away_score", [(41, 27, 4, 41, 31), (19, 0, 2, 19, 2), (22, 23, 0, 22, 23)]
|
|
39
39
|
)
|
|
40
40
|
def test_save_away_scored(self, home, away, points, home_score, away_score):
|
|
41
|
-
person = PlayerFactory()
|
|
42
|
-
event = EventFactory(
|
|
41
|
+
person = PlayerFactory.create()
|
|
42
|
+
event = EventFactory.create(
|
|
43
43
|
person=person,
|
|
44
44
|
match__away=person.current_team,
|
|
45
45
|
match__score_home=home,
|
|
@@ -50,8 +50,8 @@ class TestEvent:
|
|
|
50
50
|
assert event.match.score_away == away_score
|
|
51
51
|
|
|
52
52
|
def test_save_no_team(self):
|
|
53
|
-
person = PlayerFactory()
|
|
54
|
-
event = EventFactory(
|
|
53
|
+
person = PlayerFactory.create()
|
|
54
|
+
event = EventFactory.create(
|
|
55
55
|
person=person,
|
|
56
56
|
match__score_home=2,
|
|
57
57
|
match__score_away=1,
|
|
@@ -61,7 +61,7 @@ class TestEvent:
|
|
|
61
61
|
assert event.match.score_away == 1
|
|
62
62
|
|
|
63
63
|
def test_save_no_player(self):
|
|
64
|
-
event = EventFactory(
|
|
64
|
+
event = EventFactory.create(
|
|
65
65
|
match__score_home=2,
|
|
66
66
|
match__score_away=1,
|
|
67
67
|
event_type__points=4,
|
|
@@ -70,18 +70,20 @@ class TestEvent:
|
|
|
70
70
|
assert event.match.score_away == 1
|
|
71
71
|
|
|
72
72
|
def test_unique_constraint(self):
|
|
73
|
-
event = EventFactory()
|
|
73
|
+
event = EventFactory.create()
|
|
74
74
|
with pytest.raises(IntegrityError):
|
|
75
|
-
EventFactory(
|
|
75
|
+
EventFactory.create(
|
|
76
|
+
person=event.person, minute=event.minute, event_type=event.event_type, match=event.match
|
|
77
|
+
)
|
|
76
78
|
|
|
77
79
|
|
|
78
80
|
@pytest.mark.django_db
|
|
79
81
|
class TestEventType:
|
|
80
82
|
def test_str(self):
|
|
81
|
-
event_type = EventTypeFactory(name="Test Event Type")
|
|
83
|
+
event_type = EventTypeFactory.create(name="Test Event Type")
|
|
82
84
|
assert event_type.__str__() == "Test Event Type"
|
|
83
85
|
|
|
84
86
|
def test_unique_constraint(self):
|
|
85
|
-
event_type = EventTypeFactory()
|
|
87
|
+
event_type = EventTypeFactory.create()
|
|
86
88
|
with pytest.raises(IntegrityError):
|
|
87
|
-
EventTypeFactory(name=event_type.name, sport=event_type.sport)
|
|
89
|
+
EventTypeFactory.create(name=event_type.name, sport=event_type.sport)
|
|
@@ -24,27 +24,27 @@ from wbcore.contrib.example_app.models import (
|
|
|
24
24
|
@pytest.mark.django_db
|
|
25
25
|
class TestMatch:
|
|
26
26
|
def test_has_permissions_superuser(self):
|
|
27
|
-
user = SuperUserFactory()
|
|
28
|
-
match = MatchFactory()
|
|
27
|
+
user = SuperUserFactory.create()
|
|
28
|
+
match = MatchFactory.create()
|
|
29
29
|
assert match.has_permissions(user) is True
|
|
30
30
|
|
|
31
31
|
# TODO This tests need some fixing
|
|
32
32
|
# def test_has_permissions_custom_perm(self):
|
|
33
|
-
# match = MatchFactory()
|
|
34
|
-
# user = UserFactory(user_permissions=["wbcore.change_match_status"])
|
|
33
|
+
# match = MatchFactory.create()
|
|
34
|
+
# user = UserFactory.create(user_permissions=["wbcore.change_match_status"])
|
|
35
35
|
# assert match.has_permissions(user) is True
|
|
36
36
|
|
|
37
37
|
def test_str(self):
|
|
38
|
-
match = MatchFactory(home__name="Home Team", away__name="Away Team")
|
|
38
|
+
match = MatchFactory.create(home__name="Home Team", away__name="Away Team")
|
|
39
39
|
assert match.__str__() == "Home Team vs. Away Team"
|
|
40
40
|
|
|
41
41
|
@patch("wbcore.contrib.example_app.models.start_match.apply_async")
|
|
42
42
|
@patch("wbcore.contrib.example_app.models.current_app.control.revoke")
|
|
43
43
|
def test_reschedule_existing_task(self, mock_revoke, mock_start):
|
|
44
|
-
user = UserFactory()
|
|
44
|
+
user = UserFactory.create()
|
|
45
45
|
# we just need an object with a .id method
|
|
46
46
|
mock_start.return_value = user
|
|
47
|
-
match = MatchFactory()
|
|
47
|
+
match = MatchFactory.create()
|
|
48
48
|
old_task_id = match.task_id
|
|
49
49
|
match.reschedule_task()
|
|
50
50
|
assert mock_revoke.call_args.args == (old_task_id,)
|
|
@@ -58,10 +58,10 @@ class TestMatch:
|
|
|
58
58
|
@patch("wbcore.contrib.example_app.models.start_match.apply_async")
|
|
59
59
|
@patch("wbcore.contrib.example_app.models.current_app.control.revoke")
|
|
60
60
|
def test_reschedule_new_task(self, mock_revoke, mock_start):
|
|
61
|
-
user = UserFactory()
|
|
61
|
+
user = UserFactory.create()
|
|
62
62
|
# we just need an object with a .id method
|
|
63
63
|
mock_start.return_value = user
|
|
64
|
-
match = MatchFactory()
|
|
64
|
+
match = MatchFactory.create()
|
|
65
65
|
match.task_id = None
|
|
66
66
|
match.reschedule_task()
|
|
67
67
|
assert mock_revoke.call_count == 1
|
|
@@ -72,7 +72,7 @@ class TestMatch:
|
|
|
72
72
|
assert match.task_id == user.pk
|
|
73
73
|
|
|
74
74
|
def test_save_calendar_item(self):
|
|
75
|
-
match = MatchFactory(league__sport__match_duration=120, date_time=datetime(2023, 5, 20, 19, 15))
|
|
75
|
+
match = MatchFactory.create(league__sport__match_duration=120, date_time=datetime(2023, 5, 20, 19, 15))
|
|
76
76
|
|
|
77
77
|
home_sport_persons = SportPerson.objects.filter(
|
|
78
78
|
Q(id__in=match.home.current_players.all()) | Q(coached_team=match.home)
|
|
@@ -92,25 +92,25 @@ class TestMatch:
|
|
|
92
92
|
|
|
93
93
|
@patch("wbcore.contrib.example_app.models.Match.reschedule_task")
|
|
94
94
|
def test_save_trigger_rescheduling(self, mock_reschedule):
|
|
95
|
-
match = MatchFactory()
|
|
95
|
+
match = MatchFactory.create()
|
|
96
96
|
match.date_time = Faker().date_time(tzinfo=pytz.utc)
|
|
97
97
|
match.save()
|
|
98
98
|
assert mock_reschedule.call_count == 2
|
|
99
99
|
|
|
100
100
|
@patch("wbcore.contrib.example_app.models.Match.reschedule_task")
|
|
101
101
|
def test_save_no_rescheduling(self, mock_reschedule):
|
|
102
|
-
match = MatchFactory()
|
|
102
|
+
match = MatchFactory.create()
|
|
103
103
|
match.title = "Test"
|
|
104
104
|
match.save()
|
|
105
105
|
assert mock_reschedule.call_count == 1
|
|
106
106
|
|
|
107
107
|
def test_save_update_teamresults(self):
|
|
108
|
-
league = LeagueFactory(points_per_win=5, points_per_draw=2, points_per_loss=1)
|
|
109
|
-
home_team = TeamFactory()
|
|
110
|
-
away_team = TeamFactory()
|
|
108
|
+
league = LeagueFactory.create(points_per_win=5, points_per_draw=2, points_per_loss=1)
|
|
109
|
+
home_team = TeamFactory.create()
|
|
110
|
+
away_team = TeamFactory.create()
|
|
111
111
|
|
|
112
112
|
# Home win
|
|
113
|
-
match1 = MatchFactory(
|
|
113
|
+
match1 = MatchFactory.create(
|
|
114
114
|
home=home_team,
|
|
115
115
|
away=away_team,
|
|
116
116
|
status=Match.MatchStatus.FINISHED,
|
|
@@ -141,7 +141,7 @@ class TestMatch:
|
|
|
141
141
|
assert match1.task_id == ""
|
|
142
142
|
|
|
143
143
|
# Home Loss
|
|
144
|
-
match2 = MatchFactory(
|
|
144
|
+
match2 = MatchFactory.create(
|
|
145
145
|
home=home_team,
|
|
146
146
|
away=away_team,
|
|
147
147
|
status=Match.MatchStatus.FINISHED,
|
|
@@ -168,7 +168,7 @@ class TestMatch:
|
|
|
168
168
|
assert match2.task_id == ""
|
|
169
169
|
|
|
170
170
|
# Draw
|
|
171
|
-
match3 = MatchFactory(
|
|
171
|
+
match3 = MatchFactory.create(
|
|
172
172
|
home=home_team,
|
|
173
173
|
away=away_team,
|
|
174
174
|
status=Match.MatchStatus.FINISHED,
|
|
@@ -196,18 +196,18 @@ class TestMatch:
|
|
|
196
196
|
|
|
197
197
|
@patch("wbcore.contrib.example_app.models.Match.reschedule_task")
|
|
198
198
|
def test_save_no_task_id(self, mock_reschedule):
|
|
199
|
-
MatchFactory(status=Match.MatchStatus.FINISHED, score_home=3, score_away=1, task_id="")
|
|
199
|
+
MatchFactory.create(status=Match.MatchStatus.FINISHED, score_home=3, score_away=1, task_id="")
|
|
200
200
|
assert not TeamResults.objects.exists()
|
|
201
201
|
|
|
202
202
|
def test_unique_constraint(self):
|
|
203
|
-
match = MatchFactory()
|
|
203
|
+
match = MatchFactory.create()
|
|
204
204
|
with pytest.raises(IntegrityError):
|
|
205
|
-
MatchFactory(home=match.home, away=match.away, date_time=match.date_time)
|
|
205
|
+
MatchFactory.create(home=match.home, away=match.away, date_time=match.date_time)
|
|
206
206
|
|
|
207
207
|
def test_check_constraint(self):
|
|
208
|
-
team = TeamFactory()
|
|
208
|
+
team = TeamFactory.create()
|
|
209
209
|
with pytest.raises(IntegrityError):
|
|
210
|
-
MatchFactory(home=team, away=team)
|
|
210
|
+
MatchFactory.create(home=team, away=team)
|
|
211
211
|
|
|
212
212
|
def test_start_match_scheduled(self):
|
|
213
213
|
match = MatchFactory(status=Match.MatchStatus.SCHEDULED)
|
|
@@ -17,25 +17,25 @@ from wbcore.contrib.example_app.models import League, Match, Player, SportPerson
|
|
|
17
17
|
@pytest.mark.django_db
|
|
18
18
|
class TestPerson:
|
|
19
19
|
def test_str_full(self):
|
|
20
|
-
person = SportPersonFactory(first_name="Test", last_name="Name")
|
|
20
|
+
person = SportPersonFactory.create(first_name="Test", last_name="Name")
|
|
21
21
|
assert person.str_full() == "Test Name"
|
|
22
22
|
|
|
23
23
|
def test_str_full_coach(self):
|
|
24
|
-
person = SportPersonFactory(first_name="Test", last_name="Name")
|
|
25
|
-
TeamFactory(coach=person, name="Test Team")
|
|
24
|
+
person = SportPersonFactory.create(first_name="Test", last_name="Name")
|
|
25
|
+
TeamFactory.create(coach=person, name="Test Team")
|
|
26
26
|
assert person.str_full() == "Test Name (Coach of Test Team)"
|
|
27
27
|
|
|
28
28
|
def test_str_full_commissioner(self):
|
|
29
|
-
commissioner = SportPersonFactory(first_name="Test", last_name="Name")
|
|
30
|
-
LeagueFactory(commissioner=commissioner, name="Test League")
|
|
29
|
+
commissioner = SportPersonFactory.create(first_name="Test", last_name="Name")
|
|
30
|
+
LeagueFactory.create(commissioner=commissioner, name="Test League")
|
|
31
31
|
assert commissioner.str_full() == "Test Name (Commissioner of Test League)"
|
|
32
32
|
|
|
33
33
|
def test_get_player_fail(self):
|
|
34
|
-
person = SportPersonFactory()
|
|
34
|
+
person = SportPersonFactory.create()
|
|
35
35
|
assert person.get_player() is None
|
|
36
36
|
|
|
37
37
|
def test_get_player_sucess(self):
|
|
38
|
-
player = PlayerFactory()
|
|
38
|
+
player = PlayerFactory.create()
|
|
39
39
|
person = SportPerson.objects.get(id=player.pk)
|
|
40
40
|
assert person.get_player() == player
|
|
41
41
|
|
|
@@ -43,15 +43,17 @@ class TestPerson:
|
|
|
43
43
|
@pytest.mark.django_db
|
|
44
44
|
class TestPlayer:
|
|
45
45
|
def test_str_full(self):
|
|
46
|
-
player = PlayerFactory(first_name="Test", last_name="Name", current_team=None)
|
|
46
|
+
player = PlayerFactory.create(first_name="Test", last_name="Name", current_team=None)
|
|
47
47
|
assert player.str_full() == "Test Name"
|
|
48
48
|
|
|
49
49
|
def test_str_full_team(self):
|
|
50
|
-
player = PlayerFactory(
|
|
50
|
+
player = PlayerFactory.create(
|
|
51
|
+
current_team__name="Test Team", position=None, first_name="Test", last_name="Name"
|
|
52
|
+
)
|
|
51
53
|
assert player.str_full() == "Test Name (Test Team)"
|
|
52
54
|
|
|
53
55
|
def test_str_full_team_position(self):
|
|
54
|
-
player = PlayerFactory(
|
|
56
|
+
player = PlayerFactory.create(
|
|
55
57
|
current_team__name="Test Team", position="Test Position", first_name="Test", last_name="Name"
|
|
56
58
|
)
|
|
57
59
|
assert player.str_full() == "Test Name (Test Position at Test Team)"
|
|
@@ -60,19 +62,19 @@ class TestPlayer:
|
|
|
60
62
|
@pytest.mark.django_db
|
|
61
63
|
class TestRole:
|
|
62
64
|
def test_str(self):
|
|
63
|
-
role = RoleFactory(title="Test Role")
|
|
65
|
+
role = RoleFactory.create(title="Test Role")
|
|
64
66
|
assert role.__str__() == "Test Role"
|
|
65
67
|
|
|
66
68
|
|
|
67
69
|
@pytest.mark.django_db
|
|
68
70
|
class TestSport:
|
|
69
71
|
def test_str(self):
|
|
70
|
-
sport = SportFactory(name="Test Sport")
|
|
72
|
+
sport = SportFactory.create(name="Test Sport")
|
|
71
73
|
assert sport.__str__() == "Test Sport"
|
|
72
74
|
|
|
73
75
|
def test_post_save(self):
|
|
74
|
-
sport = SportFactory()
|
|
75
|
-
league1 = LeagueFactory(sport=sport)
|
|
76
|
+
sport = SportFactory.create()
|
|
77
|
+
league1 = LeagueFactory.create(sport=sport)
|
|
76
78
|
old_name = sport.name
|
|
77
79
|
new_name = "New Sport Name"
|
|
78
80
|
sport.name = new_name
|
|
@@ -89,12 +91,12 @@ class TestLeague:
|
|
|
89
91
|
assert league.__str__() == "Test League (Test Sport)"
|
|
90
92
|
|
|
91
93
|
def test_unique_constraint(self):
|
|
92
|
-
league = LeagueFactory()
|
|
94
|
+
league = LeagueFactory.create()
|
|
93
95
|
with pytest.raises(IntegrityError):
|
|
94
96
|
LeagueFactory(name=league.name, sport=league.sport)
|
|
95
97
|
|
|
96
98
|
def test_post_save(self):
|
|
97
|
-
commissioner = SportPersonFactory()
|
|
99
|
+
commissioner = SportPersonFactory.create()
|
|
98
100
|
league = LeagueFactory(commissioner=commissioner)
|
|
99
101
|
old_name = league.name
|
|
100
102
|
new_name = "New League Name"
|
|
@@ -117,7 +119,7 @@ class TestTeamResults:
|
|
|
117
119
|
assert team_results.match_point_difference == difference
|
|
118
120
|
|
|
119
121
|
def test_unique_constraint(self):
|
|
120
|
-
team_results = TeamResultsFactory()
|
|
122
|
+
team_results = TeamResultsFactory.create()
|
|
121
123
|
with pytest.raises(IntegrityError):
|
|
122
124
|
TeamResultsFactory(team=team_results.team, league=team_results.league)
|
|
123
125
|
|
|
@@ -136,7 +138,7 @@ class TestTeam:
|
|
|
136
138
|
assert team.__str__() == "Test Team"
|
|
137
139
|
|
|
138
140
|
def test_post_save(self):
|
|
139
|
-
team = TeamFactory()
|
|
141
|
+
team = TeamFactory.create()
|
|
140
142
|
old_name = team.name
|
|
141
143
|
player1 = PlayerFactory(current_team=team)
|
|
142
144
|
player2 = PlayerFactory(current_team=team)
|
|
@@ -11,22 +11,22 @@ from wbcore.contrib.example_app.serializers import LeagueModelSerializer
|
|
|
11
11
|
@pytest.mark.django_db
|
|
12
12
|
class TestLeagueModelSerializer(APITestCase):
|
|
13
13
|
def test_league_serializer(self):
|
|
14
|
-
sport = SportFactory()
|
|
14
|
+
sport = SportFactory.create()
|
|
15
15
|
league_data: dict = model_to_dict(LeagueFactory.build(sport=sport))
|
|
16
16
|
league_serializer = LeagueModelSerializer(data=league_data)
|
|
17
17
|
|
|
18
18
|
self.assertTrue(league_serializer.is_valid())
|
|
19
19
|
|
|
20
20
|
def test_league_exists(self):
|
|
21
|
-
sport = SportFactory()
|
|
22
|
-
league = LeagueFactory(sport=sport)
|
|
21
|
+
sport = SportFactory.create()
|
|
22
|
+
league = LeagueFactory.create(sport=sport)
|
|
23
23
|
new_league_data: dict = model_to_dict(LeagueFactory.build(sport=sport, name=league.name))
|
|
24
24
|
|
|
25
25
|
with pytest.raises(ValidationError):
|
|
26
26
|
LeagueModelSerializer(data=new_league_data).is_valid(raise_exception=True)
|
|
27
27
|
|
|
28
28
|
def test_league_wrong_date(self):
|
|
29
|
-
sport = SportFactory()
|
|
29
|
+
sport = SportFactory.create()
|
|
30
30
|
future_date: date = (datetime.now() + timedelta(days=1)).date()
|
|
31
31
|
league_data: dict = model_to_dict(LeagueFactory.build(sport=sport, established_date=future_date))
|
|
32
32
|
|
|
@@ -27,15 +27,20 @@ from wbcore.contrib.example_app.serializers import (
|
|
|
27
27
|
class TestMatchModelSerializer(APITestCase):
|
|
28
28
|
def test_match_serializer(self):
|
|
29
29
|
match_data: dict = model_to_dict(
|
|
30
|
-
MatchFactory.build(
|
|
30
|
+
MatchFactory.build(
|
|
31
|
+
away=TeamFactory.create(),
|
|
32
|
+
home=TeamFactory.create(),
|
|
33
|
+
sport=SportFactory.create(),
|
|
34
|
+
stadium=StadiumFactory.create(),
|
|
35
|
+
)
|
|
31
36
|
)
|
|
32
37
|
match_serializer = MatchModelSerializer(data=match_data)
|
|
33
38
|
self.assertTrue(match_serializer.is_valid())
|
|
34
39
|
|
|
35
40
|
def test_match_same_teams(self):
|
|
36
|
-
team = TeamFactory()
|
|
41
|
+
team = TeamFactory.create()
|
|
37
42
|
match_data: dict = model_to_dict(
|
|
38
|
-
MatchFactory.build(away=team, home=team, sport=SportFactory(), stadium=StadiumFactory())
|
|
43
|
+
MatchFactory.build(away=team, home=team, sport=SportFactory.create(), stadium=StadiumFactory.create())
|
|
39
44
|
)
|
|
40
45
|
with self.assertRaisesMessage(ValidationError, MatchErrorMessages.same_teams.value):
|
|
41
46
|
league_serializer = MatchModelSerializer(data=match_data)
|
|
@@ -99,7 +104,7 @@ class TestEventModelSerializer(APITestCase):
|
|
|
99
104
|
self.assertFalse(event_serializer.is_valid(raise_exception=True))
|
|
100
105
|
|
|
101
106
|
def test_event_duplication(self):
|
|
102
|
-
event = EventFactory()
|
|
107
|
+
event = EventFactory.create()
|
|
103
108
|
event_data = model_to_dict(event)
|
|
104
109
|
|
|
105
110
|
with pytest.raises(ValidationError):
|
|
@@ -13,8 +13,8 @@ from wbcore.contrib.example_app.serializers import TeamResultsModelSerializer
|
|
|
13
13
|
@pytest.mark.django_db
|
|
14
14
|
class TestTeamResultSerializer(APITestCase):
|
|
15
15
|
def test_result_serializer(self):
|
|
16
|
-
team = TeamFactory()
|
|
17
|
-
league = LeagueFactory()
|
|
16
|
+
team = TeamFactory.create()
|
|
17
|
+
league = LeagueFactory.create()
|
|
18
18
|
result: dict = model_to_dict(TeamResultsFactory.build(team=team, league=league))
|
|
19
19
|
result["games_played"] = 3
|
|
20
20
|
result_serializer = TeamResultsModelSerializer(data=result)
|
|
@@ -22,7 +22,7 @@ class TestTeamResultSerializer(APITestCase):
|
|
|
22
22
|
self.assertTrue(result_serializer.is_valid())
|
|
23
23
|
|
|
24
24
|
def test_same_result(self):
|
|
25
|
-
result = TeamResultsFactory()
|
|
25
|
+
result = TeamResultsFactory.create()
|
|
26
26
|
new_result: dict = model_to_dict(TeamResultsFactory.build(team=result.team, league=result.league))
|
|
27
27
|
new_result["games_played"] = 3
|
|
28
28
|
|