1
0
mirror of https://github.com/peeringdb/peeringdb.git synced 2024-05-11 05:55:09 +00:00
Files
peeringdb-peeringdb/tests/test_cmd_delete_pocs.py

101 lines
2.8 KiB
Python
Raw Normal View History

June updates (#751) * Add pointer from API docs to tutorial #650 * Sorting by clicking table headers should use local-compare #356 * Mark IXP peering LAN as bogon #352 * Add help text to "Add (Facility, Network, Exchange)" tab #669 * Add Looking Glass field to the IX object #672 * Add read-only Superuser #679 * Make spelling of traffic levels consistent #519 (#723) * Offer 2FA (#290) * Show "Last Updated" fields on fac, ix, org records (#526) * Enable sort and reverse sort of IP column in IX display (#72) * IRR validation not handling unexpected characters gracefully (#712) * Support alternative direction of writing, e.g. Arabic (#618) * Undeleting an ixlan with an emtpy IPv4 XOR IPv6 field throws a silly error (#644) * Changing org while adding net results in 500 #654 * missing delete button for organisations (#121) * When changing owner of an ix admin GUI borks because of "Ixlan for exchange already exists" #666 * Selection should only present undeleted objects (#664) * change default encoding of API calls to 'utf-8' #663 * Posting https://www.peeringdb.com onto social media doesn't select a good preview image #537 * Revert "Add Looking Glass field to the IX object #672" This reverts commit 4daf2520043c241fabe9a521757efa86a274e28a. Conflicts: peeringdb_server/migrations/0037_ix_looking_glass.py peeringdb_server/views.py * 500 Internal Error when creating IX where prefix already exists elsewhere #718 * Fix graceful restore of soft-deleted objects with translation active (#580) * Don't return any POC data with status=deleted #569 Hard delete soft-deleted pocs after grace period #566 * django-peeringdb from github@2.0.0.2-beta Co-authored-by: Stefan Pratter <stefan@20c.com>
2020-06-24 12:55:01 -05:00
import io
from datetime import timedelta
import pytest
from .util import ClientCase, Group
from django.core.management import call_command
from django.conf import settings
from django.utils import timezone
import reversion
from reversion.models import Version
from peeringdb_server.models import Network, NetworkContact
class TestRenumberLans(ClientCase):
@classmethod
def setUpTestData(cls):
super(TestRenumberLans, cls).setUpTestData()
with reversion.create_revision():
call_command("pdb_generate_test_data", limit=1, commit=True)
cls.net = Network.objects.first()
cls.poc_del = NetworkContact.objects.create(
status="ok",
network =cls.net,
phone="123467",
email="test@localhost",
name="John Smith",
url="http://www.example.com",
)
def test_run(self):
# get current total count of pocs so we can
# check against it later
count = NetworkContact.objects.count()
# need to manually set the updated field, so
# turn auto_now off
updated = self.poc_del._meta.get_field("updated")
updated.auto_now = False
dt = timezone.now() - timedelta(days=settings.POC_DELETION_PERIOD)
# set updated value to be old enough that the
# delet command recognizes it should be hard deleted
# and also soft-delete the poc
with reversion.create_revision():
self.poc_del.updated = dt
self.poc_del.delete()
self.poc_del.refresh_from_db()
# get current total count of reversion versions so
# we can check against it later
reversion_count = Version.objects.count()
# poc should have 2 Version objects attached to it
assert Version.objects.get_for_object(self.poc_del).count() == 2
# poc should be soft-deleted
assert self.poc_del.status == "deleted"
# poc should be marked as updated in the past
assert self.poc_del.updated == dt
# run command to delete all old pocs
call_command("pdb_delete_pocs", commit=True)
# check that the poc has been hard deleted
with pytest.raises(NetworkContact.DoesNotExist):
self.poc_del.refresh_from_db()
# total poc count should have gone down by 1
assert NetworkContact.objects.count() == (count-1)
# version objects for the poc should be gone as well
assert Version.objects.get_for_object(self.poc_del).count() == 0
# no other version objects should have been touched
assert Version.objects.count() == (reversion_count-2)
# set updated field to auto now again (otherwise it breaks
# other tests)
updated.auto_now = True