Fix null values on Token modified field.

This commit is contained in:
Yunfan Zhang 2018-07-10 11:13:27 -04:00
parent a7561ce527
commit e2ed24aef0
3 changed files with 25 additions and 2 deletions

View File

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.11 on 2018-07-10 14:02
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('main', '0042_v330_org_member_role_deparent'),
]
operations = [
migrations.AddField(
model_name='oauth2accesstoken',
name='modified',
field=models.DateTimeField(editable=False),
),
]

View File

@ -112,6 +112,10 @@ class OAuth2AccessToken(AbstractAccessToken):
default='write',
help_text=_('Allowed scopes, further restricts user\'s permissions. Must be a simple space-separated string with allowed scopes [\'read\', \'write\'].')
)
modified = models.DateTimeField(
editable=False,
auto_now=True
)
def is_valid(self, scopes=None):
valid = super(OAuth2AccessToken, self).is_valid(scopes)
@ -119,4 +123,3 @@ class OAuth2AccessToken(AbstractAccessToken):
self.last_used = now()
self.save(update_fields=['last_used'])
return valid

View File

@ -126,7 +126,7 @@ def test_oauth_token_create(oauth_application, get, post, admin):
reverse('api:o_auth2_application_token_list', kwargs={'pk': oauth_application.pk}),
{'scope': 'read'}, admin, expect=201
)
assert 'modified' in response.data
assert 'modified' in response.data and response.data['modified'] is not None
assert 'updated' not in response.data
token = AccessToken.objects.get(token=response.data['token'])
refresh_token = RefreshToken.objects.get(token=response.data['refresh_token'])