Passed
Push — master ( e2662a...8b3758 )
by manny
01:50
created

races_for_testing   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 51
dl 0
loc 54
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
B get_test_race() 0 47 4
1
from typing import List
2
from datetime import datetime, timedelta, timezone
3
from models.race import Race, Goal, Status, Entrant
4
from users_for_testing import get_test_user, get_test_entrant
5
from categories_for_testing import get_test_race_category
6
7
def get_test_race(status_value="in_progress", version=1, entrants_count=2, started_at=datetime.now(timezone.utc),
8
                start_delay=timedelta(seconds=-15), opened_at=datetime.now(timezone.utc), ended_at=None, 
9
                cancelled_at: datetime = None, entrant: Entrant = None, entrants: List[Entrant] = None) -> Race:
10
    if not entrants:
11
        entrants = (list(get_test_entrant() for x in range(0, entrants_count)))
12
        entrant_count_finished = 0
13
    else:
14
        entrant_count_finished = list.count((list((x.status.value == "finished" for x in entrants))), True)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable x does not seem to be defined.
Loading history...
15
    test_race= Race(name="",
16
                status=Status(value=status_value,
17
                              verbose_value="", help_text=""),
18
                category=get_test_race_category(),
19
                goal=Goal("", False),
20
                info="A test race",
21
                url="",
22
                data_url="",
23
                websocket_url="",
24
                websocket_bot_url="",
25
                websocket_oauth_url="",
26
                entrants_count=entrants_count,
27
                entrants_count_inactive=0,
28
                entrants_count_finished=entrant_count_finished,
29
                entrants=entrants,
30
                version=version,
31
                started_at=started_at,
32
                start_delay=start_delay,
33
                ended_at=ended_at,
34
                cancelled_at=cancelled_at,
35
                unlisted=False,
36
                time_limit=timedelta(days=1),
37
                streaming_required=True,
38
                auto_start=True,
39
                opened_by=get_test_user(),
40
                opened_at=opened_at,
41
                monitors=[],
42
                recordable=True,
43
                recorded=False,
44
                recorded_by=None,
45
                allow_comments=True,
46
                hide_comments=False,
47
                allow_midrace_chat=True
48
                )
49
    if entrant is not None:
50
        if not entrant in test_race.entrants:
51
            test_race.entrants.pop()
52
            test_race.entrants.append(entrant)
53
    return test_race
54