-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor ipam unit tests to maintain data (#5163)
* add module-level backend fixtures for IPAM unit tests * support memgraph * move fixtures around a little more * diff cleanup and os.path cleanup * refactor to reduce duplication
- Loading branch information
1 parent
65cc50b
commit 5f62aeb
Showing
6 changed files
with
203 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
from typing import Any | ||
|
||
from infrahub import config | ||
from infrahub.core.query import Query, QueryType | ||
from infrahub.core.timestamp import Timestamp | ||
from infrahub.database import InfrahubDatabase | ||
|
||
|
||
class DeleteAfterTimeQuery(Query): | ||
name: str = "delete_after_time" | ||
insert_return: bool = False | ||
type: QueryType = QueryType.WRITE | ||
|
||
def __init__(self, timestamp: Timestamp, **kwargs: Any): | ||
self.timestamp = timestamp | ||
super().__init__(**kwargs) | ||
|
||
async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None: | ||
self.params = {"timestamp": self.timestamp.to_string()} | ||
query_1 = """ | ||
// --------------------- | ||
// Reset edges with to time after timestamp | ||
// --------------------- | ||
CALL { | ||
OPTIONAL MATCH (p)-[r]-(q) | ||
WHERE r.to > $timestamp | ||
SET r.to = NULL | ||
} | ||
""" | ||
self.add_to_query(query_1) | ||
if config.SETTINGS.database.db_type is config.DatabaseType.NEO4J: | ||
query_2 = """ | ||
// --------------------- | ||
// Delete edges with from time after timestamp timestamp | ||
// --------------------- | ||
CALL { | ||
OPTIONAL MATCH (p)-[r]->(q) | ||
WHERE r.from > $timestamp | ||
DELETE r | ||
WITH p, q | ||
UNWIND [p, q] AS maybe_orphan | ||
WITH maybe_orphan | ||
WHERE NOT exists((maybe_orphan)--()) | ||
DELETE maybe_orphan | ||
} | ||
""" | ||
else: | ||
query_2 = """ | ||
// --------------------- | ||
// Delete edges with from time after timestamp timestamp | ||
// --------------------- | ||
CALL { | ||
OPTIONAL MATCH (p)-[r]->(q) | ||
WHERE r.from > $timestamp | ||
DELETE r | ||
} | ||
""" | ||
self.add_to_query(query_2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters