Add support for deleting namespaces (users, organizations)

Fixes #102
Fixes #105
This commit is contained in:
Joseph Schorr 2016-08-09 17:58:33 -04:00
parent a74e94fb67
commit 73eb66eac5
23 changed files with 407 additions and 33 deletions

View file

@ -21,7 +21,7 @@ from mockldap import MockLdap
from endpoints.api import api_bp, api
from endpoints.building import PreparedBuild
from endpoints.webhooks import webhooks
from app import app, config_provider, notification_queue
from app import app, config_provider, all_queues, dockerfile_build_queue, notification_queue
from buildtrigger.basehandler import BuildTriggerHandler
from initdb import setup_database_for_testing, finished_database_for_testing
from data import database, model
@ -581,7 +581,6 @@ class TestCreateNewUser(ApiTestCase):
teamname='owners'))
self.assertNotInTeam(json, NEW_USER_DETAILS['username'])
def test_createuser_withteaminvite_differentemails(self):
inviter = model.user.get_user(ADMIN_ACCESS_USER)
team = model.team.get_organization_team(ORGANIZATION, 'owners')
@ -606,6 +605,32 @@ class TestCreateNewUser(ApiTestCase):
self.assertNotInTeam(json, NEW_USER_DETAILS['username'])
class TestDeleteNamespace(ApiTestCase):
def test_deletenamespaces(self):
self.login(ADMIN_ACCESS_USER)
# Try to first delete the user. Since they are the sole admin of two orgs, it should fail.
with check_transitive_deletes():
self.deleteResponse(User, expected_code=400)
# Delete the two orgs, checking in between.
with check_transitive_deletes():
self.deleteResponse(Organization, params=dict(orgname=ORGANIZATION), expected_code=204)
self.deleteResponse(User, expected_code=400) # Should still fail.
self.deleteResponse(Organization, params=dict(orgname='library'), expected_code=204)
# Add some queue items for the user.
notification_queue.put([ADMIN_ACCESS_USER, 'somerepo', 'somename'], '{}')
dockerfile_build_queue.put([ADMIN_ACCESS_USER, 'anotherrepo'], '{}')
# Now delete the user.
with check_transitive_deletes():
self.deleteResponse(User, expected_code=204)
# Ensure the queue items are gone.
self.assertIsNone(notification_queue.get())
self.assertIsNone(dockerfile_build_queue.get())
class TestSignin(ApiTestCase):
def test_signin_unicode(self):
@ -1798,13 +1823,37 @@ class TestDeleteRepository(ApiTestCase):
self.getResponse(Repository,
params=dict(repository=self.SIMPLE_REPO))
# Add a build queue item for the repo.
dockerfile_build_queue.put([ADMIN_ACCESS_USER, 'simple'], '{}')
# Delete the repository.
self.deleteResponse(Repository, params=dict(repository=self.SIMPLE_REPO))
# Ensure the queue item is gone.
self.assertIsNone(dockerfile_build_queue.get())
# Verify the repo was deleted.
self.getResponse(Repository,
params=dict(repository=self.SIMPLE_REPO),
expected_code=404)
def test_verify_queue_removal(self):
self.login(ADMIN_ACCESS_USER)
# Verify the repo exists.
self.getResponse(Repository,
params=dict(repository=self.SIMPLE_REPO))
# Add a build queue item for the repo and another repo.
dockerfile_build_queue.put([ADMIN_ACCESS_USER, 'simple'], '{}')
dockerfile_build_queue.put([ADMIN_ACCESS_USER, 'anotherrepo'], '{}')
# Delete the repository.
self.deleteResponse(Repository, params=dict(repository=self.SIMPLE_REPO))
# Ensure the other queue item is still present.
self.assertIsNotNone(dockerfile_build_queue.get())
def test_deleterepo2(self):
self.login(ADMIN_ACCESS_USER)
@ -3717,7 +3766,7 @@ class TestSuperUserCreateInitialSuperUser(ApiTestCase):
# Delete all users in the DB.
for user in list(database.User.select()):
user.delete_instance(recursive=True)
model.user.delete_user(user, all_queues, force=True)
# Create the superuser.
self.postJsonResponse(SuperUserCreateInitialSuperUser, data=data)