-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* EREGCSC-1996-editible-dates
- Loading branch information
Showing
8 changed files
with
264 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import unittest | ||
from common.fields import VariableDateField | ||
from django.core.exceptions import ValidationError | ||
|
||
|
||
class VariableDateFieldTest(unittest.TestCase): | ||
def setUp(self): | ||
self.field = VariableDateField() | ||
|
||
def test_valid_date_values(self): | ||
values = [ | ||
"2022-07-15", | ||
"2022-07", | ||
"2022", | ||
"", | ||
None, | ||
] | ||
for value in values: | ||
self.assertEqual(self.field.clean(value, value), value) | ||
|
||
def test_invalid_date_values(self): | ||
values = [ | ||
{ | ||
"value": "abcd-07", | ||
"error_message": "Date field must be blank or of the format \"YYYY\", \"YYYY-MM\", or \"YYYY-MM-DD\"", | ||
}, | ||
{ | ||
"value": "13", | ||
"error_message": "Date field must be blank or of the format \"YYYY\", \"YYYY-MM\", or \"YYYY-MM-DD\"", | ||
}, | ||
{ | ||
"value": "2022-02-30", | ||
"error_message": "30 is not a valid day for the month of 02.", | ||
}, | ||
] | ||
|
||
for value in values: | ||
with self.assertRaises(ValidationError) as context: | ||
self.field.clean(value["value"], None) | ||
self.assertIn( | ||
value["error_message"], | ||
str(context.exception), | ||
) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
solution/backend/regulations/migrations/0009_auto_20230714_1506.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Generated by Django 3.2.19 on 2023-07-14 15:06 | ||
|
||
import common.fields | ||
import django.core.validators | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('regulations', '0008_statutelinkconfiguration'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='siteconfiguration', | ||
name='date', | ||
field=common.fields.VariableDateField(blank=True, help_text='Leave blank or enter one of: "YYYY", "YYYY-MM", or "YYYY-MM-DD".', max_length=10, null=True, validators=[common.fields.validate_date, django.core.validators.RegexValidator(message='Date field must be blank or of the format "YYYY", "YYYY-MM", or "YYYY-MM-DD". For example: 2021, 2021-01, or 2021-01-31.', regex='^\\d{4}((-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01]))|(-(0[1-9]|1[0-2])))?$')]), | ||
), | ||
migrations.AddField( | ||
model_name='siteconfiguration', | ||
name='date_type', | ||
field=models.CharField(blank=True, choices=[('effective', 'Effective'), ('amended', 'Amended')], default='', max_length=10, null=True), | ||
), | ||
] |
63 changes: 63 additions & 0 deletions
63
solution/backend/regulations/migrations/0010_auto_20230719_1157.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# Generated by Django 3.2.19 on 2023-07-19 11:57 | ||
|
||
import common.fields | ||
import django.core.validators | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('regulations', '0009_auto_20230714_1506'), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveField( | ||
model_name='siteconfiguration', | ||
name='date', | ||
), | ||
migrations.RemoveField( | ||
model_name='siteconfiguration', | ||
name='date_type', | ||
), | ||
migrations.AddField( | ||
model_name='siteconfiguration', | ||
name='ssa_gov_compilation_date', | ||
field=common.fields.VariableDateField(blank=True, help_text='Leave blank or enter one of: "YYYY", "YYYY-MM", or "YYYY-MM-DD".', max_length=10, null=True, validators=[common.fields.validate_date, django.core.validators.RegexValidator(message='Date field must be blank or of the format "YYYY", "YYYY-MM", or "YYYY-MM-DD". For example: 2021, 2021-01, or 2021-01-31.', regex='^\\d{4}((-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01]))|(-(0[1-9]|1[0-2])))?$')], verbose_name='SSA.gov Compilation Date'), | ||
), | ||
migrations.AddField( | ||
model_name='siteconfiguration', | ||
name='ssa_gov_compilation_date_type', | ||
field=models.CharField(blank=True, choices=[('effective', 'Effective'), ('amended', 'Amended')], default='', max_length=10, null=True, verbose_name='SSA.gov Compilation Date Type'), | ||
), | ||
migrations.AddField( | ||
model_name='siteconfiguration', | ||
name='statute_compilation_date', | ||
field=common.fields.VariableDateField(blank=True, help_text='Leave blank or enter one of: "YYYY", "YYYY-MM", or "YYYY-MM-DD".', max_length=10, null=True, validators=[common.fields.validate_date, django.core.validators.RegexValidator(message='Date field must be blank or of the format "YYYY", "YYYY-MM", or "YYYY-MM-DD". For example: 2021, 2021-01, or 2021-01-31.', regex='^\\d{4}((-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01]))|(-(0[1-9]|1[0-2])))?$')], verbose_name='Statute Compilation Date'), | ||
), | ||
migrations.AddField( | ||
model_name='siteconfiguration', | ||
name='statute_compilation_date_type', | ||
field=models.CharField(blank=True, choices=[('effective', 'Effective'), ('amended', 'Amended')], default='', max_length=10, null=True, verbose_name='Statute Compilation Date Type'), | ||
), | ||
migrations.AddField( | ||
model_name='siteconfiguration', | ||
name='us_code_annual_date', | ||
field=common.fields.VariableDateField(blank=True, help_text='Leave blank or enter one of: "YYYY", "YYYY-MM", or "YYYY-MM-DD".', max_length=10, null=True, validators=[common.fields.validate_date, django.core.validators.RegexValidator(message='Date field must be blank or of the format "YYYY", "YYYY-MM", or "YYYY-MM-DD". For example: 2021, 2021-01, or 2021-01-31.', regex='^\\d{4}((-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01]))|(-(0[1-9]|1[0-2])))?$')], verbose_name='US Code Annual Date'), | ||
), | ||
migrations.AddField( | ||
model_name='siteconfiguration', | ||
name='us_code_annual_date_type', | ||
field=models.CharField(blank=True, choices=[('effective', 'Effective'), ('amended', 'Amended')], default='', max_length=10, null=True, verbose_name='US Code Annual Date Type'), | ||
), | ||
migrations.AddField( | ||
model_name='siteconfiguration', | ||
name='us_code_house_gov_date', | ||
field=common.fields.VariableDateField(blank=True, help_text='Leave blank or enter one of: "YYYY", "YYYY-MM", or "YYYY-MM-DD".', max_length=10, null=True, validators=[common.fields.validate_date, django.core.validators.RegexValidator(message='Date field must be blank or of the format "YYYY", "YYYY-MM", or "YYYY-MM-DD". For example: 2021, 2021-01, or 2021-01-31.', regex='^\\d{4}((-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01]))|(-(0[1-9]|1[0-2])))?$')], verbose_name='US Code House.gov Date'), | ||
), | ||
migrations.AddField( | ||
model_name='siteconfiguration', | ||
name='us_code_house_gov_date_type', | ||
field=models.CharField(blank=True, choices=[('effective', 'Effective'), ('amended', 'Amended')], default='', max_length=10, null=True, verbose_name='US Code House.gov Date Type'), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
solution/backend/regulations/tests/test_site_configuration.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import unittest | ||
import pytest | ||
from regulations.models import SiteConfiguration | ||
|
||
|
||
@pytest.mark.django_db | ||
class SiteConfigurationTest(unittest.TestCase): | ||
def setUp(self): | ||
SiteConfiguration.objects.all().delete() | ||
|
||
def test_date_fields(self): | ||
site_config = SiteConfiguration.objects.create(pk=1) | ||
date_fields = [ | ||
{ | ||
'field_name': 'us_code_house_gov', | ||
'date_type': 'effective', | ||
'date': '2023', | ||
}, | ||
{ | ||
'field_name': 'ssa_gov_compilation', | ||
'date_type': 'amended', | ||
'date': 'Dec 2018', | ||
}, | ||
{ | ||
'field_name': 'statute_compilation', | ||
'date_type': 'effective', | ||
'date': 'Dec 2019', | ||
}, | ||
{ | ||
'field_name': 'us_code_annual', | ||
'date_type': 'effective', | ||
'date': 'Dec 2022', | ||
}, | ||
] | ||
|
||
for field in date_fields: | ||
field_name = field['field_name'] | ||
date_type = field['date_type'] | ||
date = field['date'] | ||
|
||
# Set the date field values | ||
setattr(site_config, f"{field_name}_date_type", date_type) | ||
setattr(site_config, f"{field_name}_date", date) | ||
|
||
# Retrieve the date field values and assert | ||
retrieved_date_type = getattr(site_config, f"{field_name}_date_type") | ||
retrieved_date = getattr(site_config, f"{field_name}_date") | ||
|
||
self.assertEqual(retrieved_date_type, date_type) | ||
self.assertEqual(retrieved_date, date) | ||
|
||
def test_site_configuration_str(self): | ||
site_config = SiteConfiguration.get_solo() | ||
expected_str = 'Site Configuration' | ||
self.assertEqual(str(site_config), expected_str) | ||
|
||
def test_site_configuration_valid_date_type(self): | ||
site_config = SiteConfiguration.get_solo() | ||
site_config.full_clean() # Should not raise any ValidationError | ||
|
||
def test_site_configuration_empty_date_type(self): | ||
site_config = SiteConfiguration.get_solo() | ||
site_config.full_clean() # Should not raise any ValidationError |