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>
264 lines
7.8 KiB
Python
264 lines
7.8 KiB
Python
"""
|
|
Test peeringdb data export views
|
|
"""
|
|
import os
|
|
import pytest
|
|
import json
|
|
import difflib
|
|
import re
|
|
import reversion
|
|
|
|
from django.test import Client
|
|
|
|
from .util import ClientCase
|
|
|
|
from peeringdb_server.models import (
|
|
Organization,
|
|
Network,
|
|
InternetExchange,
|
|
Facility,
|
|
NetworkFacility,
|
|
NetworkIXLan,
|
|
IXLan,
|
|
)
|
|
|
|
|
|
class AdvancedSearchExportTest(ClientCase):
|
|
"""
|
|
Tests advanced search result exports
|
|
"""
|
|
|
|
@classmethod
|
|
def setUpTestData(cls):
|
|
|
|
ClientCase.setUpTestData()
|
|
|
|
entity_count = list(range(1, 4))
|
|
|
|
countries = ["US", "FI", ""]
|
|
|
|
# create orgs
|
|
|
|
# create exchanges
|
|
cls.org = [
|
|
Organization.objects.create(
|
|
name=f"Organization {i}",
|
|
country=countries[i - 1],
|
|
city=f"City {i}",
|
|
status="ok",
|
|
)
|
|
for i in entity_count
|
|
]
|
|
|
|
# create networks
|
|
cls.net = [
|
|
Network.objects.create(
|
|
name=f"Network {i}",
|
|
status="ok",
|
|
aka=f"AKA {i}",
|
|
policy_general="Open",
|
|
info_traffic="0-20Mbps",
|
|
asn=i,
|
|
org=cls.org[i - 1],
|
|
)
|
|
for i in entity_count
|
|
]
|
|
|
|
# create exchanges
|
|
cls.ix = [
|
|
InternetExchange.objects.create(
|
|
name=f"Exchange {i}",
|
|
media="Ethernet",
|
|
country=countries[i - 1],
|
|
city=f"City {i}",
|
|
status="ok",
|
|
org=cls.org[i - 1],
|
|
)
|
|
for i in entity_count
|
|
]
|
|
|
|
# create facilities
|
|
cls.fac = [
|
|
Facility.objects.create(
|
|
name=f"Facility {i}",
|
|
status="ok",
|
|
city=f"City {i}",
|
|
clli=f"CLLI{i}",
|
|
state=f"State {i}",
|
|
npanxx=f"{i}-{i}",
|
|
country=countries[i - 1],
|
|
zipcode=i,
|
|
org=cls.org[i - 1],
|
|
)
|
|
for i in entity_count
|
|
]
|
|
|
|
# create network facility relationships
|
|
with reversion.create_revision():
|
|
cls.netfac = [
|
|
NetworkFacility.objects.create(
|
|
network=cls.net[i - 1], facility=cls.fac[i - 1], status="ok"
|
|
)
|
|
for i in entity_count
|
|
]
|
|
|
|
# create ixlans
|
|
with reversion.create_revision():
|
|
cls.ixlan = [ix.ixlan for ix in cls.ix]
|
|
|
|
# create netixlans
|
|
with reversion.create_revision():
|
|
cls.netixlan = [
|
|
NetworkIXLan.objects.create(
|
|
ixlan=cls.ixlan[i - 1],
|
|
network=cls.net[i - 1],
|
|
asn=i,
|
|
speed=0,
|
|
status="ok",
|
|
)
|
|
for i in entity_count
|
|
]
|
|
|
|
def expected_data(self, tag, fmt):
|
|
path = os.path.join(
|
|
os.path.dirname(__file__),
|
|
"data",
|
|
"export",
|
|
"advancedsearch",
|
|
f"{tag}.{fmt}",
|
|
)
|
|
with open(path) as fh:
|
|
data = fh.read().rstrip()
|
|
return data
|
|
|
|
def test_export_net_json(self):
|
|
""" test json export of network search """
|
|
client = Client()
|
|
response = client.get("/export/advanced-search/net/json?name_search=Network")
|
|
assert json.loads(response.content) == json.loads(
|
|
self.expected_data("net", "json")
|
|
)
|
|
|
|
def test_export_net_json_pretty(self):
|
|
""" test pretty json export of network search """
|
|
client = Client()
|
|
response = client.get(
|
|
"/export/advanced-search/net/json-pretty?name_search=Network"
|
|
)
|
|
|
|
assert json.loads(response.content) == json.loads(
|
|
self.expected_data("net", "jsonpretty")
|
|
)
|
|
|
|
# TODO: better check for pretty json formatting
|
|
|
|
assert len(re.findall(r"\n ", response.content.decode("utf-8"))) > 0
|
|
|
|
def test_export_net_csv(self):
|
|
""" test csv export of network search """
|
|
client = Client()
|
|
response = client.get("/export/advanced-search/net/csv?name_search=Network")
|
|
assert response.content.decode("utf-8").replace(
|
|
"\r\n", "\n"
|
|
).rstrip() == self.expected_data("net", "csv")
|
|
|
|
def test_export_fac_json(self):
|
|
""" test json export of facility search """
|
|
client = Client()
|
|
response = client.get(
|
|
"/export/advanced-search/fac/json?name__contains=Facility"
|
|
)
|
|
assert json.loads(response.content) == json.loads(
|
|
self.expected_data("fac", "json")
|
|
)
|
|
|
|
def test_export_fac_json_pretty(self):
|
|
""" test pretty json export of facility search """
|
|
client = Client()
|
|
response = client.get(
|
|
"/export/advanced-search/fac/json-pretty?name__contains=Facility"
|
|
)
|
|
|
|
assert json.loads(response.content) == json.loads(
|
|
self.expected_data("fac", "jsonpretty")
|
|
)
|
|
|
|
# TODO: better check for pretty json formatting
|
|
|
|
assert len(re.findall(r"\n ", response.content.decode("utf-8"))) > 0
|
|
|
|
def test_export_fac_csv(self):
|
|
""" test csv export of facility search """
|
|
client = Client()
|
|
response = client.get("/export/advanced-search/fac/csv?name__contains=Facility")
|
|
|
|
assert response.content.decode("utf-8").replace(
|
|
"\r\n", "\n"
|
|
).rstrip() == self.expected_data("fac", "csv")
|
|
|
|
def test_export_ix_json(self):
|
|
""" test json export of exchange search """
|
|
client = Client()
|
|
response = client.get("/export/advanced-search/ix/json?name__contains=Exchange")
|
|
self.assertEqual(
|
|
json.loads(response.content), json.loads(self.expected_data("ix", "json"))
|
|
)
|
|
|
|
def test_export_ix_json_pretty(self):
|
|
""" test pretty json export of exchange search """
|
|
client = Client()
|
|
response = client.get(
|
|
"/export/advanced-search/ix/json-pretty?name__contains=Exchange"
|
|
)
|
|
|
|
assert json.loads(response.content) == json.loads(
|
|
self.expected_data("ix", "jsonpretty")
|
|
)
|
|
|
|
# TODO: better check for pretty json formatting
|
|
|
|
assert len(re.findall(r"\n ", response.content.decode("utf-8"))) > 0
|
|
|
|
def test_export_ix_csv(self):
|
|
""" test csv export of exchange search """
|
|
client = Client()
|
|
response = client.get("/export/advanced-search/ix/csv?name__contains=Exchange")
|
|
assert response.content.decode("utf-8").replace(
|
|
"\r\n", "\n"
|
|
).rstrip() == self.expected_data("ix", "csv")
|
|
|
|
def test_export_org_json(self):
|
|
""" test json export of organization search """
|
|
client = Client()
|
|
response = client.get(
|
|
"/export/advanced-search/org/json?name_search=Organization"
|
|
)
|
|
self.assertEqual(
|
|
json.loads(response.content), json.loads(self.expected_data("org", "json"))
|
|
)
|
|
|
|
def test_export_org_json_pretty(self):
|
|
""" test pretty json export of organization search """
|
|
client = Client()
|
|
response = client.get(
|
|
"/export/advanced-search/org/json-pretty?name_search=Organization"
|
|
)
|
|
|
|
assert json.loads(response.content) == json.loads(
|
|
self.expected_data("org", "jsonpretty")
|
|
)
|
|
|
|
# TODO: better check for pretty json formatting
|
|
|
|
assert len(re.findall(r"\n ", response.content.decode("utf-8"))) > 0
|
|
|
|
def test_export_org_csv(self):
|
|
""" test csv export of organization search """
|
|
client = Client()
|
|
response = client.get(
|
|
"/export/advanced-search/org/csv?name_search=Organization"
|
|
)
|
|
assert response.content.decode("utf-8").replace(
|
|
"\r\n", "\n"
|
|
).rstrip() == self.expected_data("org", "csv")
|