Skip to content

Commit

Permalink
Added tests for expected_duration field kiwitcms#1923
Browse files Browse the repository at this point in the history
- Test case for random durations being summed
- Test case for an empty setup_duration field OR empty testing_duration field
- Test case for both setup_duration AND testing_duration fields being empty
  • Loading branch information
gasharova authored and APiligrim committed Mar 24, 2021
1 parent 7e4e9fd commit 699802e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
29 changes: 24 additions & 5 deletions tcms/testcases/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ def test_create_testcase_with_cyrillic_works_issue_1770(self):
case.refresh_from_db()
self.assertTrue(case.summary.endswith("кирилица"))


class TestCaseRemoveComponent(BasePlanCase):
"""Test TestCase.remove_component"""

Expand Down Expand Up @@ -162,14 +161,34 @@ def test_send_mail_to_case_author(self, send_mail):
)


class TestCaseCalculateExpectedDuration(TestCase):
"""Test TestCase.expected_duration"""
@parameterized.expand(
[
(
"both_values_are_set",
timezone.datetime(2021, 3, 22),
timezone.datetime(2021, 3, 23),
timezone.timedelta(days=1),
),
("both_values_are_none", None, None, None),
("setup_duration_is_none", None, timezone.datetime(2021, 3, 23), None),
("testing_duration_is_none", timezone.datetime(2021, 3, 22), None, None),
]
)
def test_expected_duration_when(self, _name, setup_duration, testing_duration, expected):
execution = TestExecutionFactory(setup_duration=setup_duration, testing_duration=testing_duration)
self.assertEqual(execution.expected_duration, expected)


class TestActualDurationProperty(TestCase):
@parameterized.expand(
[
(
"both_values_are_set",
timezone.datetime(2021, 3, 22),
timezone.datetime(2021, 3, 23),
timezone.timedelta(days=1),
"both_values_are_set",
timezone.datetime(2021, 3, 22),
timezone.datetime(2021, 3, 23),
timezone.timedelta(days=1),
),
("both_values_are_none", None, None, None),
("start_date_is_none", None, timezone.datetime(2021, 3, 23), None),
Expand Down
4 changes: 4 additions & 0 deletions tcms/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# pylint: disable=too-few-public-methods, unused-argument

import factory
from random import randrange
from datetime import timedelta
from django.conf import settings
from django.db.models import signals
from django.utils import timezone
Expand Down Expand Up @@ -163,6 +165,8 @@ class Meta:
default_tester = factory.SubFactory(UserFactory)
reviewer = factory.SubFactory(UserFactory)
text = factory.Sequence(lambda n: "Given-When-Then %d" % n)
setup_duration = timedelta(randrange(0, 10000000))
testing_duration = timedelta(randrange(0, 10000000))

@factory.post_generation
def plan(self, create, extracted, **kwargs):
Expand Down

0 comments on commit 699802e

Please sign in to comment.