mirror of
https://github.com/peeringdb/peeringdb.git
synced 2024-05-11 05:55:09 +00:00
* fix next redirect when using U2F 2FA auth (#1191) * Added self identifier to API * fix migrations hierarchy after merging in previous support branch * campus object Co-authored-by: Stefan Pratter <stefan@20c.com> * fix out of bound error message add city / country to campus view * fix tests * relock poetry * linting * linting * fix docs regen * regen docs * linting * refactor self entity view to support carrier and campus object types and also make it easier to support additional object types in the future * remove debug message --------- Co-authored-by: Gajanan Patil <dipaksavaliya.python@gmail.com>
73 lines
2.4 KiB
Python
73 lines
2.4 KiB
Python
import io
|
|
from datetime import timedelta
|
|
from unicodedata import name
|
|
|
|
import pytest
|
|
import reversion
|
|
from django.conf import settings
|
|
from django.core.management import call_command
|
|
from django.utils import timezone
|
|
from reversion.models import Version
|
|
|
|
from peeringdb_server.models import Organization, User
|
|
|
|
from .util import ClientCase, Group
|
|
|
|
|
|
class TestOrgCleanup(ClientCase):
|
|
@classmethod
|
|
def setUpTestData(cls):
|
|
super().setUpTestData()
|
|
with reversion.create_revision():
|
|
cls.org = Organization.objects.create(name="Test Org")
|
|
|
|
# Add user to all orgs' admin_usergroups
|
|
for index in range(0, 3):
|
|
user = User.objects.create_user(
|
|
username=f"admin_user_{index}",
|
|
email=f"admin_user_{index}@localhost",
|
|
first_name=f"admin_user_{index}",
|
|
last_name=f"admin_user_{index}",
|
|
)
|
|
cls.org.admin_usergroup.user_set.add(user)
|
|
user.save()
|
|
cls.org.save()
|
|
|
|
# Add affiliation request to org
|
|
cls.org.affiliation_requests.create(
|
|
user=user,
|
|
status="pending",
|
|
created=timezone.now() - timedelta(days=1),
|
|
)
|
|
|
|
# Add user to all orgs' usergroups
|
|
for index in range(0, 3):
|
|
user = User.objects.create_user(
|
|
username=f"user_{index}",
|
|
email=f"user_{index}@localhost",
|
|
first_name=f"user_{index}",
|
|
last_name=f"user_{index}",
|
|
)
|
|
cls.org.usergroup.user_set.add(user)
|
|
user.save()
|
|
cls.org.save()
|
|
|
|
def test_org_delete(self):
|
|
# Assert that all orgs have 3 users
|
|
|
|
assert self.org.admin_usergroup.user_set.count() == 3
|
|
assert self.org.usergroup.user_set.count() == 3
|
|
|
|
# Assert that all orgs have 3 affiliation request
|
|
assert self.org.affiliation_requests.count() == 3
|
|
|
|
# Delete Organization
|
|
self.org.delete()
|
|
|
|
# Assert that all users in org are removed
|
|
assert self.org.admin_usergroup.user_set.count() == 0
|
|
assert self.org.usergroup.user_set.count() == 0
|
|
|
|
# Assert that org affiliation requests is cancelled
|
|
assert self.org.affiliation_requests.count() == 0
|