Skip to content

Commit a1e22b1

Browse files
authored
Update github actions workflow and tests (#36)
1 parent 4b456ae commit a1e22b1

File tree

6 files changed

+14
-6
lines changed

6 files changed

+14
-6
lines changed

.github/workflows/pull_request.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ on:
88
jobs:
99
test:
1010
runs-on: ubuntu-latest
11+
env:
12+
NOTIFY_API_KEY: ${{ secrets.DEV_NOTIFY_API_KEY }}
1113
steps:
1214
- uses: actions/checkout@v4
1315
- run: |
@@ -27,3 +29,5 @@ jobs:
2729
run: make install-dev
2830
- name: Running lint tests
2931
run: make lint
32+
- name: Running unit tests
33+
run: make test

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,6 @@ lint:
3333
test:
3434
poetry run ./scripts/run_tests.sh
3535

36+
3637
run-debug:
3738
poetry run functions-framework --target=send_email --debug

main.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,11 @@ def send_email(request: Request) -> Union[Tuple[str, int], Tuple[str, None]]:
179179
)
180180
return message, status_code
181181
except RequestException as error:
182-
# Type ignore: To be fixed, error may not have a response
183-
notify_error = error.response.json()["errors"][0] # type: ignore
184-
status_code = error.response.status_code # type: ignore
182+
notify_error = "Unknown Error"
183+
status_code = 500
184+
if error.response is not None:
185+
notify_error = error.response.json().get("errors", [{}])[0]
186+
status_code = error.response.status_code
185187
message = "notify request failed"
186188
log_error(
187189
message,
@@ -190,7 +192,6 @@ def send_email(request: Request) -> Union[Tuple[str, int], Tuple[str, None]]:
190192
status_code=status_code,
191193
)
192194
return message, status_code
193-
194195
if response.status_code == 204:
195196
return "no content", 204
196197

scripts/run_tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ function display_result {
2222

2323
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
2424

25-
pytest --cov=main --cov-report html --cov-fail-under=100 "$@"
25+
pytest --cov=main --cov-report html --cov-fail-under=100 "$@" --ignore=tests/test_integration.py
2626
display_result $? 3 "Unit tests"

tests/test_integration.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ class TestNotify:
1515
}
1616
}
1717

18+
# The following tests will not work as the Notify API key has been removed until a mock service can be introduced
19+
# (see https://github.com/ONSdigital/eq-submission-confirmation-consumer/pull/12)
1820
def test_successful(self, base_url, requests_session):
1921
res = requests_session.post(base_url, json=self.payload)
2022
assert res.status_code == 201

tests/test_main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def test_notify_response_connection_error(mock_request):
6464

6565
@responses.activate
6666
def test_notify_response_no_content_204(mock_request):
67-
responses.add(responses.POST, url, json={}, status=204)
67+
responses.add(responses.POST, url, status=204)
6868
response = send_email(mock_request)
6969
assert response == ("no content", 204)
7070

0 commit comments

Comments
 (0)