AgePolicy: Fix bug in creating the age file

Signed-off-by: Niels Thykier <niels@thykier.net>
email-direct-upload-sponsor
Niels Thykier 8 years ago
parent 241b17602d
commit d3e343a3bd

@ -326,7 +326,7 @@ class AgePolicy(BasePolicy):
# If we using the legacy name, then just give up # If we using the legacy name, then just give up
raise raise
self.log("%s does not appear to exist. Creating it" % filename) self.log("%s does not appear to exist. Creating it" % filename)
with open(filename, mode='wx', encoding='utf-8'): with open(filename, mode='x', encoding='utf-8'):
pass pass
def _read_urgencies_file(self, britney): def _read_urgencies_file(self, britney):

@ -4,11 +4,12 @@ import os
from britney2 import SuiteInfo, SourcePackage from britney2 import SuiteInfo, SourcePackage
from britney2.excuse import Excuse from britney2.excuse import Excuse
from britney2.hints import HintParser from britney2.hints import HintParser
from britney2.policies.policy import RCBugPolicy, PolicyVerdict from britney2.policies.policy import AgePolicy, RCBugPolicy, PolicyVerdict
POLICY_DATA_BASE_DIR = os.path.join(os.path.dirname(__file__), 'policy-test-data') POLICY_DATA_BASE_DIR = os.path.join(os.path.dirname(__file__), 'policy-test-data')
TEST_HINTER = 'test-hinter' TEST_HINTER = 'test-hinter'
HINTS_ALL = ('ALL') HINTS_ALL = ('ALL')
DEFAULT_URGENCY = 'medium'
def initialize_policy(test_name, policy_class, *args, **kwargs): def initialize_policy(test_name, policy_class, *args, **kwargs):
@ -17,7 +18,7 @@ def initialize_policy(test_name, policy_class, *args, **kwargs):
if 'hints' in kwargs: if 'hints' in kwargs:
hints = kwargs['hints'] hints = kwargs['hints']
del kwargs['hints'] del kwargs['hints']
options = MockObject(state_dir=test_dir, verbose=0, **kwargs) options = MockObject(state_dir=test_dir, verbose=0, default_urgency=DEFAULT_URGENCY, **kwargs)
suite_info = { suite_info = {
'testing': SuiteInfo('testing', os.path.join(test_dir, 'testing'), ''), 'testing': SuiteInfo('testing', os.path.join(test_dir, 'testing'), ''),
'unstable': SuiteInfo('unstable', os.path.join(test_dir, 'unstable'), ''), 'unstable': SuiteInfo('unstable', os.path.join(test_dir, 'unstable'), ''),
@ -137,5 +138,33 @@ class TestRCBugsPolicy(unittest.TestCase):
assert policy_info['rc-bugs']['ignored-bugs']['issued-by'] == TEST_HINTER assert policy_info['rc-bugs']['ignored-bugs']['issued-by'] == TEST_HINTER
assert set(policy_info['rc-bugs']['shared-bugs']) == set() assert set(policy_info['rc-bugs']['shared-bugs']) == set()
class TestAgePolicy(unittest.TestCase):
DEFAULT_MIN_DAYS = {
'emergency': 0,
'critical': 0,
'high': 2,
'medium': 5,
'low': 10,
}
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)
try:
src_name = 'unlisted-source-package'
src_t, src_u, excuse, policy_info = create_policy_objects(src_name, '1.0', '2.0')
policy = initialize_policy('age/missing-age-file', AgePolicy, TestAgePolicy.DEFAULT_MIN_DAYS)
verdict = policy.apply_policy(policy_info, 'unstable', src_name, src_t, src_u, excuse)
assert os.path.exists(age_file)
assert verdict == PolicyVerdict.REJECTED_TEMPORARILY
assert policy_info['age']['age-requirement'] == TestAgePolicy.DEFAULT_MIN_DAYS[DEFAULT_URGENCY]
assert policy_info['age']['current-age'] == 0
finally:
if os.path.exists(age_file):
os.unlink(age_file)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

Loading…
Cancel
Save