mirror of
https://github.com/peeringdb/peeringdb.git
synced 2024-05-11 05:55:09 +00:00
* Add migration for service level and terms * Add service level and terms to UI and serializer, as well as data/enum * Wire up data/enum endpoint and loader * remove proto_ from ix UI * derive fields for proto_unicast and proto_ipv6 * update tests for readonly fields * Fix query for protocols * Fix api bug with protocol * add readonly fields to django admin * rename readonly fields * Add translation to names * Add pdb api test for suggested facility re-add * Add printing debuggin test * add printing debugging serializer * Update _undelete with _reapprove to handle pending cases * Update tests (one is still failing) * adjust suggest test * Add ix_count to fac (834) * Add test for ix_count on fac (834) * Add fac_count to IX (836) * add ix_count and fac_count to Network * Refactor ix net_count filtering * Add filtering for 834, 835, 836 * Remove duplicates from the Network's ix_count * Setup Network for ix_count and fac_count (835) * initial obj_counts for Facilities and Exchanges * Add signals for updates to all counts * add migration * Add print statements to test * introduce reversion to tests * rename network count to net count across codebase * fix network_count typo * add migration to set default vals * fix filter tests for obj_counts * speed up migration * fix failing tests * fix final test * sort out migration tree and add fac offered fields * update frontend for facility dropdown offered_resilience * First pass at advanced api search for user story 1 * melissa geo lookup first steps * fix migration hierarchy * working melissa integration * begin ending filters for api endpoints * add more org_present endpoints * add search for IXs that match multiple networks * extend logic to facility * Add service level and terms to advanced search * use address2 field for lookup * melissa tests * cleanup and docs * uncomment offered_power * developed offered_power component * fix geo normalize existing cmd normalize state * change migration to match django-peeringdb * add offered_space field * Fill out remaining api filter fields * Add org_not_present endpoint filter * fix unit input ux * more ux fixes * remove merge cruft * google for geocoding various melissa improvements (consider result quality) * fix tests * refactor org_preset and org_not_present queries * ix capacity api filters * ix capacity filters for #802 advanced search ux for #802 * finalize advanced search UX for #802 * css fixes * remove cruft * fix net_count fac_count queries * add new fields to create facility (#800) tests for #802 and #800 * fix tests * remove #800 changes * fix capacity search * more #800 changes to remove * django-peeringdb 2.7.0 and pipenv relock * black format * pin black version Co-authored-by: Elliot Frank <elliot@20c.com> Co-authored-by: Stefan Pratter <stefan@20c.com>
170 lines
4.0 KiB
Python
170 lines
4.0 KiB
Python
import datetime
|
|
import pytest
|
|
|
|
from django.core.management import call_command
|
|
|
|
from peeringdb_server.models import (
|
|
Organization,
|
|
Sponsorship,
|
|
SponsorshipOrganization,
|
|
ProtectedAction,
|
|
UTC,
|
|
)
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_protected_entities(db):
|
|
"""
|
|
test that protected entities cannot be deleted
|
|
if their protection conditions are met
|
|
"""
|
|
|
|
call_command("pdb_generate_test_data", limit=2, commit=True)
|
|
|
|
org = Organization.objects.first()
|
|
|
|
# assert that the org as active objects under it
|
|
|
|
assert org.ix_set_active.exists()
|
|
assert org.fac_set_active.exists()
|
|
assert org.net_set_active.exists()
|
|
|
|
def assert_protected(entity):
|
|
"""
|
|
helper function to test that an object is currently
|
|
not deletable
|
|
"""
|
|
with pytest.raises(ProtectedAction):
|
|
entity.delete()
|
|
|
|
# org has ix, net and fac under it, and should not be
|
|
# deletable
|
|
|
|
assert_protected(org)
|
|
|
|
# process the exchanges under the org for deletion
|
|
# and checking their protected status as well
|
|
|
|
for ix in org.ix_set.all():
|
|
|
|
assert ix.ixlan.ixpfx_set.exists()
|
|
assert ix.ixlan.netixlan_set.exists()
|
|
assert ix.ixfac_set.exists()
|
|
|
|
# exchange currently has netixlans and prefixes
|
|
# under it that are active and should not be
|
|
# deletable
|
|
|
|
assert_protected(ix)
|
|
|
|
# process the ixfac objects under the exchange
|
|
for ixfac in ix.ixfac_set.all():
|
|
ixfac.delete()
|
|
|
|
# process the prefixes under the exchange
|
|
|
|
for ixpfx in ix.ixlan.ixpfx_set.all():
|
|
|
|
# exchange has netixlans under it that fall
|
|
# into the address space for the prefix so
|
|
# the prefix is currently not deletable
|
|
|
|
assert_protected(ixpfx)
|
|
|
|
# process the netixlans under the exchange and
|
|
# delete them
|
|
|
|
for netixlan in ix.ixlan.netixlan_set.all():
|
|
netixlan.delete()
|
|
|
|
# with the netixlans gone, the prefixes can now
|
|
# be deleted
|
|
|
|
for ixpfx in ix.ixlan.ixpfx_set.all():
|
|
ixpfx.delete()
|
|
|
|
# with netixlans gone the exchange can now be
|
|
# deleted
|
|
ix.delete()
|
|
|
|
# org still has active fac and net under it
|
|
# and should still be protected
|
|
|
|
assert_protected(org)
|
|
|
|
# process the facilities under the org for deletion
|
|
# and checking their protected status as well
|
|
|
|
for fac in org.fac_set.all():
|
|
assert fac.ixfac_set.exists()
|
|
assert fac.netfac_set.exists()
|
|
|
|
# fac has active netfac and ixfac objects
|
|
# under it and should not be deletable
|
|
|
|
assert_protected(fac)
|
|
|
|
# delete ixfacs
|
|
|
|
for ixfac in fac.ixfac_set.all():
|
|
ixfac.delete()
|
|
|
|
# fac has active netfac under it and should
|
|
# still not be deletable
|
|
|
|
assert_protected(fac)
|
|
|
|
# delete netfacs
|
|
|
|
for netfac in fac.netfac_set.all():
|
|
netfac.delete()
|
|
|
|
# facility can now be deleted
|
|
|
|
fac.delete()
|
|
|
|
# org still has active net objects under it
|
|
# and should not be deletable
|
|
|
|
assert_protected(org)
|
|
|
|
# delete nets
|
|
|
|
for net in org.net_set.all():
|
|
net.delete()
|
|
|
|
# org is now deletable
|
|
|
|
org.delete()
|
|
assert org.status == "deleted"
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_org_protection_sponsor(db):
|
|
|
|
"""
|
|
test that organization cannot be deleted if it has
|
|
an active sponsorship going
|
|
"""
|
|
|
|
now = datetime.datetime.now().replace(tzinfo=UTC())
|
|
|
|
org = Organization.objects.create(status="ok", name="SponsorOrg")
|
|
sponsor = Sponsorship.objects.create(
|
|
start_date=now - datetime.timedelta(days=1),
|
|
end_date=now + datetime.timedelta(days=1),
|
|
)
|
|
sponsor.orgs.add(org)
|
|
|
|
assert org.sponsorship.active
|
|
|
|
assert org.deletable == False
|
|
assert "Organization is currently an active sponsor" in org.not_deletable_reason
|
|
|
|
with pytest.raises(ProtectedAction):
|
|
org.delete()
|
|
|
|
sponsor.delete()
|
|
|
|
org.delete()
|