-
Notifications
You must be signed in to change notification settings - Fork 2
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 #768 from fecgov/push-sprint-38
Update requirements for sprint 38
- Loading branch information
Showing
52 changed files
with
902 additions
and
670 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
This file was deleted.
Oops, something went wrong.
93 changes: 93 additions & 0 deletions
93
...mmittee_accounts/migrations/0003_membership_pending_email_alter_membership_id_and_more.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,93 @@ | ||
# Generated by Django 4.2.7 on 2024-02-16 20:43 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
from django.utils import timezone | ||
import uuid | ||
|
||
|
||
def delete_pending_memberships(apps, schema_editor): | ||
Membership = apps.get_model("committee_accounts", "Membership") # noqa | ||
Membership.objects.filter(user=None).delete() | ||
|
||
|
||
def generate_new_uuid(apps, schema_editor): | ||
Membership = apps.get_model("committee_accounts", "Membership") # noqa | ||
for membership in Membership.objects.all(): | ||
membership.uuid = uuid.uuid4() | ||
membership.save() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
('committee_accounts', '0002_membership'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='membership', | ||
name='pending_email', | ||
field=models.EmailField(blank=True, max_length=254, null=True), | ||
), | ||
migrations.AddField( | ||
model_name='membership', | ||
name='uuid', | ||
field=models.UUIDField( | ||
default=uuid.uuid4, | ||
editable=False, | ||
primary_key=False, | ||
serialize=False, | ||
unique=False | ||
) | ||
), | ||
migrations.RunPython( | ||
generate_new_uuid, | ||
migrations.RunPython.noop, | ||
), | ||
migrations.RemoveField( | ||
model_name='membership', | ||
name='id', | ||
), | ||
migrations.RenameField( | ||
model_name='membership', | ||
old_name='uuid', | ||
new_name='id' | ||
), | ||
migrations.AlterField( | ||
model_name='membership', | ||
name='id', | ||
field=models.UUIDField( | ||
default=uuid.uuid4, | ||
editable=False, | ||
primary_key=True, | ||
serialize=False, | ||
unique=True | ||
) | ||
), | ||
migrations.AlterField( | ||
model_name='membership', | ||
name='user', | ||
field=models.ForeignKey( | ||
null=True, | ||
on_delete=models.deletion.CASCADE, | ||
to=settings.AUTH_USER_MODEL | ||
), | ||
), | ||
migrations.AddField( | ||
model_name='membership', | ||
name='created', | ||
field=models.DateTimeField(auto_now_add=True, default=timezone.now), | ||
preserve_default=False, | ||
), | ||
migrations.AddField( | ||
model_name='membership', | ||
name='updated', | ||
field=models.DateTimeField(auto_now=True), | ||
), | ||
migrations.RunPython( | ||
migrations.RunPython.noop, | ||
delete_pending_memberships | ||
), | ||
] |
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
151 changes: 151 additions & 0 deletions
151
django-backend/fecfiler/committee_accounts/test_views.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,151 @@ | ||
from uuid import UUID | ||
from django.test import RequestFactory, TestCase | ||
from fecfiler.committee_accounts.models import Membership | ||
from fecfiler.committee_accounts.views import register_committee, \ | ||
CommitteeMembershipViewSet | ||
from fecfiler.user.models import User | ||
from django.core.management import call_command | ||
|
||
|
||
class CommitteeAccountsViewsTest(TestCase): | ||
|
||
def setUp(self): | ||
call_command("load_committee_data") | ||
self.test_user = User.objects.create( | ||
email="[email protected]", username="gov") | ||
self.other_user = User.objects.create( | ||
email="[email protected]", username="com") | ||
|
||
def test_register_committee(self): | ||
account = register_committee("C12345678", self.test_user) | ||
self.assertEquals(account.committee_id, "C12345678") | ||
|
||
def test_register_committee_existing(self): | ||
account = register_committee("C12345678", self.test_user) | ||
self.assertEquals(account.committee_id, "C12345678") | ||
self.assertRaises( | ||
Exception, register_committee, committee_id="C12345678", user=self.test_user | ||
) | ||
|
||
def test_register_committee_mismatch_email(self): | ||
self.assertRaises( | ||
Exception, | ||
register_committee, | ||
committee_id="C12345678", | ||
user=self.other_user, | ||
) | ||
|
||
|
||
class CommitteeMemberViewSetTest(TestCase): | ||
fixtures = ["C01234567_user_and_committee", "unaffiliated_users"] | ||
|
||
def setUp(self): | ||
self.user = User.objects.get(id="12345678-aaaa-bbbb-cccc-111122223333") | ||
self.factory = RequestFactory() | ||
|
||
def test_remove_member(self): | ||
membership_uuid = UUID("136a21f2-66fe-4d56-89e9-0d1d4612741c") | ||
view = CommitteeMembershipViewSet() | ||
request = self.factory.get( | ||
"/api/v1/committee-members/{membership_uuid}/remove-member" | ||
) | ||
request.user = self.user | ||
request.session = { | ||
"committee_uuid": UUID('11111111-2222-3333-4444-555555555555')} | ||
request.method = "DELETE" | ||
request.query_params = dict() | ||
view.kwargs = {"pk": membership_uuid} | ||
view.request = request | ||
response = view.remove_member( | ||
request, membership_uuid) | ||
self.assertEqual(response.status_code, 200) | ||
|
||
def test_add_pending_membership(self): | ||
view = CommitteeMembershipViewSet() | ||
request = self.factory.get("/api/v1/committee-members/add-member") | ||
request.user = self.user | ||
request.session = { | ||
"committee_uuid": UUID('11111111-2222-3333-4444-555555555555') | ||
} | ||
request.method = "POST" | ||
request.data = { | ||
"role": Membership.CommitteeRole.COMMITTEE_ADMINISTRATOR, | ||
"email": "[email protected]" | ||
} | ||
view.request = request | ||
response = view.add_member(request) | ||
|
||
self.assertEqual(response.status_code, 200) | ||
self.assertEqual( | ||
response.data['email'], | ||
'[email protected]' | ||
) | ||
self.assertEqual(response.data['is_active'], False) | ||
|
||
def test_add_membership_for_preexisting_user(self): | ||
# This test covers a bug found by QA where adding a membership | ||
# for a pre-existing user was triggering a 500 server error | ||
|
||
view = CommitteeMembershipViewSet() | ||
request = self.factory.get("/api/v1/committee-members/add-member") | ||
request.user = self.user | ||
request.session = { | ||
"committee_uuid": UUID('11111111-2222-3333-4444-555555555555') | ||
} | ||
request.method = "POST" | ||
request.data = { | ||
"role": Membership.CommitteeRole.COMMITTEE_ADMINISTRATOR, | ||
"email": '[email protected]' | ||
} | ||
view.request = request | ||
response = view.add_member(request) | ||
|
||
self.assertEqual(response.status_code, 200) | ||
self.assertEqual(response.data['email'], '[email protected]') | ||
self.assertEqual(response.data['is_active'], True) | ||
|
||
def test_add_membership_requires_correct_parameters(self): | ||
view = CommitteeMembershipViewSet() | ||
request = self.factory.get("/api/v1/committee-members/add-member") | ||
request.user = self.user | ||
request.session = { | ||
"committee_uuid": UUID('11111111-2222-3333-4444-555555555555') | ||
} | ||
request.method = "POST" | ||
|
||
request.data = { | ||
"role": Membership.CommitteeRole.COMMITTEE_ADMINISTRATOR, | ||
} | ||
view.request = request | ||
response = view.add_member(request) | ||
self.assertEqual(response.status_code, 400) | ||
self.assertEqual(response.data, 'Missing fields: email') | ||
|
||
request.data = { | ||
"email": "[email protected]" | ||
} | ||
view.request = request | ||
response = view.add_member(request) | ||
self.assertEqual(response.status_code, 400) | ||
self.assertEqual(response.data, 'Missing fields: role') | ||
|
||
request.data = { | ||
"email": "[email protected]", | ||
"role": "A Random String" | ||
} | ||
view.request = request | ||
response = view.add_member(request) | ||
self.assertEqual(response.status_code, 400) | ||
self.assertEqual(response.data, 'Invalid role') | ||
|
||
request.data = { | ||
"email": "[email protected]", | ||
"role": Membership.CommitteeRole.COMMITTEE_ADMINISTRATOR | ||
} | ||
view.request = request | ||
response = view.add_member(request) | ||
self.assertEqual(response.status_code, 400) | ||
self.assertEqual( | ||
response.data, | ||
"This email is taken by an existing membership to this committee" | ||
) |
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,10 +1,12 @@ | ||
from django.urls import path, include | ||
from rest_framework.routers import DefaultRouter | ||
from .views import CommitteeViewSet | ||
from .views import CommitteeMembershipViewSet, CommitteeViewSet | ||
|
||
# Create a router and register our viewsets with it. | ||
router = DefaultRouter() | ||
router.register(r"", CommitteeViewSet, basename="committees") | ||
router.register(r"committees", CommitteeViewSet, basename="committees") | ||
router.register(r"committee-members", CommitteeMembershipViewSet, | ||
basename="committee-members") | ||
|
||
# The API URLs are now determined automatically by the router. | ||
urlpatterns = [path("committees/", include(router.urls))] | ||
urlpatterns = [] | ||
urlpatterns += router.urls |
Oops, something went wrong.