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

Repo consistency #765

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
2e3dedb
Removed black, isort and flake8, then added ruff
fritzbrand Oct 15, 2024
fdd376e
Added ignores for all issues reported by ruff
fritzbrand Oct 15, 2024
3b07007
Loop control variable 'content' not used within loop body
fritzbrand Oct 16, 2024
c1cf803
Possible hardcoded password assigned to argument
fritzbrand Oct 16, 2024
00ff0e7
Unnecessary 'list' comprehension (rewrite as a 'set' comprehension)
fritzbrand Oct 16, 2024
e69943c
Use a single 'with' statement with multiple contexts instead of neste…
fritzbrand Oct 16, 2024
6727967
Import block is un-sorted or un-formatted
fritzbrand Oct 16, 2024
5c32e5f
Use 'key in dict' instead of 'key in dict.keys()
fritzbrand Oct 16, 2024
7a2996d
Dictionary key literal repeated
fritzbrand Oct 16, 2024
e5fb751
Use 'is' and 'is not' for type comparisons, or 'isinstance()' for isi…
fritzbrand Oct 16, 2024
95ed4db
Use ternary operator instead of 'if'-'else'-block
fritzbrand Oct 16, 2024
357c22a
Unnecessary generator (rewrite as a 'set' comprehension)
fritzbrand Oct 16, 2024
2878459
It's okay to have hardcoded passwords in tests
fritzbrand Oct 16, 2024
5b9c368
Do not use mutable data structures for argument defaults
fritzbrand Oct 16, 2024
515f377
Unnecessary open mode parameters
fritzbrand Oct 16, 2024
7cedbe4
Use a single 'if' statement instead of nested 'if' statements
fritzbrand Oct 16, 2024
afe0705
Within an 'except' clause, raise exceptions with 'raise ... from err'…
fritzbrand Oct 16, 2024
17fc24b
B005: Using '.strip()' with multi-character strings is misleading
fritzbrand Oct 16, 2024
15d44f1
S311 - Standard pseudo-random generators are not suitable for cryptog…
fritzbrand Oct 16, 2024
1912a68
Updated CI config
fritzbrand Oct 16, 2024
e4303a3
Updated CI config
fritzbrand Oct 16, 2024
cf66ce2
Merge branch 'repo-consistency' of https://github.com/praekeltfoundat…
fritzbrand Oct 16, 2024
d4564fa
Updated CI
fritzbrand Oct 16, 2024
0deb82f
Added ruff-specific rules, and added inline ignores for S105
fritzbrand Oct 24, 2024
148bf68
More ruff updates, and updated readme
fritzbrand Oct 24, 2024
ac07902
Use empty tuple instead of None
fritzbrand Oct 24, 2024
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
26 changes: 14 additions & 12 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,24 @@ jobs:
ports:
- 6379:6379
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.9.15
- uses: abatilo/[email protected]
with:
poetry-version: 1.4.2
python-version: 3.9
- uses: abatilo/actions-poetry@v3
- name: Install dependancies
run: |
poetry install
- name: Check formatting
# Lints/tests should always run, even if other lints/tests have failed.
if: success() || failure() && steps.install-deps.outcome == 'success'
run: |
poetry run ruff format --check
- name: Lint
if: success() || failure() && steps.install-deps.outcome == 'success'
run: |
poetry run black --check .
poetry run isort -c .
poetry run mypy .
poetry run flake8
- name: Test
poetry run ruff check
- name: Run tests
if: success() || failure() && steps.install-deps.outcome == 'success'
run: |
poetry run pytest
poetry run pytest -vv
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ poetry run python vaccine/worker.py

To run autoformatting and linting, run
```bash
poetry run black .
poetry run isort .
poetry run mypy .
poetry run flake8
poetry run ruff check
poetry run ruff format
```

To run the tests, run
Expand Down
4 changes: 2 additions & 2 deletions mqr/baseline_ussd.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Application(MidlineApplication):

async def state_start(self):
msisdn = normalise_phonenumber(self.inbound.from_addr)
urn = f"whatsapp:{msisdn.lstrip(' + ')}"
urn = f"whatsapp:{msisdn.removeprefix('+')}"

sms_mqr_contact = False

Expand Down Expand Up @@ -593,7 +593,7 @@ async def state_submit_data(self):

async def state_update_rapidpro_contact(self):
msisdn = normalise_phonenumber(self.inbound.from_addr)
urn = f"whatsapp:{msisdn.lstrip(' + ')}"
urn = f"whatsapp:{msisdn.removeprefix('+')}"

async with get_rapidpro() as session:
for i in range(3):
Expand Down
4 changes: 2 additions & 2 deletions mqr/midline_ussd.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async def process_message(self, message):
if message.session_event == Message.SESSION_EVENT.CLOSE:
self.user.session_id = None
msisdn = normalise_phonenumber(self.user.addr)
urn = f"whatsapp:{msisdn.lstrip(' + ')}"
urn = f"whatsapp:{msisdn.removeprefix('+')}"

async with get_rapidpro() as session:
for i in range(3):
Expand Down Expand Up @@ -523,7 +523,7 @@ async def state_likelihood_of_following_schedule(self):

async def state_update_rapidpro_contact_midline(self):
msisdn = normalise_phonenumber(self.inbound.from_addr)
urn = f"whatsapp:{msisdn.lstrip(' + ')}"
urn = f"whatsapp:{msisdn.removeprefix('+')}"

async with get_rapidpro() as session:
for i in range(3):
Expand Down
26 changes: 13 additions & 13 deletions mqr/tests/test_baseline_ussd.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@ async def rapidpro_mock():
@app.route("/api/v2/contacts.json", methods=["GET"])
def get_contact(request):
tstate.requests.append(request)
if tstate.errormax:
if tstate.errors < tstate.errormax:
tstate.errors += 1
return response.json({}, status=500)
if tstate.errormax and tstate.errors < tstate.errormax:
tstate.errors += 1
return response.json({}, status=500)

contacts = []
urn = request.args.get("urn")
Expand Down Expand Up @@ -71,7 +70,7 @@ def start_flow(request):
async with run_sanic(app) as server:
url = config.RAPIDPRO_URL
config.RAPIDPRO_URL = f"http://{server.host}:{server.port}"
config.RAPIDPRO_TOKEN = "testtoken"
config.RAPIDPRO_TOKEN = "testtoken" # noqa: S105 - Fake password/token for test purposes
server.tstate = tstate
yield server
config.RAPIDPRO_URL = url
Expand All @@ -88,19 +87,20 @@ async def eventstore_mock():
@app.route("/api/v1/mqrbaselinesurvey/", methods=["POST"])
def valid_baseline_survey(request):
tstate.requests.append(request)
if tstate.errormax:
if tstate.errors < tstate.errormax:
tstate.errors += 1
return response.json({}, status=500)
if tstate.errormax and tstate.errors < tstate.errormax:
tstate.errors += 1
return response.json({}, status=500)
return response.json({})

@app.route("/api/v1/mqrbaselinesurvey/27820001003/", methods=["GET"])
def get_baseline_survey_not_found(request):
tstate.requests.append(request)
if tstate.not_found_errormax:
if tstate.not_found_errors < tstate.not_found_errormax:
tstate.not_found_errors += 1
return response.json({}, status=500)
if (
tstate.not_found_errormax
and tstate.not_found_errors < tstate.not_found_errormax
):
tstate.not_found_errors += 1
return response.json({}, status=500)
return response.json({"detail": "Not found."}, status=404)

@app.route("/api/v1/mqrbaselinesurvey/27820001004/", methods=["GET"])
Expand Down
2 changes: 1 addition & 1 deletion mqr/tests/test_midline_ussd.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def start_flow(request):
async with run_sanic(app) as server:
url = config.RAPIDPRO_URL
config.RAPIDPRO_URL = f"http://{server.host}:{server.port}"
config.RAPIDPRO_TOKEN = "testtoken"
config.RAPIDPRO_TOKEN = "testtoken" # noqa: S105 - Fake password/token for test purposes
server.tstate = tstate
yield server
config.RAPIDPRO_URL = url
Expand Down
Loading