Fix URL validation test failures by enabling proper mocking#89
Conversation
Co-authored-by: alexeygrigorev <875246+alexeygrigorev@users.noreply.github.com>
Co-authored-by: alexeygrigorev <875246+alexeygrigorev@users.noreply.github.com>
|
@copilot I don't like this approach. Can we not mock it? |
Co-authored-by: alexeygrigorev <875246+alexeygrigorev@users.noreply.github.com>
You're absolutely right! I've fixed it with proper mocking instead of skipping validation. The issue was that the I changed the function to use Commit: c6d2d74 Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
This PR fixes failing CI tests caused by URL validation attempting actual HTTP requests during test execution, which failed due to network connectivity issues.
Problem
The test
test_submit_homework_with_all_fieldsinHomeworkDetailViewTestswas failing because:https://httpbin.org/status/200validate_url_200validator makes an actual HTTP request to verify the URL returns a 200 statussubmission.homework_linkto contain the URL, but it'sNonedue to validation failureRoot Cause
The existing
@mock.patch("requests.get")decorator in the test wasn't working because thevalidate_url_200function hadget_method=requests.getas a default parameter. In Python, default parameter values are evaluated at function definition time, not at call time, which prevented the mock from taking effect.Solution
Modified the
validate_url_200function incourses/validators/custom_url_validators.pyto enable proper mocking:This change ensures that
requests.getis referenced at runtime (when the function is called), not at definition time, allowing@mock.patch("requests.get")to work correctly.Key Features
Results
✅ The original failing test
test_submit_homework_with_all_fieldspasses✅ URL validation unit tests continue to work correctly
✅ All homework submission tests pass
✅ Validation error tests still function as intended
This fix eliminates the flaky test behavior caused by external network dependencies while maintaining comprehensive test coverage for the URL validation functionality through proper mocking.
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.