Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

378 fix northamptonshire council #412

Merged
merged 2 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
437 changes: 223 additions & 214 deletions poetry.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ setuptools = "*"
pytest-bdd = "*"
allure-pytest-bdd = "*"
pytest-xdist = {extras = ["psutil"], version = "*"}
pyhamcrest = "*"


[tool.poetry.scripts]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ Feature: Test each council output matches expected results in /outputs
| EastDevonDC |
| EastleighBoroughCouncil |
| EastLindseyDistrictCouncil |
| EastNorthamptonshireCouncil |
| EastRidingCouncil |
| EastSuffolkCouncil |
| ErewashBoroughCouncil |
Expand Down Expand Up @@ -67,6 +66,7 @@ Feature: Test each council output matches expected results in /outputs
| NorthLanarkshireCouncil |
| NorthLincolnshireCouncil |
| NorthNorfolkDistrictCouncil |
| NorthNorthamptonshireCouncil |
| NorthSomersetCouncil |
| NorthTynesideCouncil |
| NorthumberlandCouncil |
Expand Down
6 changes: 3 additions & 3 deletions uk_bin_collection/tests/input.json
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,11 @@
"wiki_name": "East Lindsey District Council",
"wiki_note": "Pass the house name/number in the house number parameter, wrapped in double quotes"
},
"EastNorthamptonshireCouncil": {
"NorthNorthamptonshireCouncil": {
"SKIP_GET_URL": "SKIP_GET_URL",
"uprn": "100031021317",
"url": "https://kbccollectiveapi-coll-api.e4ff.pro-eu-west-1.openshiftapps.com/wc-info/",
"wiki_name": "East Northamptonshire Council"
"url": "https://cms.northnorthants.gov.uk/bin-collection-search/calendarevents/100031021318/2023-10-17/2023-10-01",
"wiki_name": "North Northamptonshire Council"
},
"EastRidingCouncil": {
"SKIP_GET_URL": "SKIP_GET_URL",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
from jsonschema import validate, ValidationError

logging.basicConfig(level=logging.INFO, format='%(levelname)s - %(message)s')

def load_inputs_file(file_name):
cwd = os.getcwd()
Expand Down
8 changes: 6 additions & 2 deletions uk_bin_collection/tests/step_defs/test_validate_council.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
import pytest
import traceback
from pytest_bdd import scenario, given, when, then, parsers
from hamcrest import assert_that, equal_to

from step_helpers import file_handler
from uk_bin_collection.uk_bin_collection import collect_data

logging.basicConfig(level=logging.INFO, format='%(levelname)s - %(message)s')

@scenario("../features/validate_council_outputs.feature", "Validate Council Output")
def test_scenario_outline():
Expand Down Expand Up @@ -65,10 +67,11 @@ def scrape_step(context, council):
def validate_json_step(context):
try:
valid_json = file_handler.validate_json(context.parse_result)
assert valid_json is True
assert_that(valid_json, True)
except Exception as err:
logging.error(traceback.format_exc())
logging.info(f"Validate Output: {err}")
logging.info(f"JSON Output: {context.parse_result}")
raise (err)


Expand All @@ -79,8 +82,9 @@ def validate_output_step(context):
schema_result = file_handler.validate_json_schema(
context.parse_result, council_schema
)
assert schema_result is True
assert_that(schema_result, True)
except Exception as err:
logging.error(traceback.format_exc())
logging.info(f"Validate Output: {err}")
logging.info(f"JSON Output: {context.parse_result}")
raise (err)

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import hashlib
import math
import time
from datetime import datetime as dtm, timedelta

from uk_bin_collection.uk_bin_collection.common import *
from uk_bin_collection.uk_bin_collection.get_bin_data import \
AbstractGetBinDataClass


def myFunc(e):
return e['start']

class CouncilClass(AbstractGetBinDataClass):
"""
Concrete classes have to implement all abstract operations of the
base class. They can also override some operations with a default
implementation.
"""

def parse_data(self, page: str, **kwargs) -> dict:
data = {"bins": []}
uprn = kwargs.get("uprn")
check_uprn(uprn)
today = int(datetime.now().timestamp())*1000
dateforurl = datetime.now().strftime("%Y-%m-%d")
dateforurl2 = (datetime.now() + timedelta(days=42)).strftime("%Y-%m-%d")
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64)",
}
requests.packages.urllib3.disable_warnings()

# Get variables for workings
response = requests.get(
f"https://cms.northnorthants.gov.uk/bin-collection-search/calendarevents/{uprn}/{dateforurl}/{dateforurl2}",
headers=headers,
)
if response.status_code != 200:
raise ValueError("No bin data found for provided UPRN..")

json_response = json.loads(response.text)

output_dict = [x for x in json_response if int(''.join(filter(str.isdigit, x['start']))) >= today]

output_json = output_dict
output_json.sort(key=myFunc)

i = 0
while i < len(output_json):
sov = output_json[i]['title'].lower()
if 'recycling' in sov:
bin_type = "Recycling"
elif 'garden' in sov:
bin_type = "Garden"
elif 'refuse' in sov:
bin_type = "General"
else:
bin_type = "Unknown"
dateofbin = int(''.join(filter(str.isdigit, output_json[i]['start'])))
day = dtm.fromtimestamp(dateofbin/1000)
collection_data = {
"type": bin_type,
"collectionDate": day.strftime(date_format),
}
data["bins"].append(collection_data)
i += 1

return data
Loading