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

Verified Commit e66f75e5 authored by Emi Simpson's avatar Emi Simpson
Browse files

[new arch] Test UpdateProjectProperties and AddOwnerByUsername

parent 8c9917e9
Pipeline #864 passed with stage
in 55 seconds
......@@ -228,3 +228,79 @@ class TestQueries(unittest.TestCase):
Exception,
retreive_info.handle_results,
SqlIntegrityError(SqlErrorCode.BAD_NULL_ERROR, 'unexpected'))
def test_add_owner_by_username(self):
add_owner = AddOwnerByUsername('alch_emi', ProjectID(UncheckedPID(1312)))
self.assertEqual(
add_owner.get_query(),
QueryRequest('''
INSERT INTO owners(user_id, project_id)
SELECT user_id, %s
FROM users
WHERE users.username = %s;
''', (1312, 'alch_emi')))
self.assertEqual(
add_owner.handle_results(QueryResult(1, -1, panic, panic)),
Finished(None))
self.assertEqual(
add_owner.handle_results(SqlIntegrityError(SqlErrorCode.NO_REFERENCED_ROW, '')),
Error(AddOwnerError.NonexistantProject))
self.assertEqual(
add_owner.handle_results(SqlIntegrityError(SqlErrorCode.DUP_ENTRY, '')),
Error(AddOwnerError.DuplicateOwner))
self.assertRaises(
Exception,
add_owner.handle_results,
SqlIntegrityError(SqlErrorCode.BAD_NULL_ERROR, 'unexpected'))
def test_update_project(self):
update_project = UpdateProjectProperties(ProjectID(UncheckedPID(1312)), 'sluggity', 'Display Name', None)
self.assertEqual(
update_project.get_query(),
QueryRequest('''
UPDATE projects
SET
slug = %s,
display_name = %s
WHERE project_id = %s;
''', ('sluggity', 'Display Name', 1312)))
self.assertEqual(
update_project.handle_results(QueryResult(1, 1312, panic, panic)),
Finished(False))
self.assertEqual(
update_project.handle_results(none_result),
Error(UpdateProjectError.NonexistantProjectOrNoChange))
self.assertEqual(
update_project.handle_results(SqlIntegrityError(SqlErrorCode.DUP_ENTRY, '')),
Error(UpdateProjectError.DuplicateSlug))
self.assertRaises(
Exception,
update_project.handle_results,
SqlIntegrityError(SqlErrorCode.BAD_NULL_ERROR, 'unexpected'))
del update_project
update_project = UpdateProjectProperties(ProjectID(UncheckedPID(1312)), 'sluggity', 'Display Name', 'Description goes here')
self.assertEqual(
update_project.get_query(),
QueryRequest('''
UPDATE projects
SET
slug = %s,
display_name = %s,
description = %s,
draft_owner=NULL
WHERE project_id = %s;
''', ('sluggity', 'Display Name', 'Description goes here', 1312)))
self.assertEqual(
update_project.handle_results(QueryResult(1, 1312, panic, panic)),
Finished(True))
self.assertEqual(
update_project.handle_results(none_result),
Error(UpdateProjectError.NonexistantProjectOrNoChange))
self.assertEqual(
update_project.handle_results(SqlIntegrityError(SqlErrorCode.DUP_ENTRY, '')),
Error(UpdateProjectError.DuplicateSlug))
self.assertRaises(
Exception,
update_project.handle_results,
SqlIntegrityError(SqlErrorCode.BAD_NULL_ERROR, 'unexpected'))
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