This repository has been archived by the owner on Sep 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #639 from cdosborn/fix-account-creation
Place upper limit on tas user validation, remove selected identity notion
- Loading branch information
Showing
23 changed files
with
192 additions
and
194 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,23 @@ | ||
from django.utils import timezone | ||
import factory | ||
from api.tests.factories.user_factory import UserFactory | ||
|
||
from core.models import AllocationSource, UserAllocationSource | ||
|
||
|
||
class AllocationSourceFactory(factory.DjangoModelFactory): | ||
name = factory.fuzzy.FuzzyText() | ||
compute_allowed = 168 | ||
start_date = factory.fuzzy.FuzzyDateTime(timezone.now()) | ||
end_date = None | ||
renewal_strategy = "default" | ||
|
||
class Meta: | ||
model = AllocationSource | ||
|
||
|
||
class UserAllocationSourceFactory(factory.DjangoModelFactory): | ||
allocation_source = factory.SubFactory(AllocationSourceFactory) | ||
user = factory.SubFactory(UserFactory) | ||
class Meta: | ||
model = UserAllocationSource |
Empty file.
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,44 @@ | ||
from django.test import TestCase, override_settings | ||
from django.urls import reverse | ||
from rest_framework.test import APIRequestFactory, force_authenticate | ||
import mock | ||
|
||
from api.v1.views import Profile | ||
from api.tests.factories import UserFactory | ||
from core.models import AtmosphereUser | ||
|
||
class ProfileTests(TestCase): | ||
@override_settings(AUTO_CREATE_NEW_ACCOUNTS=True) | ||
def test_external_accounts_are_created(self): | ||
""" | ||
Sanity check that configuration results in call to create_new_accounts. | ||
""" | ||
user = UserFactory() | ||
url = reverse('api:v1:profile') | ||
view = Profile.as_view() | ||
factory = APIRequestFactory() | ||
request = factory.get(url) | ||
force_authenticate(request, user=user) | ||
|
||
with mock.patch("api.v1.views.profile.create_new_accounts") as mock_create_new_accounts: | ||
response = view(request) | ||
mock_create_new_accounts.assert_called_once() | ||
|
||
@override_settings(AUTO_CREATE_NEW_ACCOUNTS=True) | ||
def test_external_accounts_are_not_created_for_invalid_user(self): | ||
""" | ||
Accounts are NOT created when when the user is invalid | ||
""" | ||
user = UserFactory() | ||
url = reverse('api:v1:profile') | ||
view = Profile.as_view() | ||
factory = APIRequestFactory() | ||
request = factory.get(url) | ||
force_authenticate(request, user=user) | ||
|
||
# Patch the user so that they are invalid | ||
with mock.patch.object(AtmosphereUser, 'is_valid', return_value=False), \ | ||
mock.patch("api.v1.views.profile.create_new_accounts") \ | ||
as mock_create_new_accounts: | ||
response = view(request) | ||
mock_create_new_accounts.assert_not_called() |
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 was deleted.
Oops, something went wrong.
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
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
19 changes: 19 additions & 0 deletions
19
core/migrations/remove_atmosphereuser_selected_identity.py
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,19 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.11.4 on 2018-09-06 19:43 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('core', 'remove-old-allocation-models'), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveField( | ||
model_name='atmosphereuser', | ||
name='selected_identity', | ||
), | ||
] |
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
Oops, something went wrong.