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

156 lines
4.6 KiB
Python
Raw Normal View History

import json
2018-11-08 19:45:21 +00:00
import pytest
from django.test import TestCase
from django.contrib.auth.models import Group
from django.db import IntegrityError
2018-11-08 19:45:21 +00:00
import peeringdb_server.models as models
import reversion
2018-11-08 19:45:21 +00:00
class VeriQueueTests(TestCase):
"""
Test VerificationQueue creation and resolve
"""
@classmethod
def setUpTestData(cls):
"""
Test that verification queue items are created for all entities
for which it is enabled
"""
guest_group = Group.objects.create(name="guest")
user_group = Group.objects.create(name="user")
cls.inst = {}
org = models.Organization.objects.create(name="Test", status="pending")
for model in models.QUEUE_ENABLED:
if model == models.Organization:
continue
if model == models.User:
cls.inst["user"] = model.objects.create_user(
2019-12-05 16:57:52 +00:00
"test", "test@localhost", "test"
)
2018-11-08 19:45:21 +00:00
cls.inst["user"].set_unverified()
else:
kwargs = {
"org": org,
"name": "Test %s" % model.handleref.tag,
2019-12-05 16:57:52 +00:00
"status": "pending",
2018-11-08 19:45:21 +00:00
}
if model.handleref.tag == "net":
kwargs.update(asn=1)
cls.inst[model.handleref.tag] = model.objects.create(**kwargs)
def test_get_for_entity(self):
"""
Test VerificationQueueItem.get_for_entity
"""
# test verification queue items were created for all queue enabled
# entities
for k, v in list(self.inst.items()):
2018-11-08 19:45:21 +00:00
vqi = models.VerificationQueueItem.get_for_entity(v)
self.assertEqual(vqi.item, v)
def test_deskpro_tickets(self):
"""
Test that tickets were created for the facility, ix and network
"""
user = self.inst["user"]
qs = models.DeskProTicket.objects
for tag in ["fac", "net", "ix"]:
inst = self.inst[tag]
vqi = models.VerificationQueueItem.get_for_entity(inst)
vqi.user = user
vqi.save()
self.assertEqual(
Dotf fixes (#781) * fix issue where ix-f import would raise suggestions ipaddresses not that ixlan (#764) * IX-F Suggestions: Leaving the editor and returning to it via back button issues (#765) * IX-F importer: Clicking "Preview" (IXP Update Tools) on /net/ page resulted in 170 ticket resolutions (#769) More robust testing * black formatting (was lost after pyupgrade) * Add regex searching to deskpro ticket subjects * Change operational error * IX-F suggestions: consolidate delete+add (#770) * Add reset functions to commandline tool * Fix commandline tool bugs * Fix reset commandline tool bugs * add commandline tool * Ixlan needs to be set for import commandline tool * Add email model * Add admin view to emails * Allow network and ix to be null * save emails as part of ixf import * Add email model * Add email delete * add iregex search and better comments * fix ixlan selection for import * redefine migration dependencies for this branch * only enable search w start and end char * Add caption to regex search * Remove delete all ixfmemberdata option * [beta] IX-F importer: don't bother about missing IPv{4,6} address when network is not doing IPv{4,6} (#771) * Add cmdline tests * Resolve email conflicts * Add cmd tool reset tests * add autocomplete to commandline tool * Fix email bugs * Fix email migrations * Fix typos * [beta] IX-F importer: prevent Admin Committee overload by initially limiting importer to IXes enabled by AC (#772) * Finalize regex search for emails and deskprotickets * Fix keyword bug * fix typo * protocol-conflict will now be handled in the notification consolidation 771 changes where if the network indicates neither ipv4 nor ipv6 support, it is handled as supporting both (eg the network didnt configure these at all) realised that the importer command re instantiates the `Importer` class for each ixlan it processes, so moved the sending of consolidated notifications (#772) out of the `update` function and into the command itself after its done processing all the ixlans. This means for tests you will need to call `importer.notify_proposals` after `importer.update` to test the consolidated notifications. fixed several MultipleObjectsReturned errors when network switch protocol support in between imports * should be checking for "ix" in the form data (#773) * Fix cmd ixf tests * fix issue in log_peer * Add commit check for reset tool * fix importer bugs * remove dupe IXFImportEmail definition * ixfimportemail support ix__name and net__name searching * ticket resolution responses * Add commit to command ixf import changes * fix modify entry header * remove whitespace in notification about remote data changes * Begin updating tests * ixf-import command line tool to queue * refactor conflict inserts * Update import protocol tests, including tests for 770 * More test edits * Change cmd tests * better ixfmemberdata error handling and fix some test data * dont reset the same ixfmemberdata requirement * fix many bugs add many tests * remove debug message * fix bug during import when consolidating delete+add * fix perfomance issue in IXFMemberData listing * dont show reset flags on prod env * Add regex search tests * Add 772 tests * remove debug output * fix `test_resolve_deskpro_ticket` test * black formatting * remove dupe import * fix issue with unique constraint error handling * add test for ixp / network ip protocol notification * add missing test data Co-authored-by: Stefan Pratter <stefan@20c.com> Co-authored-by: Elliot Frank <elliot@20c.com>
2020-07-26 23:36:27 -05:00
qs.filter(subject=f"[test]{vqi.content_type} - {inst}").exists(), True,
2019-12-05 16:57:52 +00:00
)
2018-11-08 19:45:21 +00:00
def test_approve(self):
"""
Test VerificationqueueItem.approve
"""
ix = self.inst.get("ix")
vqi = models.VerificationQueueItem.get_for_entity(ix)
vqi.approve()
# after approval ix should be status 'ok'
ix.refresh_from_db()
self.assertEqual(ix.status, "ok")
# check that the status in the archive is correct (#558)
2019-12-05 16:57:52 +00:00
version = (
reversion.models.Version.objects.get_for_object(ix)
.order_by("-revision_id")
.first()
)
self.assertEqual(
json.loads(version.serialized_data)[0]["fields"]["status"], "ok"
)
2018-11-08 19:45:21 +00:00
# after approval vqi should no longer exist
with pytest.raises(models.VerificationQueueItem.DoesNotExist):
2018-11-08 19:45:21 +00:00
vqi.refresh_from_db()
def test_user_approve(self):
"""
Test VerificationqueueItem.approve when approving users
"""
# test that approving a user also moves them in the correct usergroup
user = self.inst.get("user")
vqi = models.VerificationQueueItem.get_for_entity(user)
vqi.approve()
# after approval user should be status 'ok'
user.refresh_from_db()
self.assertEqual(user.status, "ok")
# after approval user should be in 'users' group
self.assertEqual(user.groups.filter(name="user").exists(), True)
self.assertEqual(user.groups.filter(name="guest").exists(), False)
def test_deny(self):
"""
Test VerificationqueueItem.deny
"""
fac = self.inst.get("fac")
vqi = models.VerificationQueueItem.get_for_entity(fac)
vqi.deny()
# after denial fac should no longer exist
with pytest.raises(models.Facility.DoesNotExist):
2018-11-08 19:45:21 +00:00
fac.refresh_from_db()
# after denial vqi should no longer exist
with pytest.raises(models.VerificationQueueItem.DoesNotExist):
2018-11-08 19:45:21 +00:00
vqi.refresh_from_db()
def test_unique(self):
"""
Test that only one verification queue item can exist for an entity
"""
fac = self.inst.get("fac")
vqi = models.VerificationQueueItem.get_for_entity(fac)
with pytest.raises(IntegrityError):
models.VerificationQueueItem.objects.create(
content_type=models.ContentType.objects.get_for_model(type(fac)),
2019-12-05 16:57:52 +00:00
object_id=fac.id,
)