-
Notifications
You must be signed in to change notification settings - Fork 819
Make Resource Owner model configurable #459
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| # -*- coding: utf-8 -*- | ||
| # Generated by Django 1.10.4 on 2016-12-21 19:06 | ||
| from __future__ import unicode_literals | ||
|
|
||
| from django.conf import settings | ||
| from django.db import migrations, models | ||
| import django.db.models.deletion | ||
| from oauth2_provider.settings import oauth2_settings | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ('oauth2_provider', '0004_auto_20160525_1623'), | ||
| migrations.swappable_dependency(oauth2_settings.RESOURCE_OWNER_MODEL), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AlterField( | ||
| model_name='accesstoken', | ||
| name='user', | ||
| field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to=oauth2_settings.RESOURCE_OWNER_MODEL), | ||
| ), | ||
| migrations.AlterField( | ||
| model_name='grant', | ||
| name='user', | ||
| field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=oauth2_settings.RESOURCE_OWNER_MODEL), | ||
| ), | ||
| migrations.AlterField( | ||
| model_name='refreshtoken', | ||
| name='user', | ||
| field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=oauth2_settings.RESOURCE_OWNER_MODEL), | ||
| ), | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,10 @@ | ||
| from django.conf import settings | ||
| from django.db import models | ||
| from oauth2_provider.models import AbstractApplication | ||
|
|
||
|
|
||
| class TestApplication(AbstractApplication): | ||
| custom_field = models.CharField(max_length=255) | ||
|
|
||
| class TestResourceOwner(models.Model): | ||
| user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name="resource_owners") |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -126,3 +126,5 @@ | |
| }, | ||
| } | ||
| } | ||
|
|
||
| OAUTH2_PROVIDER_RESOURCE_OWNER_MODEL = 'auth.User' | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,16 +7,20 @@ | |
| from django.test.utils import override_settings | ||
| from django.utils import timezone | ||
|
|
||
| from ..models import get_application_model, Grant, AccessToken, RefreshToken | ||
| from ..models import get_application_model, get_resource_owner_model | ||
| from ..models import Grant, AccessToken, RefreshToken | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These two lines can be combined. |
||
|
|
||
|
|
||
| Application = get_application_model() | ||
| ResourceOwnerModel = get_resource_owner_model() | ||
| UserModel = get_user_model() | ||
|
|
||
|
|
||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: This extra newline is not necessary. |
||
| class TestModels(TestCase): | ||
| def setUp(self): | ||
| self.user = UserModel.objects.create_user("test_user", "[email protected]", "123456") | ||
| self.resource_owner = self.user | ||
|
|
||
| def test_allow_scopes(self): | ||
| self.client.login(username="test_user", password="123456") | ||
|
|
@@ -29,7 +33,7 @@ def test_allow_scopes(self): | |
| ) | ||
|
|
||
| access_token = AccessToken( | ||
| user=self.user, | ||
| user=self.resource_owner, | ||
| scope='read write', | ||
| expires=0, | ||
| token='', | ||
|
|
@@ -88,15 +92,15 @@ def test_scopes_property(self): | |
| ) | ||
|
|
||
| access_token = AccessToken( | ||
| user=self.user, | ||
| user=self.resource_owner, | ||
| scope='read write', | ||
| expires=0, | ||
| token='', | ||
| application=app | ||
| ) | ||
|
|
||
| access_token2 = AccessToken( | ||
| user=self.user, | ||
| user=self.resource_owner, | ||
| scope='write', | ||
| expires=0, | ||
| token='', | ||
|
|
@@ -150,6 +154,7 @@ def test_expires_can_be_none(self): | |
| class TestAccessTokenModel(TestCase): | ||
| def setUp(self): | ||
| self.user = UserModel.objects.create_user("test_user", "[email protected]", "123456") | ||
| self.resource_owner = self.user | ||
|
|
||
| def test_str(self): | ||
| access_token = AccessToken(token="test_token") | ||
|
|
@@ -177,3 +182,12 @@ class TestRefreshTokenModel(TestCase): | |
| def test_str(self): | ||
| refresh_token = RefreshToken(token="test_token") | ||
| self.assertEqual("%s" % refresh_token, refresh_token.token) | ||
|
|
||
|
|
||
| @override_settings(OAUTH2_PROVIDER={'RESOURCE_OWNER_MODEL':'tests.TestResourceOwner'}) | ||
| class TestCustomResourceOwnerModel(TestCase): | ||
| def setUp(self): | ||
| self.user = UserModel.objects.create_user("test_user", "[email protected]", "123456") | ||
|
|
||
| def test_model(self): | ||
| self.user.resource_owners.all() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a comment explaining what you're testing here. |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/authorize/authorized