Beispiel #1
0
 def test_get_first_monday(self):
     formatting_dates = ManagerDates()
     self.assertEqual(formatting_dates.get_first_monday("2019"),
                      "06/05/2019")
Beispiel #2
0
 def test_date_is_valid_true(self):
     date = '01/02/2019'
     formatting_dates = ManagerDates()
     self.assertEqual(formatting_dates.date_is_valid(date), True)
Beispiel #3
0
 def test_get_all_dates(self):
     formatting_dates = ManagerDates()
     self.assertEqual(len(formatting_dates.get_all_dates("02", "2019")), 28)
Beispiel #4
0
 def test_count_days_mounth(self):
     formatting_dates = ManagerDates()
     self.assertEqual(formatting_dates.count_days_mounth("03", "2019"), 21)
Beispiel #5
0
 def test_convert_string_to_date(self):
     date = "19/01/2018"
     formatting_dates = ManagerDates()
     self.assertEqual(formatting_dates.convert_string_to_date(date),
                      datetime.datetime(2018, 1, 19))
Beispiel #6
0
 def test_date_weekday(self):
     date = datetime.datetime(2019, 3, 24)
     formatting_dates = ManagerDates()
     self.assertEqual(formatting_dates.date_weekday(date), "Sunday")
Beispiel #7
0
 def test_date_is_valid_false(self):
     date = '01-02-2019'
     formatting_dates = ManagerDates()
     self.assertEqual(formatting_dates.date_is_valid(date), False)
Beispiel #8
0
    def setUp(self):
        """Creates an object of the ManagerDates class before each test method."""

        self.formatter = ManagerDates()
Beispiel #9
0
class ManagerDatesTests(unittest.TestCase):
    """Performs unit test in the ManagerDates class."""
    def setUp(self):
        """Creates an object of the ManagerDates class before each test method."""

        self.formatter = ManagerDates()

    def test_date_is_valid(self):
        """Tests if a date conforms to a format."""

        self.assertEqual(self.formatter.date_is_valid('01/02/2019'), True)
        for date in ['01-02-2019', '1022019', '02/2019']:
            self.assertEqual(self.formatter.date_is_valid(date), False)

    def test_date_weekday(self):
        """Tests if the weekday name is correct given a date."""

        self.assertEqual(self.formatter.date_weekday(datetime(2019, 6, 30)),
                         'Sunday')
        self.assertEqual(self.formatter.date_weekday(datetime(2019, 7, 1)),
                         'Monday')
        self.assertEqual(self.formatter.date_weekday(datetime(2019, 7, 2)),
                         'Tuesday')
        self.assertEqual(self.formatter.date_weekday(datetime(2019, 7, 3)),
                         'Wednesday')
        self.assertEqual(self.formatter.date_weekday(datetime(2019, 7, 4)),
                         'Thursday')
        self.assertEqual(self.formatter.date_weekday(datetime(2019, 7, 5)),
                         'Friday')
        self.assertEqual(self.formatter.date_weekday(datetime(2019, 7, 6)),
                         'Saturday')

    def test_convert_string_to_date(self):
        """Tests if a date in the string format is correctly converted to datetime."""

        self.assertEqual(self.formatter.convert_string_to_date('19/01/2018'),
                         datetime(2018, 1, 19))
        self.assertEqual(self.formatter.convert_string_to_date('19-01-2018'),
                         datetime(2018, 1, 19))
        self.assertEqual(self.formatter.convert_string_to_date('19012018'),
                         datetime(2018, 1, 19))
        self.assertEqual(self.formatter.convert_string_to_date('2018/01/12'),
                         False)

    def test_get_all_dates(self):
        """Tests if the list with the dates of a month in a year was successfully generated according to the number of days in that month."""

        self.assertEqual(len(self.formatter.get_all_dates('02', '2019')), 28)
        self.assertEqual(len(self.formatter.get_all_dates('07', '2019')), 31)

    def test_count_days_mounth(self):
        """Tests if the busdays was counted correctly given a month and year."""

        self.assertEqual(self.formatter.count_days_mounth('03', '2019'), 21)
        self.assertEqual(self.formatter.count_days_mounth('07', '2019'), 23)

    def test_get_first_monday(self):
        """Tests if the date of the first Monday in May was correctly returned according to a year."""

        self.assertEqual(self.formatter.get_first_monday('2018'), '07/05/2018')
        self.assertEqual(self.formatter.get_first_monday('2019'), '06/05/2019')