mirror of
https://github.com/peeringdb/peeringdb.git
synced 2024-05-11 05:55:09 +00:00
Support 202104 (#980)
* 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>
This commit is contained in:
@@ -7,6 +7,30 @@ import googlemaps
|
||||
|
||||
import peeringdb_server.models as models
|
||||
from peeringdb_server.serializers import GeocodeSerializerMixin
|
||||
import peeringdb_server.geo as geo
|
||||
|
||||
|
||||
class MockMelissa(geo.Melissa):
|
||||
def __init__(self):
|
||||
super().__init__("")
|
||||
|
||||
def global_address(self, **kwargs):
|
||||
|
||||
return {
|
||||
"Records": [
|
||||
{
|
||||
"Results": "AV25",
|
||||
"FormattedAddress": "address 1;address 2;city",
|
||||
"AdministrativeArea": "state",
|
||||
"AddressLine1": "address 1",
|
||||
"AddressLine2": "address 2",
|
||||
"Locality": "city",
|
||||
"PostalCode": "12345",
|
||||
"Latitude": 1.234567,
|
||||
"Longitude": 1.234567,
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -43,16 +67,6 @@ def load_json(filename):
|
||||
return json_data
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def reverse():
|
||||
return load_json("reverse")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def reverse_parsed():
|
||||
return load_json("reverse_parsed")
|
||||
|
||||
|
||||
def test_geo_model_defaults(fac):
|
||||
assert fac.geocode_status is False
|
||||
assert fac.geocode_date is None
|
||||
@@ -69,34 +83,6 @@ def test_geo_model_geocode_addresss(fac):
|
||||
assert fac.geocode_address == "Some street , Chicago, IL 1234"
|
||||
|
||||
|
||||
def test_geo_model_get_address1(fac):
|
||||
data = [{"empty": "empty"}]
|
||||
assert fac.get_address1_from_geocode(data) is None
|
||||
|
||||
data = load_json("address1_test0")
|
||||
assert fac.get_address1_from_geocode(data) == "427 S LaSalle St"
|
||||
|
||||
data = load_json("address1_test1")
|
||||
assert fac.get_address1_from_geocode(data) == "427"
|
||||
|
||||
data = load_json("address1_test2")
|
||||
assert fac.get_address1_from_geocode(data) == "S LaSalle St"
|
||||
|
||||
|
||||
def test_geo_model_reverse_geocode_blank(fac):
|
||||
with pytest.raises(AttributeError):
|
||||
fac.reverse_geocode(None, "-1,1")
|
||||
|
||||
with pytest.raises(ValidationError) as exc:
|
||||
fac.reverse_geocode(None, None)
|
||||
message = "Latitude and longitude must be defined for reverse geocode lookup"
|
||||
assert message in str(exc.value)
|
||||
|
||||
|
||||
def test_geo_model_parse_reverse(fac, reverse, reverse_parsed):
|
||||
assert fac.parse_reverse_geocode(reverse) == reverse_parsed
|
||||
|
||||
|
||||
def test_need_address_suggestion(fac):
|
||||
suggested_address = {
|
||||
"name": "Geocode Fac",
|
||||
@@ -125,3 +111,91 @@ def test_does_not_need_address_suggestion(fac):
|
||||
}
|
||||
geocodeserializer = GeocodeSerializerMixin()
|
||||
assert geocodeserializer.needs_address_suggestion(suggested_address, fac) is False
|
||||
|
||||
|
||||
def test_melissa_global_address_params():
|
||||
client = geo.Melissa("")
|
||||
|
||||
expected = {
|
||||
"a1": "address 1",
|
||||
"a2": "address 2",
|
||||
"ctry": "us",
|
||||
"loc": "city",
|
||||
"postal": "12345",
|
||||
}
|
||||
|
||||
assert (
|
||||
client.global_address_params(
|
||||
address1="address 1",
|
||||
address2="address 2",
|
||||
country="us",
|
||||
city="city",
|
||||
zipcode="12345",
|
||||
)
|
||||
== expected
|
||||
)
|
||||
|
||||
|
||||
def test_melissa_global_address_best_result():
|
||||
client = geo.Melissa("")
|
||||
|
||||
expected = {"Results": "AV25", "Address1": "value1"}
|
||||
|
||||
result = {"Records": [expected, {"Results": "AV25", "Address1": "value2"}]}
|
||||
|
||||
assert client.global_address_best_result(result) == expected
|
||||
assert client.global_address_best_result({}) == None
|
||||
assert client.global_address_best_result(None) == None
|
||||
|
||||
result = {"Records": [{"Results": "AV12", "Address1": "value2"}]}
|
||||
|
||||
assert client.global_address_best_result(result) == None
|
||||
|
||||
|
||||
def test_melissa_apply_global_address():
|
||||
|
||||
client = geo.Melissa("")
|
||||
|
||||
data = client.apply_global_address(
|
||||
{
|
||||
"address1": "address1 old",
|
||||
"city": "city old",
|
||||
"zipcode": "zipcode old",
|
||||
},
|
||||
{
|
||||
"Results": "AV25",
|
||||
"FormattedAddress": "address1 new;address2 new",
|
||||
"AdministrativeArea": "state new",
|
||||
"AddressLine1": "address1 new",
|
||||
"AddressLine2": "address2 new",
|
||||
"Latitude": 1.234567,
|
||||
"Longitude": 1.234567,
|
||||
"PostalCode": "zipcode new",
|
||||
"Locality": "city new",
|
||||
},
|
||||
)
|
||||
|
||||
expected = {
|
||||
"address1": "address1 new",
|
||||
"address2": "address2 new",
|
||||
"city": "city new",
|
||||
"zipcode": "zipcode new",
|
||||
"longitude": 1.234567,
|
||||
"latitude": 1.234567,
|
||||
"state": "state new",
|
||||
}
|
||||
|
||||
assert data == expected
|
||||
|
||||
|
||||
def test_melissa_sanitize(fac):
|
||||
|
||||
client = MockMelissa()
|
||||
|
||||
sanitized = client.sanitize_address_model(fac)
|
||||
|
||||
assert sanitized["address1"] == "address 1"
|
||||
assert sanitized["city"] == "city"
|
||||
assert sanitized["latitude"] == 1.234567
|
||||
assert sanitized["longitude"] == 1.234567
|
||||
assert sanitized["zipcode"] == "12345"
|
||||
|
Reference in New Issue
Block a user