From ddb8906687bc30bcfc00227e0ff91858c85c2e10 Mon Sep 17 00:00:00 2001 From: Will Barton Date: Fri, 1 Mar 2024 11:51:43 -0500 Subject: [PATCH] Update dependencies and support Django 4.2 --- .../data_collection/gather_county_data.py | 2 +- .../management/commands/load_county_limits.py | 2 +- countylimits/tests.py | 22 ++++---- ratechecker/dataset.py | 2 +- .../commands/test_load_daily_data.py | 3 +- ratechecker/tests/test_dataset.py | 3 +- ratechecker/tests/test_loader.py | 4 +- ratechecker/tests/test_validation.py | 3 +- ratechecker/tests/test_views.py | 10 ++-- ratechecker/views.py | 6 +-- settings_for_testing.py | 52 +++++++++---------- setup.py | 17 +++--- tox.ini | 6 +-- 13 files changed, 64 insertions(+), 68 deletions(-) diff --git a/countylimits/data_collection/gather_county_data.py b/countylimits/data_collection/gather_county_data.py index 8004b91..ee67609 100644 --- a/countylimits/data_collection/gather_county_data.py +++ b/countylimits/data_collection/gather_county_data.py @@ -51,7 +51,7 @@ def load_FIPS(): - with open("{}/county_FIPS.csv".format(CSV_DIR), "rU") as f: + with open(f"{CSV_DIR}/county_FIPS.csv", "r", newline="") as f: reader = DictReader(f) return [row for row in reader] diff --git a/countylimits/management/commands/load_county_limits.py b/countylimits/management/commands/load_county_limits.py index bb80e7c..63269b8 100644 --- a/countylimits/management/commands/load_county_limits.py +++ b/countylimits/management/commands/load_county_limits.py @@ -93,7 +93,7 @@ def handle(self, *args, **options): # Users can pass in `latest` or their own CSV path csv_file = DEFAULT_CSV.get(options.get("csv"), options.get("csv")) try: - with open(csv_file, "rU") as csvfile: + with open(csv_file, "r", newline="") as csvfile: csvreader = csv.reader( csvfile, delimiter=",", quotechar='"' ) diff --git a/countylimits/tests.py b/countylimits/tests.py index 27d3a70..9963f43 100644 --- a/countylimits/tests.py +++ b/countylimits/tests.py @@ -9,8 +9,8 @@ from django.core.management.base import CommandError from django.test import TestCase -import mock -from model_mommy import mommy +from unittest import mock +from model_bakery import baker from rest_framework import status from countylimits.data_collection.county_data_monitor import ( @@ -271,16 +271,16 @@ def test_county_data_monitor_with_change_and_email( class CountyLimitTest(TestCase): def setUp(self): - self.AL = mommy.make(State, state_fips="01", state_abbr="AL") + self.AL = baker.make(State, state_fips="01", state_abbr="AL") - self.ALCO = mommy.make( + self.ALCO = baker.make( County, county_fips="001", county_name="Autauga County", state=State.objects.get(state_fips="01"), ) - self.ALLIM = mommy.make( + self.ALLIM = baker.make( CountyLimit, fha_limit=Decimal("294515.00"), gse_limit=Decimal("453100.00"), @@ -288,16 +288,16 @@ def setUp(self): county=County.objects.get(county_name="Autauga County"), ) - self.DC = mommy.make(State, state_fips="11", state_abbr="DC") + self.DC = baker.make(State, state_fips="11", state_abbr="DC") - self.DCCO = mommy.make( + self.DCCO = baker.make( County, county_fips="001", county_name="District of Columbia", state=State.objects.get(state_fips="11"), ) - self.DCLIM = mommy.make( + self.DCLIM = baker.make( CountyLimit, fha_limit=Decimal("294515.00"), gse_limit=Decimal("453100.00"), @@ -305,16 +305,16 @@ def setUp(self): county=County.objects.get(county_name="District of Columbia"), ) - self.VA = mommy.make(State, state_fips="51", state_abbr="VA") + self.VA = baker.make(State, state_fips="51", state_abbr="VA") - self.VACO = mommy.make( + self.VACO = baker.make( County, county_fips="001", county_name="Accomack County", state=State.objects.get(state_fips="51"), ) - self.VALIM = mommy.make( + self.VALIM = baker.make( CountyLimit, fha_limit=Decimal("294515.00"), gse_limit=Decimal("453100.00"), diff --git a/ratechecker/dataset.py b/ratechecker/dataset.py index d0d2dcd..f835f1a 100644 --- a/ratechecker/dataset.py +++ b/ratechecker/dataset.py @@ -85,7 +85,7 @@ def date(self): def expected_scenario_results(self): results = OrderedDict() - for scenario in self.tree.getiterator(tag="Scenario"): + for scenario in self.tree.iter(tag="Scenario"): scenario_data = {elem.tag: elem.text for elem in scenario} scenario_id = int(scenario_data["ScenarioNo"]) diff --git a/ratechecker/tests/management/commands/test_load_daily_data.py b/ratechecker/tests/management/commands/test_load_daily_data.py index 26f38e0..7f829fd 100644 --- a/ratechecker/tests/management/commands/test_load_daily_data.py +++ b/ratechecker/tests/management/commands/test_load_daily_data.py @@ -1,13 +1,12 @@ import os import shutil import tempfile +from unittest.mock import patch from django.core.management import call_command from django.core.management.base import CommandError from django.test import TestCase -from mock import patch - from ratechecker.tests.helpers import write_sample_dataset diff --git a/ratechecker/tests/test_dataset.py b/ratechecker/tests/test_dataset.py index 1314ee9..68f4aea 100644 --- a/ratechecker/tests/test_dataset.py +++ b/ratechecker/tests/test_dataset.py @@ -1,12 +1,11 @@ from datetime import date, datetime from unittest import TestCase +from unittest.mock import Mock from xml.etree.cElementTree import ParseError from django.core.files.base import ContentFile from django.utils import timezone -from mock import Mock - from ratechecker.dataset import CoverSheet from ratechecker.tests.helpers import get_sample_dataset diff --git a/ratechecker/tests/test_loader.py b/ratechecker/tests/test_loader.py index c247d6c..515fe54 100644 --- a/ratechecker/tests/test_loader.py +++ b/ratechecker/tests/test_loader.py @@ -5,7 +5,7 @@ from django.test import TestCase from django.utils import timezone -from model_mommy import mommy +from model_bakery import baker from ratechecker.loader import ( AdjustmentLoader, @@ -352,7 +352,7 @@ class TestRateLoader(LoaderTestCaseMixin, TestCase): loader_cls = RateLoader def setUp(self): - self.product = mommy.make(Product, plan_id=3) + self.product = baker.make(Product, plan_id=3) self.row = { "ratesid": "123", diff --git a/ratechecker/tests/test_validation.py b/ratechecker/tests/test_validation.py index b4dfc6e..5faacd1 100644 --- a/ratechecker/tests/test_validation.py +++ b/ratechecker/tests/test_validation.py @@ -1,10 +1,9 @@ import json from unittest import TestCase +from unittest.mock import patch from django.core.files.base import ContentFile -from mock import patch - from ratechecker.tests.helpers import get_sample_dataset from ratechecker.validation import ( ScenarioLoader, diff --git a/ratechecker/tests/test_views.py b/ratechecker/tests/test_views.py index 3f7c0ed..778ac0b 100644 --- a/ratechecker/tests/test_views.py +++ b/ratechecker/tests/test_views.py @@ -4,7 +4,7 @@ from django.test import override_settings from django.utils import timezone -from model_mommy import mommy +from model_bakery import baker from rest_framework import status from rest_framework.test import APITestCase @@ -494,17 +494,17 @@ def test_no_data_returns_none(self): self.assertEqual(json.loads(response.content), {"load": None}) def test_data_returns_200(self): - mommy.make(Region) + baker.make(Region) response = self.get() self.assertEqual(response.status_code, 200) def test_data_returns_json(self): - mommy.make(Region) + baker.make(Region) response = self.get() self.assertEqual(response["Content-type"], "application/json") def test_data_returns_timestamp(self): - region = mommy.make(Region) + region = baker.make(Region) response = self.get() ts = datetime.strptime( json.loads(response.content)["load"], "%Y-%m-%dT%H:%M:%S.%fZ" @@ -516,6 +516,6 @@ def test_data_returns_timestamp(self): def test_data_format_iso8601(self): timestamp = datetime(2017, 1, 2, 3, 4, 56, tzinfo=timezone.utc) - mommy.make(Region, data_timestamp=timestamp) + baker.make(Region, data_timestamp=timestamp) response = self.get() self.assertContains(response, "2017-01-02T03:04:56Z") diff --git a/ratechecker/views.py b/ratechecker/views.py index 01da5ff..0d33eb7 100644 --- a/ratechecker/views.py +++ b/ratechecker/views.py @@ -66,9 +66,9 @@ def get_rates(params_data, data_load_testing=False, return_fees=False): products = {} for rate in rates: all_rates.append(rate) - products[ - "{}{}".format(rate.product_id, rate.region_id) - ] = rate.product_id + products["{}{}".format(rate.product_id, rate.region_id)] = ( + rate.product_id + ) product_ids = products.values() adjustments = ( diff --git a/settings_for_testing.py b/settings_for_testing.py index a115f64..014e13c 100644 --- a/settings_for_testing.py +++ b/settings_for_testing.py @@ -4,52 +4,52 @@ import dj_database_url BASE_DIR = os.path.abspath(os.path.dirname(__file__)) -sys.path.append(os.path.abspath(os.path.join(BASE_DIR, '..'))) +sys.path.append(os.path.abspath(os.path.join(BASE_DIR, ".."))) INSTALLED_APPS = ( - 'oahapi', - 'ratechecker', - 'countylimits', - 'rest_framework', - 'django.contrib.auth', - 'django.contrib.contenttypes', - 'django.contrib.sessions', - 'django.contrib.messages', - 'django.contrib.staticfiles', + "oahapi", + "ratechecker", + "countylimits", + "rest_framework", + "django.contrib.auth", + "django.contrib.contenttypes", + "django.contrib.sessions", + "django.contrib.messages", + "django.contrib.staticfiles", ) MIDDLEWARE = ( - 'django.contrib.sessions.middleware.SessionMiddleware', - 'django.middleware.common.CommonMiddleware', - 'django.contrib.auth.middleware.AuthenticationMiddleware', - 'django.contrib.messages.middleware.MessageMiddleware', - 'django.middleware.clickjacking.XFrameOptionsMiddleware', + "django.contrib.sessions.middleware.SessionMiddleware", + "django.middleware.common.CommonMiddleware", + "django.contrib.auth.middleware.AuthenticationMiddleware", + "django.contrib.messages.middleware.MessageMiddleware", + "django.middleware.clickjacking.XFrameOptionsMiddleware", ) SECRET_KEY = "django_tests_secret_key" DEBUG = True TEMPLATE_DEBUG = False -ROOT_URLCONF = 'oahapi.urls' +ROOT_URLCONF = "oahapi.urls" DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': 'oah.sqlite3', + "default": { + "ENGINE": "django.db.backends.sqlite3", + "NAME": "oah.sqlite3", } } -if 'DATABASE_URL' in os.environ: - DATABASES['default'] = dj_database_url.config() +if "DATABASE_URL" in os.environ: + DATABASES["default"] = dj_database_url.config() -LANGUAGE_CODE = 'en-us' -TIME_ZONE = 'UTC' +LANGUAGE_CODE = "en-us" +TIME_ZONE = "UTC" USE_I18N = True USE_L10N = True USE_TZ = True -STATIC_URL = '/static/' +STATIC_URL = "/static/" TEMPLATES = [ { - 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'APP_DIRS': True, + "BACKEND": "django.template.backends.django.DjangoTemplates", + "APP_DIRS": True, } ] diff --git a/setup.py b/setup.py index d10ca94..70ea4e6 100755 --- a/setup.py +++ b/setup.py @@ -3,13 +3,13 @@ install_requires = [ - "beautifulsoup4>=4.5.0,<4.9", - "Django>=1.11,<3.3", + "beautifulsoup4>=4.11.0,<5.0", + "Django>=3.2,<4.3", "django-cors-headers", - "dj-database-url>=0.4.2,<1", - "django-localflavor>=1.1,<3.1", - "djangorestframework>=3.9.1,<4.0", - "requests>=2.18,<3", + "dj-database-url>=2.1,<3", + "django-localflavor>=4.0,<5.0", + "djangorestframework>=3.14,<4.0", + "requests>=2.31,<3", ] setup_requires = [ @@ -18,9 +18,8 @@ ] testing_extras = [ - "coverage>=5.0,<6", - "mock==2.0.0", - "model_mommy>=1.6.0,<1.7", + "coverage>=7.4,<8", + "model_bakery>=1.17.0,<2", ] docs_extras = [ diff --git a/tox.ini b/tox.ini index 079be80..472ef58 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,6 @@ [tox] skipsdist=True -envlist=lint,py{38}-dj{22,32} +envlist=lint,py{38,312}-dj{32,42} [testenv] install_command=pip install -e ".[testing]" -U {opts} {packages} @@ -11,11 +11,11 @@ commands= basepython= py38: python3.8 + py312: python3.12 deps= - dj22: Django>=2.2,<2.3 - dj31: Django>=3.1,<3.2 dj32: Django>=3.2,<3.3 + dj42: Django>=4.2,<4.3 [testenv:lint] recreate=False