Example #1
0
 def test_validate_required_fields(self):
     validator1 = Validator(self.correct_data)
     validator2 = Validator(self.empty_data)
     validator1.validate_required_fields()
     self.assertFalse(validator1.errors)
     validator2.validate_required_fields()
     self.assertDictEqual(
         {key: f'"{key}" is required field'
          for key in self.correct_data}, validator2.errors)
Example #2
0
 def test_check_errors(self):
     validator1 = Validator(self.incorrect_data)
     validator2 = Validator(self.correct_data)
     validator2.check_errors()
     self.assertFalse(validator2.errors)
     validator1.check_errors()
     self.assertDictEqual(
         {
             'title': '"title" is required field',
             'start_date': 'Input "start_date" as dd/mm/yyyy',
             'lectures_number': 'Must be a digit'
         }, validator1.errors)
Example #3
0
 def test_validate_date_chronology(self):
     validator1 = Validator(self.incorrect_data_date_reverse)
     validator2 = Validator(self.correct_data)
     self.assertFalse(validator1.validate_date_chronology())
     self.assertEqual('"start_date" mast be earlier then "end_date"',
                      validator1.errors['start_date'])
     self.assertTrue(validator2.validate_date_chronology())
Example #4
0
 def test_check_if_date_exists(self):
     validator1 = Validator(self.incorrect_data)
     validator2 = Validator(self.correct_data)
     self.assertFalse(
         validator1.check_if_date_exists(self.incorrect_data['end_date'],
                                         'end_date'))
     self.assertEqual('"end_date" is not exists or in the past',
                      validator1.errors['end_date'])
     self.assertTrue(
         validator2.check_if_date_exists(self.correct_data['end_date'],
                                         'end_date'))
Example #5
0
 def test_check_date_string_format(self):
     validator1 = Validator(self.incorrect_data)
     validator2 = Validator(self.correct_data)
     self.assertFalse(
         validator1.check_date_string_format(
             self.incorrect_data['start_date'], 'start_date'))
     self.assertEqual('Input "start_date" as dd/mm/yyyy',
                      validator1.errors['start_date'])
     self.assertTrue(
         validator2.check_date_string_format(
             self.correct_data['start_date'], 'start_date'))
Example #6
0
 def test_validate_title_length(self):
     validator = Validator({'title': "1" * 129})
     validator.validate_title_length()
     self.assertEqual('Must be less then 128',
                      validator.errors['wrong_title_length'])
Example #7
0
 def test_validate_lectures_number(self):
     validator = Validator(self.incorrect_data)
     validator.validate_lectures_number()
     self.assertEqual('Must be a digit',
                      validator.errors['lectures_number'])
Example #8
0
 def test_str_to_datetime(self, date='11/05/2020'):
     self.assertEqual(Validator.str_to_datetime(date),
                      datetime.strptime(date, '%d/%m/%Y'))