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

Verified Commit 0a60762a authored by Emi Simpson's avatar Emi Simpson
Browse files

[new arch] Test RetreiveProjectInfoIfOwned

parent b020ac74
......@@ -4,6 +4,13 @@ from mystic.queries import *
def panic():
raise Exception("This code shouldn't've run!")
null_result = QueryResult(0, 0, panic, panic)
none_result = QueryResult(0, -1, lambda: None, lambda: [])
def next_and_all(results: Sequence[Tuple[Any, ...]]) -> Tuple[Callable[[], Tuple[Any, ...]], Callable[[], Sequence[Tuple[Any, ...]]]]:
return (
lambda: results[0],
lambda: results
)
class TestQueries(unittest.TestCase):
def assert_then_return(self, equal_to: str) -> Callable[[str], Query[int, NoReturn]]:
......@@ -157,3 +164,28 @@ class TestQueries(unittest.TestCase):
Exception,
delete_source.handle_results,
SqlIntegrityError(SqlErrorCode.BAD_NULL_ERROR, 'unexpected error'))
def test_retreive_project_info_if_owned(self):
retreive_info = RetreiveProjectInfoIfOwned(UncheckedPID(100), UserID(200))
self.assertEqual(
retreive_info.get_query(),
QueryRequest('''
SELECT project_id, slug, display_name, description, draft_owner
FROM owners
JOIN projects USING (project_id)
WHERE project_id = %s
AND user_id = %s;
''',
(100, 200)))
self.assertEqual(
retreive_info.handle_results(QueryResult(
1, 100,
*next_and_all([(100, 'my_project', 'My Project', 'A project that is mine', None)]))),
Finished(ProjectInfo(ProjectID(UncheckedPID(100)), 'my_project', 'My Project', 'A project that is mine', None)))
self.assertEqual(
retreive_info.handle_results(none_result),
Error(None))
self.assertRaises(
Exception,
retreive_info.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