diff --git a/britney2/policies/policy.py b/britney2/policies/policy.py index a2ebc22..986c5b1 100644 --- a/britney2/policies/policy.py +++ b/britney2/policies/policy.py @@ -179,6 +179,7 @@ class AgePolicy(BasePolicy): raise ValueError("Missing age-requirement for default urgency (MINDAYS_%s)" % options.default_urgency) self._min_days_default = mindays[options.default_urgency] # britney's "day" begins at 7pm (we want aging to occur in the 22:00Z run and we run Britney 2-4 times a day) + # NB: _date_now is used in tests self._date_now = int(((time.time() / (60*60)) - 19) / 24) self._dates = {} self._urgencies = {} diff --git a/tests/policy-test-data/age/basic/age-policy-dates b/tests/policy-test-data/age/basic/age-policy-dates new file mode 100644 index 0000000..fd374b9 --- /dev/null +++ b/tests/policy-test-data/age/basic/age-policy-dates @@ -0,0 +1,6 @@ +# +# NB: The default "day" for the tests is 10. For urgency medium, this implies +# setting to 0-5 is passing while 6-10 is too young. +out-of-date-version 1.5 5 +almost-aged-properly 2.0 6 +aged-properly 2.0 5 diff --git a/tests/policy-test-data/age/basic/age-policy-urgencies b/tests/policy-test-data/age/basic/age-policy-urgencies new file mode 100644 index 0000000..1bb8bf6 --- /dev/null +++ b/tests/policy-test-data/age/basic/age-policy-urgencies @@ -0,0 +1 @@ +# empty diff --git a/tests/test_policy.py b/tests/test_policy.py index 2ece786..ade4235 100644 --- a/tests/test_policy.py +++ b/tests/test_policy.py @@ -140,6 +140,10 @@ class TestAgePolicy(unittest.TestCase): 'low': 10, } + @classmethod + def reset_age(cls, policy, effective_date=10): + policy._date_now = effective_date + def test_missing_age_file(self): age_file = os.path.join(POLICY_DATA_BASE_DIR, 'age', 'missing-age-file', 'age-policy-dates') assert not os.path.exists(age_file) @@ -155,6 +159,47 @@ class TestAgePolicy(unittest.TestCase): if os.path.exists(age_file): os.unlink(age_file) + def test_age_new(self): + src_name = 'unlisted-source-package' + policy = initialize_policy('age/basic', AgePolicy, TestAgePolicy.DEFAULT_MIN_DAYS) + age_policy_info = apply_policy(policy, PolicyVerdict.REJECTED_TEMPORARILY, src_name) + assert age_policy_info['age-requirement'] == TestAgePolicy.DEFAULT_MIN_DAYS[DEFAULT_URGENCY] + assert age_policy_info['current-age'] == 0 + + def test_age_urgented(self): + src_name = 'unlisted-source-package' + policy = initialize_policy('age/basic', AgePolicy, TestAgePolicy.DEFAULT_MIN_DAYS, + hints=['urgent unlisted-source-package/2.0']) + age_policy_info = apply_policy(policy, PolicyVerdict.PASS_HINTED, src_name) + assert age_policy_info['age-requirement'] == TestAgePolicy.DEFAULT_MIN_DAYS[DEFAULT_URGENCY] + assert age_policy_info['current-age'] == 0 + assert age_policy_info['age-requirement-reduced']['new-requirement'] == 0 + assert age_policy_info['age-requirement-reduced']['changed-by'] == TEST_HINTER + + def test_age_old_version_aged(self): + src_name = 'out-of-date-version' + policy = initialize_policy('age/basic', AgePolicy, TestAgePolicy.DEFAULT_MIN_DAYS) + self.reset_age(policy) + age_policy_info = apply_policy(policy, PolicyVerdict.REJECTED_TEMPORARILY, src_name) + assert age_policy_info['age-requirement'] == TestAgePolicy.DEFAULT_MIN_DAYS[DEFAULT_URGENCY] + assert age_policy_info['current-age'] == 0 + + def test_age_almost_aged(self): + src_name = 'almost-aged-properly' + policy = initialize_policy('age/basic', AgePolicy, TestAgePolicy.DEFAULT_MIN_DAYS) + self.reset_age(policy) + age_policy_info = apply_policy(policy, PolicyVerdict.REJECTED_TEMPORARILY, src_name) + assert age_policy_info['age-requirement'] == TestAgePolicy.DEFAULT_MIN_DAYS[DEFAULT_URGENCY] + assert age_policy_info['current-age'] == 4 + + def test_age_aged_properly(self): + src_name = 'aged-properly' + policy = initialize_policy('age/basic', AgePolicy, TestAgePolicy.DEFAULT_MIN_DAYS) + self.reset_age(policy) + age_policy_info = apply_policy(policy, PolicyVerdict.PASS, src_name) + assert age_policy_info['age-requirement'] == TestAgePolicy.DEFAULT_MIN_DAYS[DEFAULT_URGENCY] + assert age_policy_info['current-age'] == 5 + class TestPiupartsPolicy(unittest.TestCase): @@ -195,5 +240,6 @@ class TestPiupartsPolicy(unittest.TestCase): assert piu_policy_info['test-results'] == 'failed' assert piu_policy_info['piuparts-test-url'] == 'https://piuparts.debian.org/sid/source/f/failed-not-regression.html' + if __name__ == '__main__': unittest.main()