From b0c4f5b2f5e0b59c01403ffbecc1ac6733e8ad0e Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Tue, 8 Jul 2014 18:19:13 -0400 Subject: [PATCH] - Fix tests to not hit remote Redis endpoint - Fix convert organization to allow admin email address, in addition to username - Add test for the above --- endpoints/api/user.py | 5 +++-- test/test_api_usage.py | 30 ++++++++++++++++++++++++------ test/testconfig.py | 2 +- test/testlogs.py | 5 ++++- 4 files changed, 32 insertions(+), 10 deletions(-) diff --git a/endpoints/api/user.py b/endpoints/api/user.py index 41012e8ab..3f54dbf2a 100644 --- a/endpoints/api/user.py +++ b/endpoints/api/user.py @@ -296,7 +296,8 @@ class ConvertToOrganization(ApiResource): # Ensure that the sign in credentials work. admin_password = convert_data['adminPassword'] - if not authentication.verify_user(admin_username, admin_password): + admin_user = authentication.verify_user(admin_username, admin_password) + if not admin_user: raise request_error(reason='invaliduser', message='The admin user credentials are not valid') @@ -306,7 +307,7 @@ class ConvertToOrganization(ApiResource): subscribe(user, plan, None, True) # Require business plans # Convert the user to an organization. - model.convert_user_to_organization(user, model.get_user(admin_username)) + model.convert_user_to_organization(user, admin_user) log_action('account_convert', user.username) # And finally login with the admin credentials. diff --git a/test/test_api_usage.py b/test/test_api_usage.py index 96f894d11..141054429 100644 --- a/test/test_api_usage.py +++ b/test/test_api_usage.py @@ -53,6 +53,8 @@ READ_ACCESS_USER = 'reader' ADMIN_ACCESS_USER = 'devtable' PUBLIC_USER = 'public' +ADMIN_ACCESS_EMAIL = 'jschorr@devtable.com' + ORG_REPO = 'orgrepo' ORGANIZATION = 'buynlarge' @@ -274,6 +276,28 @@ class TestConvertToOrganization(ApiTestCase): self.assertEquals(True, json['is_admin']) + def test_convert_via_email(self): + self.login(READ_ACCESS_USER) + json = self.postJsonResponse(ConvertToOrganization, + data={'adminUser': ADMIN_ACCESS_EMAIL, + 'adminPassword': 'password', + 'plan': 'free'}) + + self.assertEqual(True, json['success']) + + # Verify the organization exists. + organization = model.get_organization(READ_ACCESS_USER) + assert organization is not None + + # Verify the admin user is the org's admin. + self.login(ADMIN_ACCESS_USER) + json = self.getJsonResponse(Organization, + params=dict(orgname=READ_ACCESS_USER)) + + self.assertEquals(READ_ACCESS_USER, json['name']) + self.assertEquals(True, json['is_admin']) + + class TestChangeUserDetails(ApiTestCase): def test_changepassword(self): self.login(READ_ACCESS_USER) @@ -982,12 +1006,6 @@ class TestRepoBuilds(ApiTestCase): self.assertEquals(status_json, build) - # Check the logs. - logs_json = self.getJsonResponse(RepositoryBuildLogs, - params=dict(repository=ADMIN_ACCESS_USER + '/building', build_uuid=build['id'])) - - assert 'logs' in logs_json - class TestRequestRepoBuild(ApiTestCase): def test_requestrepobuild(self): self.login(ADMIN_ACCESS_USER) diff --git a/test/testconfig.py b/test/testconfig.py index 8d7989c6e..716b8a36f 100644 --- a/test/testconfig.py +++ b/test/testconfig.py @@ -28,7 +28,7 @@ class TestConfig(DefaultConfig): DISTRIBUTED_STORAGE_PREFERENCE = ['local_us'] BUILDLOGS_MODULE_AND_CLASS = ('test.testlogs', 'testlogs.TestBuildLogs') - BUILDLOGS_OPTIONS = ['devtable', 'building', 'deadbeef-dead-beef-dead-beefdeadbeef'] + BUILDLOGS_OPTIONS = ['devtable', 'building', 'deadbeef-dead-beef-dead-beefdeadbeef', False] USERFILES_TYPE = 'FakeUserfiles' diff --git a/test/testlogs.py b/test/testlogs.py index fa3c2bec2..8ea09e58e 100644 --- a/test/testlogs.py +++ b/test/testlogs.py @@ -42,11 +42,12 @@ class TestBuildLogs(RedisBuildLogs): 'pull_completion': 0.0, } - def __init__(self, redis_host, namespace, repository, test_build_id): + def __init__(self, redis_host, namespace, repository, test_build_id, allow_delegate=True): super(TestBuildLogs, self).__init__(redis_host) self.namespace = namespace self.repository = repository self.test_build_id = test_build_id + self.allow_delegate = allow_delegate self.remaining_script = self._generate_script() logger.debug('Total script size: %s', len(self.remaining_script)) self._logs = [] @@ -188,5 +189,7 @@ class TestBuildLogs(RedisBuildLogs): returnable_status = self._last_status self._last_status = self._status return returnable_status + elif not self.allow_delegate: + return None else: return super(TestBuildLogs, self).get_status(build_id)