Ejemplo n.º 1
0
    def test_date_between(self):
        today = date.today()
        _30_years_ago = change_year(today, -30)
        _20_years_ago = change_year(today, -20)

        random_date = self.fake.date_between(start_date='-30y', end_date='-20y')

        assert isinstance(random_date, date)
        self.assertBetween(random_date, _30_years_ago, _20_years_ago)
Ejemplo n.º 2
0
    def test_date_time_between(self):
        now = datetime.now()
        _30_years_ago = change_year(now, -30)
        _20_years_ago = change_year(now, -20)

        random_datetime = self.fake.date_time_between(start_date='-30y', end_date='-20y')

        assert isinstance(random_datetime, datetime)
        self.assertBetween(random_datetime, _30_years_ago, _20_years_ago)
Ejemplo n.º 3
0
    def test_distant_age_range(self):
        for _ in range(100):
            now = datetime.now(utc).date()

            days_since_one_hundred_years_ago = now - change_year(now, -100)
            days_since_one_hundred_eleven_years_ago = now - change_year(now, -111)

            dob = self.fake.date_of_birth(minimum_age=100, maximum_age=110)
            days_since_dob = now - dob

            assert isinstance(dob, date)
            assert days_since_one_hundred_eleven_years_ago > days_since_dob >= days_since_one_hundred_years_ago
Ejemplo n.º 4
0
    def test_identical_age_range(self):
        for _ in range(100):
            now = datetime.now(utc).date()

            days_since_five_years_ago = now - change_year(now, -5)
            days_since_six_years_ago = now - change_year(now, -6)

            dob = self.fake.date_of_birth(tzinfo=utc, minimum_age=5, maximum_age=5)
            days_since_dob = now - dob

            assert isinstance(dob, date)
            assert days_since_six_years_ago > days_since_dob >= days_since_five_years_ago
Ejemplo n.º 5
0
 def test_change_year(self):
     _2020_06_01 = datetime.strptime("2020-06-01", "%Y-%m-%d")
     _20_years_ago = change_year(_2020_06_01, -20)
     self.assertEqual(_20_years_ago.strftime("%Y-%m-%d"), "2000-06-01")
     # Verify a leap day
     today = datetime.strptime("2020-02-29", "%Y-%m-%d")
     with self.assertRaises(ValueError):
         _11_years_ago = today.replace(year=11)
     _11_years_ago = change_year(today, -11)
     self.assertEqual(_11_years_ago.strftime("%Y-%m-%d"), "2009-03-01")
     # 0 is an invalid year, so it should still raise a ValueError
     with self.assertRaises(ValueError):
         change_year(today, -today.year)
Ejemplo n.º 6
0
    def test_date_time_between(self):
        now = datetime.now()
        _30_years_ago = change_year(now, -30)
        _20_years_ago = change_year(now, -20)

        random_datetime = self.fake.date_time_between(start_date="-30y",
                                                      end_date="-20y")
        assert isinstance(random_datetime, datetime)
        self.assertBetween(random_datetime, _30_years_ago, _20_years_ago)

        now = datetime.now(tz=utc)
        _30_years_ago = change_year(now, -30)
        _20_years_ago = change_year(now, -20)

        random_datetime = self.fake.date_time_between(start_date="-30y",
                                                      end_date="-20y",
                                                      tzinfo=utc)
        assert isinstance(random_datetime, datetime)
        self.assertBetween(random_datetime, _30_years_ago, _20_years_ago)
Ejemplo n.º 7
0
    def test_acceptable_age_range_eighteen_years(self):
        for _ in range(100):
            now = datetime.now(utc).date()

            days_since_now = now - now
            days_since_nineteen_years_ago = now - change_year(now, -19)

            dob = self.fake.date_of_birth(tzinfo=utc, minimum_age=0, maximum_age=18)
            days_since_dob = now - dob

            assert isinstance(dob, date)
            assert days_since_nineteen_years_ago > days_since_dob >= days_since_now