- 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
This commit is contained in:
Joseph Schorr 2014-07-08 18:19:13 -04:00
parent 3ebdf2c062
commit b0c4f5b2f5
4 changed files with 32 additions and 10 deletions

View file

@ -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.

View file

@ -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)

View file

@ -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'

View file

@ -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)