Пример #1
0
 def test_blank_data(self):
     form = FootballHistoryForm(data={})
     self.assertFalse(form.is_valid())
     self.assertEqual(len(form.errors), 3)
     self.assertIn("Du måste fylla i detta fält.",
                   form.errors['start_year'])
     self.assertIn("Du måste fylla i detta fält.", form.errors['end_year'])
     self.assertIn("Du måste fylla i detta fält.", form.errors['team_name'])
Пример #2
0
 def test_valid_data(self):
     form_data = {
         "start_year": "2000",
         "end_year": "2001",
         "team_name": "Örebro SK",
     }
     form = FootballHistoryForm(data=form_data)
     self.assertTrue(form.is_valid())
Пример #3
0
 def test_invalid_data(self):
     form_data = {
         "start_year": True,
         "end_year": True,
         "team_name": "Örebro SK",
     }
     form = FootballHistoryForm(data=form_data)
     self.assertFalse(form.is_valid())
     self.assertEqual(len(form.errors), 2)
     self.assertIn("Du måste ange en siffra.", form.errors['start_year'])
     self.assertIn("Du måste ange en siffra.", form.errors['end_year'])
Пример #4
0
 def test_clean_start_and_end_year(self):
     ''' Making sure start year is not greater than the end year. '''
     form_data = {
         "start_year": "2010",
         "end_year": "2005",
         "team_name": "Örebro SK",
     }
     form = FootballHistoryForm(data=form_data)
     self.assertFalse(form.is_valid())
     self.assertIn("Startåret kan inte vara senare än s**tåret.",
                   form.errors['start_year'])
Пример #5
0
 def test_clean_year_format(self):
     form_data = {
         "start_year": "200",
         "end_year": "201",
         "team_name": "Örebro SK",
     }
     form = FootballHistoryForm(data=form_data)
     self.assertFalse(form.is_valid())
     self.assertIn("Startåret måste ha det följande formatet: YYYY",
                   form.errors['start_year'])
     self.assertIn("S**tåret måste ha det följande formatet: YYYY",
                   form.errors['end_year'])
Пример #6
0
 def test_clean_future_year(self):
     current_year = datetime.datetime.now().year
     form_data = {
         "start_year": current_year + 1,
         "end_year": current_year + 2,
         "team_name": "Örebro SK",
     }
     form = FootballHistoryForm(data=form_data)
     self.assertFalse(form.is_valid())
     self.assertIn("Startåret kan inte ligga i framtiden.",
                   form.errors['start_year'])
     self.assertIn("S**tåret kan inte ligga i framtiden.",
                   form.errors['end_year'])
Пример #7
0
 def test_labels(self):
     form = FootballHistoryForm()
     self.assertEqual(form.fields['start_year'].label, "startdatum:")
     self.assertEqual(form.fields['end_year'].label, "slutdatum:")
     self.assertEqual(form.fields['team_name'].label, "lagnamn:")
Пример #8
0
 def test_widgets(self):
     form = FootballHistoryForm()
     self.assertIsInstance(form.fields['start_year'].widget, forms.Select)
     self.assertIsInstance(form.fields['end_year'].widget, forms.Select)
Пример #9
0
 def test_fields(self):
     form = FootballHistoryForm()
     self.assertEqual(len(form.fields), 3)
     self.assertIn("start_year", form.fields)
     self.assertIn("end_year", form.fields)
     self.assertIn("team_name", form.fields)