mirror of
https://github.com/peeringdb/peeringdb.git
synced 2024-05-11 05:55:09 +00:00
Support 202110 (#1085)
* Block registering private ASN ranges * Add a continental region field for facilities #1007 * Incorrect order of search results #232 * Allow users to upload a small logo to their record #346 * Sponsor badge CSS and text translation issues #453 * IXP and Facility summary #18 * Add sales email and phone contact to ix object #949 * Increase timeout timer for IX-F JSON importer to 30s #962 * IX-F manually triggered import bugs #1054 * remove survey notifications * IX-F importer: manual add followed by IX-F prompted add can result in "The server rejected your data" #807 * performance fix for net view * api documentation generate broken #956 * fix poc set missing from net view * Auto focus cursor on search field on main website #695 * PeeringDB website has a poor choice of line-breaks for IPv6 addresses. #748 * Delete childless org objects #838 * linting * poetry lock * re-add mistakingly dropped translation to email template * fix template variables * regen docs * regen api docs * fix merge cruft * django-peeringdb to 2.11 and poetry relock * linting * comment out django-peeringdb volume mount * add missing declaration Co-authored-by: Stefan Pratter <stefan@20c.com> Co-authored-by: David Poarch <dpoarch@20c.com>
This commit is contained in:
@@ -8,6 +8,7 @@ import jsonschema
|
||||
import pytest
|
||||
import requests
|
||||
import reversion
|
||||
from django.core.cache import cache
|
||||
from django.core.management import call_command
|
||||
from django.test import override_settings
|
||||
|
||||
@@ -30,6 +31,73 @@ from peeringdb_server.models import (
|
||||
from .util import setup_test_data
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_import_error_status(entities):
|
||||
ixlan = entities["ixlan"]
|
||||
ixlan.ixf_ixp_member_list_url = "localhost"
|
||||
ixlan.ixf_ixp_import_enabled = True
|
||||
ixlan.save()
|
||||
|
||||
ixlan.ix.request_ixf_import()
|
||||
|
||||
call_command("pdb_ixf_ixp_member_import", process_requested=0, commit=True)
|
||||
|
||||
ixlan.ix.refresh_from_db()
|
||||
# Import will fail. Check if import status is == error
|
||||
assert ixlan.ix.ixf_import_request_status == "error"
|
||||
assert ixlan.ix.ixf_import_request
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_import_processed_count(entities_base):
|
||||
ixf_import_data = setup_test_data("ixf.member.0")
|
||||
|
||||
importer = ixf.Importer()
|
||||
cache.set(
|
||||
importer.cache_key("http://www.localhost.com"), ixf_import_data, timeout=None
|
||||
)
|
||||
ixlans = entities_base["ixlan"]
|
||||
for ixlan in ixlans:
|
||||
ixlan.ixf_ixp_import_enabled = False
|
||||
ixlan.ixf_ixp_member_list_url = "http://www.localhost.com"
|
||||
importer.update(ixlan, data=None)
|
||||
ixlan.ix.request_ixf_import()
|
||||
|
||||
call_command(
|
||||
"pdb_ixf_ixp_member_import", process_requested=1, commit=True, cache=True
|
||||
)
|
||||
|
||||
assert (
|
||||
InternetExchange.objects.filter(ixf_import_request_status="finished").count()
|
||||
== 1
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_ignore_import_enabled(entities_base):
|
||||
ixf_import_data = setup_test_data("ixf.member.0")
|
||||
|
||||
importer = ixf.Importer()
|
||||
cache.set(
|
||||
importer.cache_key("http://www.localhost.com"), ixf_import_data, timeout=None
|
||||
)
|
||||
ixlans = entities_base["ixlan"]
|
||||
for ixlan in ixlans:
|
||||
ixlan.ixf_ixp_import_enabled = True
|
||||
ixlan.ixf_ixp_member_list_url = "http://www.localhost.com"
|
||||
importer.update(ixlan, data=None)
|
||||
ixlan.ix.request_ixf_import()
|
||||
|
||||
call_command(
|
||||
"pdb_ixf_ixp_member_import", process_requested=0, commit=None, cache=True
|
||||
)
|
||||
|
||||
assert (
|
||||
InternetExchange.objects.filter(ixf_import_request_status="finished").count()
|
||||
== 2
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_reset_hints(entities, data_cmd_ixf_hints):
|
||||
ixf_import_data = json.loads(data_cmd_ixf_hints.json)
|
||||
@@ -44,23 +112,6 @@ def test_reset_hints(entities, data_cmd_ixf_hints):
|
||||
assert DeskProTicket.objects.filter(body__contains="reset_hints").count() == 1
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_reset_process_requested(entities):
|
||||
ixlan = entities["ixlan"]
|
||||
ixlan.ixf_ixp_member_list_url = "localhost"
|
||||
ixlan.ixf_ixp_import_enabled = True
|
||||
ixlan.save()
|
||||
|
||||
ixlan.ix.request_ixf_import()
|
||||
|
||||
call_command("pdb_ixf_ixp_member_import", process_requested=0, commit=True)
|
||||
|
||||
ixlan.ix.refresh_from_db()
|
||||
|
||||
assert ixlan.ix.ixf_import_request_status == "finished"
|
||||
assert ixlan.ix.ixf_import_request
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_reset_dismissals(entities, data_cmd_ixf_dismissals):
|
||||
ixf_import_data = json.loads(data_cmd_ixf_dismissals.json)
|
||||
@@ -423,6 +474,129 @@ def entities():
|
||||
return entities
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def entities_base():
|
||||
entities = {}
|
||||
with reversion.create_revision():
|
||||
entities["org"] = [Organization.objects.create(name="Netflix", status="ok")]
|
||||
|
||||
# create exchange(s)
|
||||
entities["ix"] = [
|
||||
InternetExchange.objects.create(
|
||||
name="Test Exchange One",
|
||||
org=entities["org"][0],
|
||||
status="ok",
|
||||
tech_email="ix1@localhost",
|
||||
),
|
||||
InternetExchange.objects.create(
|
||||
name="Test Exchange Two",
|
||||
org=entities["org"][0],
|
||||
status="ok",
|
||||
tech_email="ix2@localhost",
|
||||
),
|
||||
]
|
||||
|
||||
# create ixlan(s)
|
||||
entities["ixlan"] = [ix.ixlan for ix in entities["ix"]]
|
||||
|
||||
# create ixlan prefix(s)
|
||||
entities["ixpfx"] = [
|
||||
IXLanPrefix.objects.create(
|
||||
ixlan=entities["ixlan"][0],
|
||||
status="ok",
|
||||
prefix="195.69.144.0/22",
|
||||
protocol="IPv4",
|
||||
),
|
||||
IXLanPrefix.objects.create(
|
||||
ixlan=entities["ixlan"][0],
|
||||
status="ok",
|
||||
prefix="2001:7f8:1::/64",
|
||||
protocol="IPv6",
|
||||
),
|
||||
IXLanPrefix.objects.create(
|
||||
ixlan=entities["ixlan"][1],
|
||||
status="ok",
|
||||
prefix="195.66.224.0/22",
|
||||
protocol="IPv4",
|
||||
),
|
||||
IXLanPrefix.objects.create(
|
||||
ixlan=entities["ixlan"][1],
|
||||
status="ok",
|
||||
prefix="2001:7f8:4::/64",
|
||||
protocol="IPv6",
|
||||
),
|
||||
]
|
||||
|
||||
# create network(s)
|
||||
entities["net"] = {
|
||||
"UPDATE_ENABLED": Network.objects.create(
|
||||
name="Network w allow ixp update enabled",
|
||||
org=entities["org"][0],
|
||||
asn=2906,
|
||||
info_prefixes4=42,
|
||||
info_prefixes6=42,
|
||||
website="http://netflix.com/",
|
||||
policy_general="Open",
|
||||
policy_url="https://www.netflix.com/openconnect/",
|
||||
allow_ixp_update=True,
|
||||
status="ok",
|
||||
irr_as_set="AS-NFLX",
|
||||
info_unicast=True,
|
||||
info_ipv6=True,
|
||||
),
|
||||
"UPDATE_DISABLED": Network.objects.create(
|
||||
name="Network w allow ixp update disabled",
|
||||
org=entities["org"][0],
|
||||
asn=1001,
|
||||
allow_ixp_update=False,
|
||||
status="ok",
|
||||
info_prefixes4=42,
|
||||
info_prefixes6=42,
|
||||
website="http://netflix.com/",
|
||||
policy_general="Open",
|
||||
policy_url="https://www.netflix.com/openconnect/",
|
||||
info_unicast=True,
|
||||
info_ipv6=True,
|
||||
),
|
||||
"UPDATE_DISABLED_2": Network.objects.create(
|
||||
name="Network w allow ixp update disabled (2)",
|
||||
org=entities["org"][0],
|
||||
asn=1101,
|
||||
allow_ixp_update=False,
|
||||
status="ok",
|
||||
info_prefixes4=42,
|
||||
info_prefixes6=42,
|
||||
website="http://netflix.com/",
|
||||
policy_general="Open",
|
||||
policy_url="https://www.netflix.com/openconnect/",
|
||||
info_unicast=True,
|
||||
info_ipv6=True,
|
||||
),
|
||||
}
|
||||
|
||||
entities["netcontact"] = [
|
||||
NetworkContact.objects.create(
|
||||
email="network1@localhost",
|
||||
network=entities["net"]["UPDATE_ENABLED"],
|
||||
status="ok",
|
||||
role="Policy",
|
||||
),
|
||||
NetworkContact.objects.create(
|
||||
email="network2@localhost",
|
||||
network=entities["net"]["UPDATE_DISABLED"],
|
||||
status="ok",
|
||||
role="Policy",
|
||||
),
|
||||
]
|
||||
entities["netixlan"] = []
|
||||
admin_user = User.objects.create_user("admin", "admin@localhost", "admin")
|
||||
ixf_importer_user = User.objects.create_user(
|
||||
"ixf_importer", "ixf_importer@localhost", "ixf_importer"
|
||||
)
|
||||
entities["org"][0].admin_usergroup.user_set.add(admin_user)
|
||||
return entities
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def deskprotickets():
|
||||
"""
|
||||
|
||||
49
tests/test_cmd_pdb_delete_childless_org.py
Normal file
49
tests/test_cmd_pdb_delete_childless_org.py
Normal file
@@ -0,0 +1,49 @@
|
||||
import io
|
||||
from datetime import timedelta
|
||||
|
||||
import pytest
|
||||
import reversion
|
||||
from django.conf import settings
|
||||
from django.core.management import call_command
|
||||
from django.db.transaction import commit
|
||||
from django.utils import timezone
|
||||
from reversion.models import Version
|
||||
|
||||
from peeringdb_server.models import Facility, InternetExchange, Network, Organization
|
||||
|
||||
from .util import ClientCase, Group
|
||||
|
||||
|
||||
class TestChildlessDeleteOrg(ClientCase):
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
super().setUpTestData()
|
||||
with reversion.create_revision():
|
||||
call_command("pdb_generate_test_data", limit=1, commit=True)
|
||||
cls.org = Organization.objects.first()
|
||||
|
||||
def test_cmd_delete_childless_org(self):
|
||||
|
||||
dt = timezone.now() - timedelta(days=settings.ORG_CHILDLESS_DELETE_DURATION + 1)
|
||||
|
||||
org = self.org
|
||||
|
||||
# Set the date to days before the current date (based on settings.ORG_CHILDLESS_DELETE_DURATION)
|
||||
org.flagged_date = dt
|
||||
org.save()
|
||||
|
||||
# delete child objects
|
||||
net = Network.objects.filter(org=org).delete()
|
||||
ix = InternetExchange.objects.filter(org=org).delete()
|
||||
fac = Facility.objects.filter(org=org).delete()
|
||||
|
||||
# Check if org is childless and can be deleted
|
||||
assert org.deletable
|
||||
|
||||
call_command("pdb_delete_childless_org", commit=True)
|
||||
|
||||
org = Organization.objects.filter(id=org.id).first()
|
||||
|
||||
# Check if org was flagged and deleted
|
||||
assert org.flagged
|
||||
assert org.status == "deleted"
|
||||
@@ -10,6 +10,7 @@ from peeringdb_server.models import (
|
||||
User,
|
||||
UserOrgAffiliationRequest,
|
||||
)
|
||||
from tests.util import reset_group_ids
|
||||
|
||||
URL = "/affiliate-to-org"
|
||||
|
||||
@@ -120,6 +121,7 @@ def test_affiliate_to_nonexisting_org_multiple(client):
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_adv_search_init():
|
||||
reset_group_ids()
|
||||
client = Client()
|
||||
response = client.get("/advanced_search")
|
||||
assert response.status_code == 200
|
||||
|
||||
@@ -89,8 +89,15 @@ def reset_group_ids():
|
||||
to make sure the settings are updated
|
||||
"""
|
||||
|
||||
settings.USER_GROUP_ID = Group.objects.get(name="user").id
|
||||
settings.GUEST_GROUP_ID = Group.objects.get(name="guest").id
|
||||
try:
|
||||
settings.USER_GROUP_ID = Group.objects.get(name="user").id
|
||||
except Group.DoesNotExist:
|
||||
Group.objects.create(name="user", id=settings.USER_GROUP_ID)
|
||||
|
||||
try:
|
||||
settings.GUEST_GROUP_ID = Group.objects.get(name="guest").id
|
||||
except Group.DoesNotExist:
|
||||
Group.objects.create(name="guest", id=settings.GUEST_GROUP_ID)
|
||||
|
||||
|
||||
def override_group_id():
|
||||
|
||||
Reference in New Issue
Block a user