1
0
mirror of https://github.com/peeringdb/peeringdb.git synced 2024-05-11 05:55:09 +00:00
Files
peeringdb-peeringdb/tests/test_signals.py
Matt Griswold b07baf3092 Support 202011 (#917)
* install django-grainy

* nsp to grainy first iteration

* Fix validation error message overflow

* Add migration, update views.py and template to add help_text to UI

* nsp to grainy second iteration

* grainy and django-grainy pinned to latest releases

* deskpro ticket cc (#875)

* black formatting

* move ac link to bottom for ticket body

* Fix typo

* Update djangorestframework, peeringdb, django-ratelimit

* Rewrite login view ratelimit decorator

* Relock pipfile

* add list() to make copy of dictionaries before iterating

* respect ix-f url visibilty in ix-f conflict emails

* Add type coercion to settings taken from environment variables

* Add bool handling

* relock pipfile with python3.9
change docker to use python3.9

* Check bool via isinstance

* add ordering to admin search queryset for deskproticket and email

* update settings with envvar_type option

* Add tooltips to add ix and add exchange views (in org)

* Add tooltip to suggest fac view

* get phone information in view

* add missing migration

* add migration and make org a geo model

* Wire normalization to put/create requests for Facility

* Update admin with new address fields

* Refactor serializer using mixin

* Add floor and suite to address API

* Write command to geonormalize existing entries

* Remove unnecessary method from model

* Add floor and suite to views

* Add ignore geo status

* Force refresh for fac and org updates

* adjust frontend typo

* add checking if update needs geosync

* redo error handling for geosync

* remove save keyword from geonormalize command script

* change raw_id_fields

* alternate autocomplete lookup field depending on where inline is called

* remove unnecessary error handling

* Add  csv option

* Fix bug
 with None vs empty string

* add regex parsing for suite and floor conversion

* Add migration that removes geo error as a field

* add geostatus update to command

* Ignore suite floor and address2 changes for api normalization

* update geomodel by removing geo_error

* Black models.py

* Black serializers.py

* remove geocode error from admin

* Add function for reversing pretty speed

* add conversion to export method

* fix typo

* fix speed value feedback after submit

* remove conditional

* Add error handling to create endpoint

* Refine floor and suite parsing regex

* Add geocoding tests

* Add json for tests

* IX-F Importer: Bogus output of "Preview" tool #896

* remove cruft

* black formatting

* IX-F Importer: history of changes per ixlan & netixlan #893

* 6 add geocode to org view

* 4 update geocode without refresh

* Update error display

* Fix bug with formatting translated string

* Add DateTimeFields to model

* Add update signals

* add last updated fields to views and serializers

* Add last updated model migration

* Add the data migration for last updated fields

* add test that tests a normal org user with create org permissions

* grainy to 1.7
django grainy to 1.9.1

* Fix formatting issues

* Adjust var names

* Refactor signals

* Temporary: save override from network model

* Empty vlan lists no longer cause error

* typo in ixf.py

* typo in admin

* Typos in model verbose names

* Add serializer IXLAN validation for ixf_ixp_import_enabled

* Add model validation to IXLan

* relock pipfile

* relock pipfile

* begin signal test file

* Remove full clean from save in ixlan

* use post_reversion_commit signal instead

* remove redundant save override

* remove cruft / debug code

* Add signal tests

* exclude organizations with city missing from commandline geosync

* Skip geosync if the only address information we have is a country

* initial commit for vlan matcher in importer

* Add more tests and remove unused imports

* update tests

* Actually add vlan matching to importer

* Add type checking for speed list and state

* Change how we register connection.state

* add bootstrap options

* add rdap cache command

* remove outdated perm docs

* rdap from master and relock

* propagate rdap settings to peeringdb.settings

* add loaddata for initial fixtures

* user friendly error message on RdapNotFound errors (#497)

* update rdap errors

* django-peeringdb to 2.5.0 and relock

* rdap to 1.2.0 and relock

* fix migration hierarchy

* add ignore_recurse_errors option

* add missing fields to mock
remove cruft missed during merge

* rdap to 1.2.1

* dont geo validate during api tests

* fix tests

* Add test file

* fix merge

* RDAP_SELF_BOOTSTRAP to False while running tests

* black formatted

* run black

* add github actions

* add runs on

Co-authored-by: Stefan Pratter <stefan@20c.com>
Co-authored-by: Elliot Frank <elliot@20c.com>
2021-01-13 14:35:07 -06:00

186 lines
5.0 KiB
Python

from peeringdb_server.models import (
Organization,
Network,
NetworkIXLan,
InternetExchange,
Facility,
NetworkFacility,
NetworkContact,
)
import pytest
from datetime import datetime, timezone, timedelta
import reversion
import time
def now():
return datetime.now(timezone.utc)
def two_weeks_ago():
return datetime.now(timezone.utc) - timedelta(days=14)
def assert_same_time(time1, time2, eps=100):
threshold = timedelta(milliseconds=eps)
assert (time1 - time2) < threshold
@pytest.fixture()
def entities():
with reversion.create_revision():
org = Organization.objects.create(name="Netflix", status="ok")
network = Network.objects.create(
name="Network",
asn=123,
org=org,
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,
)
ix = InternetExchange.objects.create(
name="Test Exchange One",
org=org,
status="ok",
tech_email="ix1@localhost",
)
facility = Facility.objects.create(
name="Facility",
status="ok",
city="City",
clli="CLLI",
state="MD",
country="US",
zipcode=1,
org=org,
)
netfac = NetworkFacility.objects.create(
network=network,
facility=facility,
status="ok",
)
netixlan = NetworkIXLan.objects.create(
network=network,
ixlan=ix.ixlan,
asn=network.asn,
speed=1,
ipaddr4="195.69.147.250",
ipaddr6="2001:7f8:1::a500:2906:1",
status="ok",
is_rs_peer=True,
operational=False,
)
poc = NetworkContact.objects.create(
email="network1@localhost", network=network, status="ok", role="Policy"
)
return {
"facility": facility,
"org": org,
"ix": ix,
"network": network,
"netfac": netfac,
"netixlan": netixlan,
"poc": poc,
}
def null_network_update_fields(network):
network._meta.get_field("updated").auto_now = False
network.netixlan_updated = None
network.netfac_updated = None
network.poc_updated = None
network.updated = two_weeks_ago()
network.save()
network._meta.get_field("updated").auto_now = True
network.refresh_from_db()
return network
def print_all(network):
print(f"netixlan updated: {network.netixlan_updated}")
print(f"Netfac updated: {network.netfac_updated}")
print(f"poc updated: {network.poc_updated}")
@pytest.mark.django_db
def test_netixlan_update(entities):
netixlan = NetworkIXLan.objects.first()
network = Network.objects.first()
network = null_network_update_fields(network)
assert network.netixlan_updated is None
assert network.netfac_updated is None
assert network.poc_updated is None
# update netixlan
netixlan.speed = 2000
with reversion.create_revision():
netixlan.save()
network.refresh_from_db()
# Check that netixlan_updated reflects the netixlan change and is recent
assert_same_time(network.netixlan_updated, netixlan.updated)
assert network.netfac_updated is None
assert network.poc_updated is None
assert_same_time(network.updated, two_weeks_ago())
@pytest.mark.django_db
def test_netfac_update(entities):
netfac = NetworkFacility.objects.first()
network = Network.objects.first()
network = null_network_update_fields(network)
assert network.netixlan_updated is None
assert network.netfac_updated is None
assert network.poc_updated is None
# update netfac
netfac.status = "deleted"
with reversion.create_revision():
netfac.save()
network.refresh_from_db()
# Check that netixlan_updated reflects the netixlan change and is recent
assert_same_time(network.netfac_updated, netfac.updated)
assert network.netixlan_updated is None
assert network.poc_updated is None
assert_same_time(network.updated, two_weeks_ago())
@pytest.mark.django_db
def test_poc_update(entities):
poc = NetworkContact.objects.first()
network = Network.objects.first()
network = null_network_update_fields(network)
assert network.netixlan_updated is None
assert network.netfac_updated is None
assert network.poc_updated is None
# update poc
poc.phone = "555-555-5555"
with reversion.create_revision():
poc.save()
network.refresh_from_db()
# Check that netixlan_updated reflects the netixlan change and is recent
assert_same_time(network.poc_updated, poc.updated)
assert network.netixlan_updated is None
assert network.netfac_updated is None
assert_same_time(network.updated, two_weeks_ago())