Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'release-0.9.x' into release-0.10.x
- Loading branch information
Showing
4 changed files
with
81 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from __future__ import unicode_literals | ||
|
||
from django.contrib.auth.models import User | ||
from django.db import models | ||
|
||
from djblets.testing.testcases import TestCase | ||
from djblets.webapi.models import BaseWebAPIToken | ||
from kgb import SpyAgency | ||
|
||
|
||
class WebAPIToken(BaseWebAPIToken): | ||
my_field = models.BooleanField(default=False) | ||
|
||
|
||
class WebAPITokenManagerTests(SpyAgency, TestCase): | ||
def setUp(self): | ||
super(WebAPITokenManagerTests, self).setUp() | ||
|
||
self.user = User.objects.create(username='test-user') | ||
self.spy_on(WebAPIToken.save, call_original=False) | ||
|
||
def test_generate_token_with_defaults(self): | ||
"""Testing WebAPITokenManager.generate_token with default arguments""" | ||
webapi_token = WebAPIToken.objects.generate_token(self.user) | ||
|
||
self.assertEqual(webapi_token.user, self.user) | ||
self.assertEqual(webapi_token.policy, {}) | ||
self.assertEqual(webapi_token.note, '') | ||
self.assertEqual(webapi_token.my_field, False) | ||
self.assertIsNotNone(webapi_token.token) | ||
|
||
def test_generate_token_with_custom_field(self): | ||
"""Testing WebAPITokenManager.generate_token with custom field""" | ||
webapi_token = WebAPIToken.objects.generate_token(self.user, | ||
my_field=True) | ||
|
||
self.assertEqual(webapi_token.my_field, True) |