Skip to content

Commit

Permalink
Merge e4c84ae into 59aa5cc
Browse files Browse the repository at this point in the history
  • Loading branch information
jnation3406 committed Jun 6, 2019
2 parents 59aa5cc + e4c84ae commit 7c3a004
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
Expand Up @@ -50,6 +50,3 @@ def handle(self, *args, **options):
token, created = Token.objects.get_or_create(user=user)
token.delete()
Token.objects.create(user=user, key=options['token'])
sys.exit(0)


21 changes: 21 additions & 0 deletions observation_portal/accounts/tests.py
@@ -1,12 +1,15 @@
from django.test import TestCase
from django.utils import timezone
from django.contrib.auth.models import User
from django.core.management import call_command
from datetime import timedelta
from mixer.backend.django import mixer
from oauth2_provider.models import Application, AccessToken
from unittest.mock import patch
from rest_framework.authtoken.models import Token

from observation_portal.accounts.models import Profile
from observation_portal.proposals.models import Proposal


class TestArchiveBearerToken(TestCase):
Expand Down Expand Up @@ -52,3 +55,21 @@ def test_quota_is_zero(self):
@patch('django.core.cache.cache.get', return_value=([1504903107.1322677, 1504903106.6130717]))
def test_quota_used(self, cache_mock):
self.assertEqual(self.profile.api_quota['used'], 2)


class TestInitCredentialsCommand(TestCase):
def test_credentials_are_setup(self):
self.assertEqual(User.objects.count(), 0)
self.assertEqual(Proposal.objects.count(), 0)
call_command('init_e2e_credentials', '-pMyProposal', '-umy_user', '-tmy_token')

self.assertEqual(User.objects.count(), 1)
user = User.objects.all()[0]
self.assertEqual(user.username, 'my_user')

self.assertEqual(Proposal.objects.count(), 1)
proposal = Proposal.objects.all()[0]
self.assertEqual(proposal.id, 'MyProposal')

token = Token.objects.get(user=user)
self.assertEqual(token.key, 'my_token')

0 comments on commit 7c3a004

Please sign in to comment.