def test_parse_format_parse(self): for (rep, val) in self.cannonical_form_tests: exp = val.total_seconds() act = utils.parse_duration( utils.format_duration( utils.parse_duration(rep))).total_seconds() self.assertEqual(exp, act)
def ban_user(user, duration='1m', reason='test ban', start_expired=False): start_date = timezone.now() if duration != None: duration = utils.parse_duration(duration) if start_expired: start_date -= duration + timedelta(seconds=1) end_date = start_date + duration elif start_expired: raise RuntimeError( 'It makes no sense to have an infinte duration ban but also ' 'start expired.') else: end_date=None ban = Ban( subject=user, given_by=Poster.get_or_create_system_user(), start_date=start_date, end_date=end_date, reason=reason) ban.save() return ban
def test_strange_parse_duration(self): for (rep, val) in self.strange_tests: exp = val.total_seconds() act = utils.parse_duration(rep).total_seconds() msg = 'Expected "%s" to evaluate to %d seconds, got %d.' % ( rep, exp, act) self.assertEqual(exp, act, msg)