"""Unit tests for the dates util module.""" import datetime from freezegun import freeze_time from activity_detector.utils import dates @freeze_time('2018-01-03') # Wednesday the 3rd of January 2018 def test_get_last_monday_on_wednesday(): """Test getting the last monday when running on a wednesday.""" # Monday the 1st of January 2018 at midnight expected = datetime.datetime(2018, 1, 1, 0, 0, 0) result = dates.get_last_monday() assert result == expected @freeze_time('2018-01-01') # Monday the 1st of January 2018 def test_get_last_monday_on_monday(): """Test getting the last monday when running on a monday.""" # Monday the 1st of January 2018 at midnight expected = datetime.datetime(2018, 1, 1, 0, 0, 0) result = dates.get_last_monday() assert result == expected @freeze_time('2018-01-03') # Wednesday the 3rd of January 2018 def test_get_friday_of_last_week_on_wednesday(): """Test getting the last friday when running on a wednesday.""" # Friday the 29th of December 2017 at midnight expected = datetime.datetime(2017, 12, 29, 0, 0, 0) result = dates.get_friday_of_last_week() assert result == expected @freeze_time('2018-01-05') # Friday the 5th of January 2018 def test_get_friday_of_last_week_on_friday(): """Test getting the last friday when running on a friday.""" # Friday the 29th of December 2017 at midnight expected = datetime.datetime(2017, 12, 29, 0, 0, 0) result = dates.get_friday_of_last_week() assert result == expected @freeze_time('2018-01-03') # Wednesday the 3rd of January 2018 def test_get_friday_of_two_weeks_ago_on_wednesday(): """Test getting the friday before last when running on a wednesday.""" # Friday the 22nd of December 2017 at midnight expected = datetime.datetime(2017, 12, 22, 0, 0, 0) result = dates.get_friday_of_two_weeks_ago() assert result == expected @freeze_time('2018-01-05') # Friday the 5th of January 2018 def test_get_friday_of_two_weeks_ago_on_friday(): """Test getting the friday before last when running on a friday.""" # Friday the 22nd of December 2017 at midnight expected = datetime.datetime(2017, 12, 22, 0, 0, 0) result = dates.get_friday_of_two_weeks_ago() assert result == expected @freeze_time('2018-01-04') # Thursday the 4th of January 2018 def test_get_last_thursday_on_thursday(): """Test getting the last thursday when running on a thursday.""" # Thursday the 28nd of December 2017 at midnight expected = datetime.datetime(2017, 12, 28, 0, 0, 0) result = dates.get_last_thursday() assert result == expected @freeze_time('2018-01-01') # Thursday the 1th of January 2018 def test_get_last_thursday_on_monday(): """Test getting the last thursday when running on a monday.""" # Thursday the 28nd of December 2017 at midnight expected = datetime.datetime(2017, 12, 28, 0, 0, 0) result = dates.get_last_thursday() assert result == expected @freeze_time('2018-01-07') # Sunday the 7th of January 2018 def test_get_last_thursday_on_sunday(): """Test getting the last thursday when running on a sunday.""" # Thursday the 4th of january 2018 at midnight expected = datetime.datetime(2018, 1, 4, 0, 0, 0) result = dates.get_last_thursday() assert result == expected @freeze_time('2018-01-07') # Sunday the 7th of January 2018 def test_get_friday_before_last_on_sunday(): """Test getting the last friday when running on a sunday.""" # Friday the 29th of december 2017 at midnight expected = datetime.datetime(2017, 12, 29, 0, 0, 0) result = dates.get_friday_before_last() assert result == expected @freeze_time('2018-01-05') # Friday the 5th of January 2018 def test_get_friday_before_last_on_friday(): """Test getting the last friday when running on a friday.""" # Friday the 22th of december 2017 at midnight expected = datetime.datetime(2017, 12, 22, 0, 0, 0) result = dates.get_friday_before_last() assert result == expected