Skip to content

Conversation

@paigewilliams
Copy link
Contributor

asana task

First pass at upping the test coverage. Definitely still more room for improvement, but my brain is a bit tapped out on writing tests.

I removed /tests/ from coverage metrics, which were falsely inflating our coverage number. After these tests coverage is now at 83%.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR significantly increases test coverage from the previous baseline to 83% by adding comprehensive tests across multiple modules. The PR also includes important bug fixes and code quality improvements in production code, including fixing Http404 exception handling, adding proper HTTP status codes to JSON responses, and renaming functions to follow Python naming conventions.

Key Changes:

  • Added extensive test coverage for views, models, admin, and context processors
  • Fixed bug where Http404 was returned instead of raised in download_media_file
  • Added missing status parameter to JsonResponse calls for proper HTTP status code reporting
  • Refactored getPlacesGeoJSON to get_places_geojson to follow snake_case convention

Reviewed changes

Copilot reviewed 12 out of 13 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
TEKDB/.coveragerc Excludes /tests/ directory from coverage metrics to prevent false inflation
TEKDB/explore/views.py Fixed Http404 bug (changed from return to raise) and refactored media file download logic
TEKDB/explore/tests/test_views.py Added comprehensive tests for home, about, help, explore views, search functionality, media downloads, and export features
TEKDB/explore/tests/test_context_processors.py Added tests for explore context processor with various configuration scenarios
TEKDB/TEKDB/views.py Added status codes to JsonResponse, renamed getPlacesGeoJSON to get_places_geojson, fixed whitespace issues
TEKDB/TEKDB/tests/test_views.py Refactored ImportTest to ImportDatabaseTest, added tests for failed imports and GeoJSON endpoint
TEKDB/TEKDB/tests/test_models.py Added extensive tests for model methods including relationships, data, links, and keyword search functionality
TEKDB/TEKDB/tests/test_context_processors.py Added tests for search settings and map default context processors
TEKDB/TEKDB/tests/test_admin.py Added comprehensive tests for admin forms, permissions, and bulk upload functionality
TEKDB/TEKDB/models.py Removed commented-out code and cleaned up whitespace
TEKDB/TEKDB/context_processors.py Simplified error handling by removing unnecessary try-except wrapper
TEKDB/TEKDB/admin.py Added Meta classes to CitationsForm and ResourcesForm, updated function call to use snake_case naming
TEKDB/TEKDB/tests/test_files/test_wrong_import.txt Added test fixture file for testing incorrect file type imports

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

else:
obj = None

media = obj.media()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if obj is None obj.media() throws an error

)
return response
else:
return Http404
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we either want to raise Http404 or return HttpResponseNotFound

docs


places_geojson = get_places_geojson(self.import_request)

### 2025-05-09: No one has any idea what a 'placeMap' is.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't find having these left in super helpful


def changelist_view(self, request, extra_context=None):
from .views import getPlacesGeoJSON
from .views import get_places_geojson
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I renamed the function to snake case instead of camel case to follow convention.



class CitationsForm(forms.ModelForm):
class Meta:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was getting an error with Meta missing

if not request.method == "POST":
status_code = 405
status_message = "Request method not allowed. Must be a post."
return JsonResponse(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

first arg is data so passing status arg to get response.status in tests

omit =
*/migrations/*
*/migrations/*
*/tests/*
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removing tests from coverage stats

@paigewilliams paigewilliams merged commit e470e9f into main Dec 9, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants