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

Setup codecov and add coverage for CSV branch import. #12

Merged
merged 2 commits into from
Jan 2, 2024
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
15 changes: 12 additions & 3 deletions .github/workflows/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,19 @@ jobs:
echo 'MAPIT_DB_HOST: localhost' >> conf/general.yml
echo 'DJANGO_SECRET_KEY: secret' >> conf/general.yml

- name: Run migrations
env:
SECRET_KEY: 'secret'
DATABASE_URL: 'postgis://postgres:password@localhost/mapit'
run: python manage.py migrate

- name: Run tests
- name: Run tests with coverage
env:
SECRET_KEY: 'secret'
DATABASE_URL: 'postgis://postgres:password@localhost/mapit'
COBRAND: 'cobrand_hackney'
run: python manage.py test
run: coverage run manage.py test

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
4 changes: 4 additions & 0 deletions mapit_labour/importers.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ def handle_rows(self, csv: DictReader):
parents = self._load_parents(parent_gss_codes)
branch_count = len(branches)
for i, branch in enumerate(branches.values(), start=1):
created_area_for_branch = False
self.update_progress(f"Working on area {i} of {branch_count}")
parent_area = parents.get(branch["parent_gss_code"])

Expand Down Expand Up @@ -218,6 +219,7 @@ def handle_rows(self, csv: DictReader):
parent_area=parent_area,
)
self.created += 1
created_area_for_branch = True

a.codes.update_or_create(
type=gss_codetype, defaults={"code": branch["area_gss"]}
Expand Down Expand Up @@ -262,6 +264,8 @@ def handle_rows(self, csv: DictReader):
f"Branch {branch['area_id']} doesn't overlap with parent area ({branch['parent_gss_code']}), not creating."
)
a.delete()
if created_area_for_branch:
self.created -= 1
elif area_area < 50000:
self.warnings.append(
f"Area {a.id} (branch {branch['area_id']}) has a small geographic area ({int(area_area)} ㎡)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def handle_label(self, label: str, **options):
)
if result["error"]:
raise CommandError(result["error"])
print(f"Created: {result['created']}\nUpdated: {result['updated']}")
self.stdout.write(f"Created: {result['created']}\nUpdated: {result['updated']}")
if result["warnings"]:
print(f"Warnings: {len(result['warnings'])}")
print("\n".join(result["warnings"]))
self.stdout.write(f"Warnings: {len(result['warnings'])}")
self.stdout.write("\n".join(result["warnings"]))
Empty file.
Loading
Loading