Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 7, 2025

Problem

Issue #660 highlighted that breaking changes in the social-core storage API can go unnoticed until they cause runtime failures in production. Specifically, social-core PR #986 introduced a breaking change in the OpenID storage API that raised NotImplementedError when calling get_association():

NotImplementedError: Implement in subclass
  File "social_core/storage.py", line 256, in get_association
    raise NotImplementedError("Implement in subclass")

The issue occurred because:

  1. OpenIdStore.getAssociation() calls self.assoc.oids()
  2. AssociationMixin.oids() calls cls.get(**kwargs)
  3. If get() wasn't properly implemented, it raised NotImplementedError

Solution

This PR adds comprehensive integration tests for the storage layer to prevent similar issues in the future. The new test file tests/test_storage_integration.py includes:

Test Coverage

1. Full OpenID Workflow Tests (TestStorageIntegration)

  • Complete association lifecycle (store, retrieve, remove)
  • Expired association handling and cleanup
  • Multiple associations per server
  • Nonce creation and replay prevention
  • Timestamp skew validation

2. Critical API Integration Tests (TestAssociationMixinIntegration)

  • The oids() method that was the breaking point
  • The get() method implementation
  • Handle-based filtering

3. Nonce Storage Tests (TestNonceMixinIntegration)

  • Nonce creation, retrieval, and deletion

Key Features

End-to-end testing - Tests the complete call stack from OpenIdStore down to Django ORM, not just individual methods
Real API usage - Uses actual social_core.store.OpenIdStore instead of mocks to catch integration issues
Time-aware - Uses proper timestamps to test association expiration logic correctly
Well-documented - Includes detailed explanation of the issue and what each test validates

Test Results

  • ✅ All 11 new integration tests pass
  • ✅ All 59 existing tests still pass
  • ✅ Total: 70 tests passing
  • ✅ Passes all linting checks

These tests will catch breaking changes in social-core's storage API before they reach production, addressing the core issue raised in #176.

Fixes #660

Original prompt

This section details on the original issue you should resolve

<issue_title>Add integration tests for storage</issue_title>
<issue_description>python-social-auth/social-core#986 introduced breaking change in (OpenID) storage API and it went unnoticed into the release. I'm now reverting it in python-social-auth/social-core#1020.

If social-app-django would have integartion tests for these, the error would be noticed earlier.

Exception stack trace:

NotImplementedError: Implement in subclass
  File "django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
  File "django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "django/views/decorators/cache.py", line 80, in _view_wrapper
    response = view_func(request, *args, **kwargs)
  File "django/views/decorators/http.py", line 64, in inner
    return func(request, *args, **kwargs)
  File "weblate/accounts/views.py", line 1330, in social_auth
    return do_auth(request.backend, redirect_name=REDIRECT_FIELD_NAME)
  File "social_core/actions.py", line 35, in do_auth
    return backend.start()
  File "social_core/backends/base.py", line 33, in start
    if self.uses_redirect():
  File "social_core/backends/open_id.py", line 244, in uses_redirect
    return self.openid_request().shouldSendRedirect()
  File "social_core/backends/open_id.py", line 249, in openid_request
    return self.consumer().begin(url_add_parameters(self.openid_url(), params))
  File "openid/consumer/consumer.py", line 360, in begin
    return self.beginWithoutDiscovery(service, anonymous)
  File "openid/consumer/consumer.py", line 383, in beginWithoutDiscovery
    auth_req = self.consumer.begin(service)
  File "openid/consumer/consumer.py", line 611, in begin
    assoc = self._getAssociation(service_endpoint)
  File "openid/consumer/consumer.py", line 1179, in _getAssociation
    assoc = self.store.getAssociation(endpoint.server_url)
  File "social_core/store.py", line 39, in getAssociation
    for assoc_id, association in self.assoc.oids(server_url, handle):
  File "social_core/storage.py", line 229, in oids
    for assoc in cls.get_association(**kwargs)
  File "social_core/storage.py", line 256, in get_association
    raise NotImplementedError("Implement in subclass")
```</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>
Fixes #660

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Add integration tests for storage Add integration tests for storage layer to catch breaking changes in social-core API Oct 7, 2025
Copilot AI requested a review from nijel October 7, 2025 10:58
Copilot finished work on behalf of nijel October 7, 2025 10:58
@codecov
Copy link

codecov bot commented Oct 7, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.21%. Comparing base (10c80e2) to head (483f1aa).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #811      +/-   ##
==========================================
+ Coverage   92.35%   93.21%   +0.86%     
==========================================
  Files          41       42       +1     
  Lines        1203     1341     +138     
  Branches       62       63       +1     
==========================================
+ Hits         1111     1250     +139     
+ Misses         68       67       -1     
  Partials       24       24              
Flag Coverage Δ
unittests 93.21% <100.00%> (+0.86%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@nijel nijel marked this pull request as ready for review October 7, 2025 11:20
@nijel nijel merged commit 47dd0a9 into master Oct 7, 2025
18 checks passed
@nijel nijel deleted the copilot/fix-176a377a-bdc6-43d9-9874-030016d18fb7 branch October 7, 2025 11:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Add integration tests for storage

2 participants