IEEE.org     |     IEEE Xplore Digital Library     |     IEEE Standards     |     IEEE Spectrum     |     More Sites

Verified Commit 2cbec3db authored by Emi Simpson's avatar Emi Simpson
Browse files

[new arch] test delete source query + add query requst equality checking

parent b552073f
Pipeline #855 passed with stage
in 1 minute and 1 second
......@@ -25,6 +25,18 @@ class QueryRequest(NamedTuple):
query: str
args: Tuple[Any, ...] | List[Any]
def __eq__(self, other: object) -> bool:
return\
isinstance(other, QueryRequest) and\
self.args == other.args and\
self.query.lower().split() == other.query.lower().split()\
or\
isinstance(other, Tuple) and\
other.__len__() == 2 and\
isinstance(other[0], str) and\
(isinstance(other[1], Tuple) or isinstance(other[1], List)) and\
self == QueryRequest(*cast(Tuple[str, Tuple[Any, ...] | List[Any]], other))
T = TypeVar('T', covariant=True)
E = TypeVar('E', covariant=True)
......
......@@ -101,3 +101,28 @@ class TestQueries(unittest.TestCase):
r2 = q2.handle_results(null_result)
assert isinstance(r2, Error)
self.assertEqual(r2.value, 'JAN ALE O TOKI')
def test_delete_source(self):
delete_source = DeleteSourceIfOwned(100, UserID(200))
self.assertEqual(
delete_source.get_query(),
QueryRequest('''
DELETE FROM data_sources
WHERE source_id = %s
AND project_id IN (
SELECT project_id
FROM owners
WHERE user_id = %s
);
''',
(100, 200)))
self.assertEqual(
delete_source.handle_results(QueryResult(1, 123, panic, panic)),
Finished(100))
self.assertEqual(
delete_source.handle_results(QueryResult(0, -1, panic, panic)),
Error(100))
self.assertRaises(
Exception,
delete_source.handle_results,
SqlIntegrityError(SqlErrorCode.BAD_NULL_ERROR, 'unexpected error'))
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment