"""Unit tests for dates validation.""" import pytest from analytics.consts import error from analytics.validation import date_validation @pytest.mark.parametrize( 'correct_dates', [('2017-02-01', '2017-02-28'), ('2017-03-01', '2017-05-29')] ) def test_validate_correct_dates(correct_dates): """Test date range validation with correct dates.""" from_date, to_date = correct_dates days_threshold = 90 result = date_validation.validate_date_range( from_date, to_date, days_threshold) assert result @pytest.mark.parametrize( 'incorrect_dates', [('2017-02-28', '2017-02-01'), ('2017-05-29', '2017-03-01'), ('2017-05-29', '2017-05-29'), ('2017-01-01', '2018-01-01')] ) def test_validate_incorrect_dates(incorrect_dates): """Test date range validation with incorrect dates.""" from_date, to_date = incorrect_dates days_threshold = 90 result = date_validation.validate_date_range( from_date, to_date, days_threshold) assert not result assert result.status == 400 assert result.errors['message'] == error.INVALID_DATE_RANGE_VALUES_MESSAGE @pytest.mark.parametrize( 'ill_formatted_dates', [('2017-03-32', '2017-04-01'), ('31.03.2017', 'AAAAAAA')] ) def test_validate_ill_formatted_dates(ill_formatted_dates): """Test date range validation with ill formatted dates.""" from_date, to_date = ill_formatted_dates days_threshold = 90 result = date_validation.validate_date_range( from_date, to_date, days_threshold) assert not result assert result.status == 400 assert result.errors['message'] == error.INVALID_DATE_RANGE_FORMAT_MESSAGE @pytest.mark.parametrize( 'bad_threshold', [-5, 0] ) def test_validate_correct_dates_with_bad_threshold(bad_threshold): """Test date range validation with correct dates.""" from_date, to_date = ('2017-02-01', '2017-02-28') result = date_validation.validate_date_range( from_date, to_date, bad_threshold) assert not result assert result.status == 400 assert result.errors['message'] == error.INVALID_DAYS_THRESHOLD_MESSAGE