Skip to content

Commit

Permalink
Update dependencies and support Django 4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
willbarton committed Mar 1, 2024
1 parent c3791ad commit f292f83
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 68 deletions.
2 changes: 1 addition & 1 deletion countylimits/data_collection/gather_county_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
2 changes: 1 addition & 1 deletion countylimits/management/commands/load_county_limits.py
Original file line number Diff line number Diff line change
Expand Up @@ -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='"'
)
Expand Down
22 changes: 11 additions & 11 deletions countylimits/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -271,50 +271,50 @@ 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"),
va_limit=Decimal("453100.00"),
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"),
va_limit=Decimal("453100.00"),
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"),
Expand Down
2 changes: 1 addition & 1 deletion ratechecker/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])

Expand Down
Original file line number Diff line number Diff line change
@@ -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


Expand Down
3 changes: 1 addition & 2 deletions ratechecker/tests/test_dataset.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 2 additions & 2 deletions ratechecker/tests/test_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand Down
3 changes: 1 addition & 2 deletions ratechecker/tests/test_validation.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
10 changes: 5 additions & 5 deletions ratechecker/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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"
Expand All @@ -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")
6 changes: 3 additions & 3 deletions ratechecker/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down
52 changes: 26 additions & 26 deletions settings_for_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
]
17 changes: 8 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@


install_requires = [
"beautifulsoup4>=4.5.0,<4.9",
"Django>=1.11,<3.3",
"beautifulsoup4>=4.12.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 = [
Expand All @@ -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 = [
Expand Down
6 changes: 3 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -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}
Expand All @@ -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
Expand Down

0 comments on commit f292f83

Please sign in to comment.