mirror of
https://github.com/peeringdb/peeringdb.git
synced 2024-05-11 05:55:09 +00:00
Fix pending campus sync (#1428)
* allow syncing of pending campuses through incremental sync * linting
This commit is contained in:
@@ -3100,6 +3100,22 @@ class TestJSON(unittest.TestCase):
|
||||
|
||||
##########################################################################
|
||||
|
||||
def test_guest_005_list_campus_since(self):
|
||||
# test that pending campuses are included in incremental update
|
||||
# query (?since parameter)
|
||||
|
||||
data = self.db_guest.all(
|
||||
"campus", since=int(START_TIMESTAMP) - 10, status="pending"
|
||||
)
|
||||
self.assertEqual(len(data), 7)
|
||||
self.assert_handleref_integrity(data[0])
|
||||
self.assert_data_integrity(data[0], "campus")
|
||||
|
||||
for row in data:
|
||||
assert row["status"] == "pending"
|
||||
|
||||
##########################################################################
|
||||
|
||||
def test_guest_005_list_carrier_no_website(self):
|
||||
carrier = SHARED["carrier_rw_ok"]
|
||||
carrier.website = ""
|
||||
|
||||
@@ -612,7 +612,23 @@ class ModelViewSet(viewsets.ModelViewSet):
|
||||
|
||||
if not self.kwargs:
|
||||
if since > 0:
|
||||
# .filter(status__in=["ok","deleted"])
|
||||
# incremental update query (used by peeringdb-py client
|
||||
# to handle incremental updates, will include `deleted` objects)
|
||||
|
||||
allowed_status = ["ok", "deleted"]
|
||||
|
||||
if self.model.HandleRef.tag == "campus":
|
||||
# Special treatment for campus objects, since their status
|
||||
# is fluid, depending on the number of facilities. #1472
|
||||
#
|
||||
# If the campus has less than 2 facilities in it is considered pending
|
||||
# If the campus has 2 or more facilities in it is considered ok
|
||||
#
|
||||
# Pending campuses need to be included in the incremental update , since
|
||||
# a pending campus may be referenced by a facility
|
||||
|
||||
allowed_status.append("pending")
|
||||
|
||||
qset = (
|
||||
qset.since(
|
||||
timestamp=datetime.datetime.fromtimestamp(since).replace(
|
||||
@@ -621,7 +637,7 @@ class ModelViewSet(viewsets.ModelViewSet):
|
||||
deleted=True,
|
||||
)
|
||||
.order_by("updated")
|
||||
.filter(status__in=["ok", "deleted"])
|
||||
.filter(status__in=allowed_status)
|
||||
)
|
||||
else:
|
||||
qset = qset.filter(status="ok")
|
||||
|
||||
Reference in New Issue
Block a user