Skip to content

Commit

Permalink
Support Django 3.2 (#159)
Browse files Browse the repository at this point in the history
* Switch Django 3.1 to 3.2

* Linting

Co-authored-by: Justin Slay <justin.slay@cfpb.gov>
  • Loading branch information
jslay-excella and Justin Slay committed Jul 9, 2021
1 parent 5ee44bf commit 424250e
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 29 deletions.
8 changes: 4 additions & 4 deletions countylimits/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@


class State(models.Model):
""" A basic State object. """
"""A basic State object."""

state_fips = models.CharField(
max_length=2, help_text="A two-digit FIPS code for the state"
Expand All @@ -30,7 +30,7 @@ def __str__(self):


class County(models.Model):
""" A basic state county object. """
"""A basic state county object."""

county_fips = models.CharField(
max_length=3,
Expand All @@ -47,7 +47,7 @@ def __str__(self):


class CountyLimit(models.Model):
""" County limit object. """
"""County limit object."""

fha_limit = models.DecimalField(
max_digits=12,
Expand All @@ -74,7 +74,7 @@ def __str__(self):

@staticmethod
def county_limits_by_state(state):
""" Get a list of state counties with limits. """
"""Get a list of state counties with limits."""
data = []
# state value can be a State FIPS or a state abbr.
state_obj = State.objects.filter(
Expand Down
14 changes: 7 additions & 7 deletions countylimits/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,15 +325,15 @@ def setUp(self):
url = "/oah-api/county/"

def test_county_limits_by_state__no_args(self):
""" ... when state is blank """
"""... when state is blank"""
response = self.client.get(self.url, {})
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(
response.data, {"detail": "Required parameter state is missing"}
)

def test_county_limit_by_state__invalid_arg(self):
""" ... when state has an invalid value """
"""... when state has an invalid value"""
response = self.client.get(self.url, {"state": 1234})
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(response.data, {"state": "Invalid state"})
Expand All @@ -342,7 +342,7 @@ def test_county_limit_by_state__invalid_arg(self):
self.assertEqual(response.data, {"state": "Invalid state"})

def test_county_limit_by_state__valid_arg(self):
""" ... when state has a valid arg """
"""... when state has a valid arg"""
response_01 = self.client.get(self.url, {"state": "01"})
self.assertEqual(response_01.status_code, 200)
self.assertEqual(
Expand Down Expand Up @@ -382,13 +382,13 @@ def setUp(self):
self.addCleanup(stdout_patch.stop)

def test_handle__no_confirm(self):
""" .. check that nothing happens when confirm is not y|Y."""
""".. check that nothing happens when confirm is not y|Y."""
err = StringIO()
call_command("load_county_limits", stderr=err)
self.assertNotIn("Successfully loaded data from", err.getvalue())

def test_handle__bad_file(self):
""" .. check that CommandError is raised when path to file is wrong."""
""".. check that CommandError is raised when path to file is wrong."""
self.assertRaises(
CommandError,
self.c.handle,
Expand Down Expand Up @@ -416,13 +416,13 @@ def test_dump_countylimit_fixture(self):
)

def test_handle__success(self):
""" .. check that all countylimits are loaded from CSV."""
""".. check that all countylimits are loaded from CSV."""
self.c.handle(csv=self.test_csv, confirmed="y")
self.assertIn("Successfully loaded data", self.c.stdout.getvalue())
self.assertEqual(CountyLimit.objects.count(), 3233)

def test_handle__fixture_success(self):
""" .. check that all countylimits are loaded from fixture."""
""".. check that all countylimits are loaded from fixture."""
self.c.handle(confirmed="y")
self.assertIn("Successfully loaded data", self.c.stdout.getvalue())
self.assertEqual(CountyLimit.objects.count(), 3233)
Expand Down
2 changes: 1 addition & 1 deletion countylimits/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@

@api_view(["GET"])
def county_limits(request):
""" Return all counties with their limits per state. """
"""Return all counties with their limits per state."""
if request.method == "GET":
package = {"request": {}, "data": []}
if "state" in request.GET:
Expand Down
8 changes: 4 additions & 4 deletions ratechecker/management/commands/load_daily_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def print(self, *args, **kwargs):
print(*args, **kwargs)

def archive_data_to_temp_tables(self):
""" Save data to temporary tables and delete it from normal tables."""
"""Save data to temporary tables and delete it from normal tables."""
self.delete_temp_tables()

cursor = connection.cursor()
Expand All @@ -99,23 +99,23 @@ def archive_data_to_temp_tables(self):
self.delete_data_from_base_tables()

def delete_temp_tables(self):
""" Delete temporary tables."""
"""Delete temporary tables."""
cursor = connection.cursor()
cursor.execute("DROP TABLE IF EXISTS temporary_product")
cursor.execute("DROP TABLE IF EXISTS temporary_region")
cursor.execute("DROP TABLE IF EXISTS temporary_rate")
cursor.execute("DROP TABLE IF EXISTS temporary_adjustment")

def delete_data_from_base_tables(self):
""" Delete current data."""
"""Delete current data."""
cursor = connection.cursor()
cursor.execute("DELETE FROM ratechecker_product")
cursor.execute("DELETE FROM ratechecker_region")
cursor.execute("DELETE FROM ratechecker_rate")
cursor.execute("DELETE FROM ratechecker_adjustment")

def reload_old_data(self):
""" Move data from temporary tables back into the base tables."""
"""Move data from temporary tables back into the base tables."""
cursor = connection.cursor()
cursor.execute(
"INSERT INTO ratechecker_product "
Expand Down
4 changes: 2 additions & 2 deletions ratechecker/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


class Product(models.Model):
""" Loan Product. """
"""Loan Product."""

FIXED = "FIXED"
ARM = "ARM"
Expand Down Expand Up @@ -130,7 +130,7 @@ class Adjustment(models.Model):


class Region(models.Model):
""" This table maps regions to states. """
"""This table maps regions to states."""

region_id = models.IntegerField(db_index=True)
state_id = USStateField()
Expand Down
4 changes: 2 additions & 2 deletions ratechecker/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,12 +435,12 @@ def test_set_lock_max_min(self):
self.assertEqual(mock_data["min_lock"], locks[key]["minval"])

def test_rate_checker__no_args(self):
"""... when no parameters provided """
"""... when no parameters provided"""
response = self.client.get(self.url, {})
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)

def test_rate_checker__valid(self):
"""... when valid parameters are provided """
"""... when valid parameters are provided"""
params = {
"state": "DC",
"loan_purpose": "PURCH",
Expand Down
10 changes: 5 additions & 5 deletions ratechecker/tests/test_views_rate_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ def setUp(self):
adjustment.save()

def initialize_params(self, values={}):
""" a helper method to init params """
"""a helper method to init params"""
self.params = Object
self.params.state = values.get("state", "DC")
self.params.loan_purpose = values.get("loan_purpose", "PURCH")
Expand All @@ -521,15 +521,15 @@ def initialize_params(self, values={}):
self.params.io = 0

def test_get_rates__no_results(self):
""" ... get_rates with a valid state for which there's no data."""
"""... get_rates with a valid state for which there's no data."""
self.initialize_params({"state": "IL"})
result = get_rates(self.params.__dict__, return_fees=True)
self.assertFalse(result["data"])
self.assertFalse(result["timestamp"])
self.assertFalse("fees" in result)

def test_get_rates__rate_structure(self):
""" ... get_rates, different values for rate_structure param."""
"""... get_rates, different values for rate_structure param."""
self.initialize_params()
result = get_rates(self.params.__dict__)
self.assertTrue(result)
Expand Down Expand Up @@ -559,7 +559,7 @@ def test_get_rates__rate_structure(self):
self.assertTrue(result["timestamp"])

def test_get_rates__loan_type(self):
""" diff values for loan_type param."""
"""diff values for loan_type param."""
# actually only HighBalance ones
self.initialize_params(
{
Expand All @@ -584,7 +584,7 @@ def test_get_rates__plan_selection_logic(self):
self.assertEqual(result["data"]["2.005"], 1)

def test_get_rates__data_load_testing(self):
""" ... check that factor = -1 is applied to the results."""
"""... check that factor = -1 is applied to the results."""
self.initialize_params()
self.params.state = "MD"
self.params.institution = "Institution 8"
Expand Down
2 changes: 1 addition & 1 deletion ratechecker/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


def get_rates(params_data, data_load_testing=False, return_fees=False):
""" params_data is a method parameter of type RateCheckerParameters."""
"""params_data is a method parameter of type RateCheckerParameters."""

# the precalculated results are done by favoring negative points over
# positive ones, and the API does the opposite
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

install_requires = [
"beautifulsoup4>=4.5.0,<4.9",
"Django>=1.11,<3.2",
"Django>=1.11,<3.3",
"django-cors-headers",
"dj-database-url>=0.4.2,<1",
"django-localflavor>=1.1,<3.1",
Expand Down
5 changes: 3 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tox]
skipsdist=True
envlist=lint,py{36}-dj{22,31}
envlist=lint,py{36}-dj{22,32}

[testenv]
install_command=pip install -e ".[testing]" -U {opts} {packages}
Expand All @@ -12,10 +12,11 @@ commands=
basepython=
py36: python3.6
py38: python3.8

deps=
dj22: Django>=2.2,<2.3
dj31: Django>=3.1,<3.2
dj32: Django>=3.2,<3.3

[testenv:lint]
recreate=False
Expand Down

0 comments on commit 424250e

Please sign in to comment.