Skip to content

Commit

Permalink
FS-2689: Change maximum line length to 120 (#68)
Browse files Browse the repository at this point in the history
* FS-2689: Change maximum line length to 120

- Add flake8 argument for 120 line length
- Remove black argument for line length

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
tferns and pre-commit-ci[bot] authored May 10, 2023
1 parent e7a5782 commit 463acd4
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ repos:
- id: black
language_version: python3
args:
- --line-length=79
- --experimental-string-processing
- repo: https://github.com/PyCQA/flake8
rev: 3.9.2
hooks:
- id: flake8
args:
- --max-line-length=120
- --ignore=E203,W503
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.2.0
Expand Down
4 changes: 3 additions & 1 deletion core/data_operations/round_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

shared_cof_r2_data = {
"fund_id": "47aef2f5-3fcb-4d45-acb5-f0152b5f03c4",
"prospectus": "https://www.gov.uk/government/publications/community-ownership-fund-prospectus", # noqa
"prospectus": ( # noqa
"https://www.gov.uk/government/publications/community-ownership-fund-prospectus"
),
"privacy_notice": "https://www.gov.uk/government/publications/community-ownership-fund-privacy-notice/community-ownership-fund-privacy-notice", # noqa
"contact_details": {
"phone": "",
Expand Down
7 changes: 2 additions & 5 deletions core/fund_round_dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,14 @@ def get_all(self):
def search_by_round_short_name(self, round_short_name, fund):

fund_round_list = [
round
for round in self.get_all()
if round["fund_id"] == fund.get("id")
round for round in self.get_all() if round["fund_id"] == fund.get("id")
]

return next(
(
round
for round in fund_round_list
if str.upper(round["short_name"])
== str.upper(round_short_name)
if str.upper(round["short_name"]) == str.upper(round_short_name)
),
None,
)
13 changes: 3 additions & 10 deletions core/rounds.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,13 @@ def get_round(fund_id: str, round_id: str):
use_short_name = short_name_arg and strtobool(short_name_arg)
if use_short_name:
fund = get_fund(fund_id)[0]
round_search = round_data.ROUNDS_DAO.search_by_round_short_name(
round_id, fund
)
round_search = round_data.ROUNDS_DAO.search_by_round_short_name(round_id, fund)
else:
round_search = round_data.ROUNDS_DAO.get_one(
fund_id, round_id, language
)
round_search = round_data.ROUNDS_DAO.get_one(fund_id, round_id, language)
if isinstance(round_search, dict):
return round_search, 200
else:
return {
"code": 404,
"message": (
f"round_id : {round_id} in fund_id : {fund_id} cannot be"
" found."
),
"message": f"round_id : {round_id} in fund_id : {fund_id} cannot be found.",
}, 404
24 changes: 6 additions & 18 deletions tests/test_cof_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ def test_get_cof_r2w3(mocker, monkeypatch):
"core.rounds.request",
MockRequest_en(),
)
result = get_round(
CommonConfig.COF_FUND_ID, CommonConfig.COF_ROUND_2_W3_ID
)
result = get_round(CommonConfig.COF_FUND_ID, CommonConfig.COF_ROUND_2_W3_ID)

assert "Round 2 Window 3" == result[0]["title"]
assert "Monday to Friday" == result[0]["support_availability"]["days"]
Expand All @@ -34,13 +32,9 @@ def test_get_cof_r2w3_welsh(mocker, monkeypatch):
"core.rounds.request",
MockRequest_cy(),
)
result = get_round(
CommonConfig.COF_FUND_ID, CommonConfig.COF_ROUND_2_W3_ID
)
result = get_round(CommonConfig.COF_FUND_ID, CommonConfig.COF_ROUND_2_W3_ID)
assert "Cylch 2 Cyfnod Cynnig 3" == result[0]["title"]
assert (
"Dydd Llun i ddydd Gwener" == result[0]["support_availability"]["days"]
)
assert "Dydd Llun i ddydd Gwener" == result[0]["support_availability"]["days"]


def test_get_cof_r2w2(mocker, monkeypatch):
Expand Down Expand Up @@ -80,21 +74,15 @@ def test_override_fields(monkeypatch):


def test_force_open(monkeypatch):
monkeypatch.setattr(
"core.data_operations.round_data.Config.FORCE_OPEN", "True"
)
monkeypatch.setattr("core.data_operations.round_data.Config.FORCE_OPEN", "True")
result = get_round_data("en")
assert (
"2022-01-01 12:00:00" == result[1]["opens"]
), "opens field not changed"
assert "2022-01-01 12:00:00" == result[1]["opens"], "opens field not changed"
assert "R2W3" == result[1]["short_name"], "other field changed"


def test_override_fields_with_force_open(monkeypatch):
monkeypatch.setenv("force_opens_R2W3", "changed")
monkeypatch.setattr(
"core.data_operations.round_data.Config.FORCE_OPEN", "True"
)
monkeypatch.setattr("core.data_operations.round_data.Config.FORCE_OPEN", "True")
result = get_round_data("en")
assert "changed" == result[1]["opens"], "opens field not changed"
assert "R2W3" == result[1]["short_name"], "other field changed"
14 changes: 3 additions & 11 deletions tests/test_funds.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,12 @@ def test_get_fund_by_short_name(client, load_test_data):
host_url = request.host_url
expected_data = TEST_FUND_ONE

url = (
host_url
+ "funds/fb986cdc-8e02-477a-a7e0-41cf19dd7675?use_short_name=false"
)
url = host_url + "funds/fb986cdc-8e02-477a-a7e0-41cf19dd7675?use_short_name=false"
api_response_json = client.get(url).json

assert api_response_json == expected_data

url = (
host_url
+ "funds/fb986cdc-8e02-477a-a7e0-41cf19dd7675?use_short_name=true"
)
url = host_url + "funds/fb986cdc-8e02-477a-a7e0-41cf19dd7675?use_short_name=true"
response = client.get(url)

assert 404 == response.status_code
Expand All @@ -122,9 +116,7 @@ def test_get_round_by_short_name(client, load_test_data):
url = host_url + "funds/FUND1/rounds/R2W3?use_short_name=true"
api_response_json = client.get(url).json

assert api_response_json.get("short_name") == expected_data[0].get(
"short_name"
)
assert api_response_json.get("short_name") == expected_data[0].get("short_name")
assert api_response_json.get("fund_id") == expected_data[0].get("fund_id")
assert api_response_json.get("id") == expected_data[0].get("id")
assert api_response_json.get("title") == expected_data[0].get("title")
Expand Down

0 comments on commit 463acd4

Please sign in to comment.