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 committed Mar 5, 2021
1 parent 1157433 commit e13bd71
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
4 changes: 2 additions & 2 deletions tcms/testcases/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ class TestCase(TCMSActionModel):
requirement = models.CharField(max_length=255, blank=True, null=True)
notes = models.TextField(blank=True, null=True)
text = models.TextField(blank=True)
setup_duration = models.DurationField(db_index=True, null=True, blank=True)
testing_duration = models.DurationField(db_index=True, null=True, blank=True)
setup_duration = models.DurationField(null=True, blank=True)
testing_duration = models.DurationField(null=True, blank=True)

@property
def expected_duration(self):
Expand Down
38 changes: 38 additions & 0 deletions tcms/testcases/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from django.test import TestCase
from django.utils.translation import gettext_lazy as _
from mock import patch
from datetime import timedelta

from tcms.core.history import history_email_for
from tcms.testcases.helpers.email import get_case_notification_recipients
Expand All @@ -28,6 +29,43 @@ def test_create_testcase_with_cyrillic_works_issue_1770(self):
case.refresh_from_db()
self.assertTrue(case.summary.endswith("кирилица"))

class TestCaseCalculateExpectedDuration(TestCase):
"""Test TestCase.expected_duration"""

def test_duration_is_calculated_correctly(self):
case_random_duration = TestCaseFactory()
setup_duration = case_random_duration.setup_duration
testing_duration = case_random_duration.testing_duration
expected = setup_duration + testing_duration

case_random_duration.save()

case_random_duration.refresh_from_db()
self.assertEqual(case_random_duration.expected_duration, expected)

def test_empty_setup_duration_is_calculated_correctly(self):
case_empty_setup_duration = TestCaseFactory(setup_duration = None)
testing_duration = case_empty_setup_duration.testing_duration
case_empty_setup_duration.save()

case_empty_setup_duration.refresh_from_db()
self.assertEqual(case_empty_setup_duration.expected_duration, testing_duration)

def test_empty_testing_duration_is_calculated_correctly(self):
case_empty_testing_duration = TestCaseFactory(testing_duration = None)
setup_duration = case_empty_testing_duration.setup_duration
case_empty_testing_duration.save()

case_empty_testing_duration.refresh_from_db()
self.assertEqual(case_empty_testing_duration.expected_duration, setup_duration)

def test_empty_durations_are_calculated_correctly(self):
case_no_durations = TestCaseFactory(setup_duration = None, testing_duration = None)
case_no_durations.save()

case_no_durations.refresh_from_db()
self.assertEqual(case_no_durations.expected_duration, None)


class TestCaseRemoveComponent(BasePlanCase):
"""Test TestCase.remove_component"""
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 @@ -165,6 +167,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 e13bd71

Please sign in to comment.