Add full application management API, UI and test cases
This commit is contained in:
parent
a3eff7a2e8
commit
f7c27f250b
16 changed files with 904 additions and 15 deletions
|
@ -27,7 +27,9 @@ from endpoints.api.billing import (UserCard, UserPlan, ListPlans, OrganizationCa
|
|||
from endpoints.api.discovery import DiscoveryResource
|
||||
from endpoints.api.organization import (OrganizationList, OrganizationMember,
|
||||
OrgPrivateRepositories, OrgnaizationMemberList,
|
||||
Organization)
|
||||
Organization, ApplicationInformation,
|
||||
OrganizationApplications, OrganizationApplicationResource,
|
||||
OrganizationApplicationResetClientSecret)
|
||||
from endpoints.api.repository import RepositoryList, RepositoryVisibility, Repository
|
||||
from endpoints.api.permission import (RepositoryUserPermission, RepositoryTeamPermission,
|
||||
RepositoryTeamPermissionList, RepositoryUserPermissionList)
|
||||
|
@ -55,6 +57,7 @@ NEW_USER_DETAILS = {
|
|||
'email': 'bobby@tables.com',
|
||||
}
|
||||
|
||||
FAKE_APPLICATION_CLIENT_ID = 'deadbeef'
|
||||
|
||||
class ApiTestCase(unittest.TestCase):
|
||||
def setUp(self):
|
||||
|
@ -1391,6 +1394,103 @@ class TestLogs(ApiTestCase):
|
|||
self.assertEquals(READ_ACCESS_USER, log['performer']['name'])
|
||||
|
||||
|
||||
class TestApplicationInformation(ApiTestCase):
|
||||
def test_get_info(self):
|
||||
json = self.getJsonResponse(ApplicationInformation, params=dict(client_id=FAKE_APPLICATION_CLIENT_ID))
|
||||
assert 'name' in json
|
||||
assert 'uri' in json
|
||||
assert 'organization' in json
|
||||
|
||||
def test_get_invalid_info(self):
|
||||
self.getJsonResponse(ApplicationInformation, params=dict(client_id='invalid-code'),
|
||||
expected_code=404)
|
||||
|
||||
|
||||
class TestOrganizationApplications(ApiTestCase):
|
||||
def test_list_create_applications(self):
|
||||
self.login(ADMIN_ACCESS_USER)
|
||||
|
||||
json = self.getJsonResponse(OrganizationApplications, params=dict(orgname=ORGANIZATION))
|
||||
|
||||
self.assertEquals(2, len(json['applications']))
|
||||
self.assertEquals(FAKE_APPLICATION_CLIENT_ID, json['applications'][0]['client_id'])
|
||||
|
||||
# Add a new application.
|
||||
json = self.postJsonResponse(OrganizationApplications, params=dict(orgname=ORGANIZATION),
|
||||
data=dict(name="Some cool app", description="foo"))
|
||||
|
||||
self.assertEquals("Some cool app", json['name'])
|
||||
self.assertEquals("foo", json['description'])
|
||||
|
||||
# Retrieve the apps list again
|
||||
list_json = self.getJsonResponse(OrganizationApplications, params=dict(orgname=ORGANIZATION))
|
||||
self.assertEquals(3, len(list_json['applications']))
|
||||
self.assertEquals(json, list_json['applications'][2])
|
||||
|
||||
|
||||
class TestOrganizationApplicationResource(ApiTestCase):
|
||||
def test_get_edit_delete_application(self):
|
||||
self.login(ADMIN_ACCESS_USER)
|
||||
|
||||
# Retrieve the application.
|
||||
json = self.getJsonResponse(OrganizationApplicationResource,
|
||||
params=dict(orgname=ORGANIZATION, client_id=FAKE_APPLICATION_CLIENT_ID))
|
||||
|
||||
self.assertEquals(FAKE_APPLICATION_CLIENT_ID, json['client_id'])
|
||||
|
||||
# Edit the application.
|
||||
edit_json = self.putJsonResponse(OrganizationApplicationResource,
|
||||
params=dict(orgname=ORGANIZATION, client_id=FAKE_APPLICATION_CLIENT_ID),
|
||||
data=dict(name="Some App", description="foo", application_uri="bar",
|
||||
redirect_uri="baz", gravatar_email="meh"))
|
||||
|
||||
self.assertEquals(FAKE_APPLICATION_CLIENT_ID, edit_json['client_id'])
|
||||
self.assertEquals("Some App", edit_json['name'])
|
||||
self.assertEquals("foo", edit_json['description'])
|
||||
self.assertEquals("bar", edit_json['application_uri'])
|
||||
self.assertEquals("baz", edit_json['redirect_uri'])
|
||||
self.assertEquals("meh", edit_json['gravatar_email'])
|
||||
|
||||
# Retrieve the application again.
|
||||
json = self.getJsonResponse(OrganizationApplicationResource,
|
||||
params=dict(orgname=ORGANIZATION, client_id=FAKE_APPLICATION_CLIENT_ID))
|
||||
|
||||
self.assertEquals(json, edit_json)
|
||||
|
||||
# Delete the application.
|
||||
self.deleteResponse(OrganizationApplicationResource,
|
||||
params=dict(orgname=ORGANIZATION, client_id=FAKE_APPLICATION_CLIENT_ID))
|
||||
|
||||
# Make sure the application is gone.
|
||||
self.getJsonResponse(OrganizationApplicationResource,
|
||||
params=dict(orgname=ORGANIZATION, client_id=FAKE_APPLICATION_CLIENT_ID),
|
||||
expected_code=404)
|
||||
|
||||
|
||||
class TestOrganizationApplicationResetClientSecret(ApiTestCase):
|
||||
def test_reset_client_secret(self):
|
||||
self.login(ADMIN_ACCESS_USER)
|
||||
|
||||
# Retrieve the application.
|
||||
json = self.getJsonResponse(OrganizationApplicationResource,
|
||||
params=dict(orgname=ORGANIZATION, client_id=FAKE_APPLICATION_CLIENT_ID))
|
||||
|
||||
self.assertEquals(FAKE_APPLICATION_CLIENT_ID, json['client_id'])
|
||||
|
||||
# Reset the client secret.
|
||||
reset_json = self.postJsonResponse(OrganizationApplicationResetClientSecret,
|
||||
params=dict(orgname=ORGANIZATION, client_id=FAKE_APPLICATION_CLIENT_ID))
|
||||
|
||||
self.assertEquals(FAKE_APPLICATION_CLIENT_ID, reset_json['client_id'])
|
||||
self.assertNotEquals(reset_json['client_secret'], json['client_secret'])
|
||||
|
||||
# Verify it was changed in the DB.
|
||||
json = self.getJsonResponse(OrganizationApplicationResource,
|
||||
params=dict(orgname=ORGANIZATION, client_id=FAKE_APPLICATION_CLIENT_ID))
|
||||
self.assertEquals(reset_json['client_secret'], json['client_secret'])
|
||||
|
||||
|
||||
|
||||
class FakeBuildTrigger(BuildTriggerBase):
|
||||
@classmethod
|
||||
def service_name(cls):
|
||||
|
|
Reference in a new issue