def test_format_conditional_date_not_set(self): # Given # When with self.assertRaises(Exception) as exception: format_conditional_date(self.autoescape_context, None, None) # Then self.assertIn('No valid items provided.', str(exception.exception))
def test_format_conditional_date_not_date(self): # Given no test for integers this check was removed from jinja_filters invalid_input = [('1', None), ('1-1-1', None)] # When for nonsense in invalid_input: date1 = nonsense[0] date2 = nonsense[1] with self.assertRaises(Exception) as exception: format_conditional_date(self.autoescape_context, date1, date2) # Then self.assertIn("does not match format '%Y-%m'", str(exception.exception))
def test_format_conditional_date(self): # Given datelist = [('2016-01-12', '2016-02-12', '12 January 2016'), ('2017-12-23', None, '23 December 2017'), (None, '2017-12-24', '24 December 2017')] # When with self.app_request_context('/'): for triple in datelist: date1 = triple[0] date2 = triple[1] format_value = format_conditional_date(self.autoescape_context, date1, date2) # Then self.assertEqual(format_value, "<span class='date'>{date}</span>".format(date=triple[2]))