Return application/problem+json format errors and provide error endpoint
to dereference error codes.
This commit is contained in:
parent
8c81915f38
commit
9c08717173
7 changed files with 156 additions and 39 deletions
|
@ -44,6 +44,7 @@ from endpoints.api.logs import UserLogs, OrgLogs, OrgAggregateLogs, UserAggregat
|
|||
from endpoints.api.billing import (UserCard, UserPlan, ListPlans, OrganizationCard,
|
||||
OrganizationPlan)
|
||||
from endpoints.api.discovery import DiscoveryResource
|
||||
from endpoints.api.error import ApiError
|
||||
from endpoints.api.organization import (OrganizationList, OrganizationMember,
|
||||
OrgPrivateRepositories, OrganizationMemberList,
|
||||
Organization, ApplicationInformation,
|
||||
|
@ -236,6 +237,14 @@ class TestDiscovery(ApiTestCase):
|
|||
assert 'paths' in json
|
||||
|
||||
|
||||
class TestError(ApiTestCase):
|
||||
def test_get_error(self):
|
||||
json = self.getJsonResponse(APIError, data=dict(error='not_found'))
|
||||
assert json['title'] == 'not_found'
|
||||
assert type in json
|
||||
assert description in json
|
||||
|
||||
|
||||
class TestPlans(ApiTestCase):
|
||||
def test_plans(self):
|
||||
json = self.getJsonResponse(ListPlans)
|
||||
|
@ -276,7 +285,7 @@ class TestUserStarredRepositoryList(ApiTestCase):
|
|||
},
|
||||
expected_code=401)
|
||||
|
||||
def test_star_and_unstar_repo_user(self):
|
||||
def test_star_and_uznstar_repo_user(self):
|
||||
self.login(READ_ACCESS_USER)
|
||||
|
||||
# Queries: Base + the list query
|
||||
|
@ -346,7 +355,7 @@ class TestGetUserPrivateAllowed(ApiTestCase):
|
|||
assert json['privateCount'] == 0
|
||||
assert not json['privateAllowed']
|
||||
|
||||
def test_allowed(self):
|
||||
def test_allowedz(self):
|
||||
self.login(ADMIN_ACCESS_USER)
|
||||
|
||||
# Change the subscription of the namespace.
|
||||
|
@ -372,7 +381,7 @@ class TestConvertToOrganization(ApiTestCase):
|
|||
'plan': 'free'},
|
||||
expected_code=400)
|
||||
|
||||
self.assertEqual('The admin user is not valid', json['message'])
|
||||
self.assertEqual('The admin user is not valid', json['detail'])
|
||||
|
||||
def test_sameadminuser_by_email(self):
|
||||
self.login(READ_ACCESS_USER)
|
||||
|
@ -382,7 +391,7 @@ class TestConvertToOrganization(ApiTestCase):
|
|||
'plan': 'free'},
|
||||
expected_code=400)
|
||||
|
||||
self.assertEqual('The admin user is not valid', json['message'])
|
||||
self.assertEqual('The admin user is not valid', json['detail'])
|
||||
|
||||
def test_invalidadminuser(self):
|
||||
self.login(READ_ACCESS_USER)
|
||||
|
@ -393,7 +402,7 @@ class TestConvertToOrganization(ApiTestCase):
|
|||
expected_code=400)
|
||||
|
||||
self.assertEqual('The admin user credentials are not valid',
|
||||
json['message'])
|
||||
json['detail'])
|
||||
|
||||
def test_invalidadminpassword(self):
|
||||
self.login(READ_ACCESS_USER)
|
||||
|
@ -404,7 +413,7 @@ class TestConvertToOrganization(ApiTestCase):
|
|||
expected_code=400)
|
||||
|
||||
self.assertEqual('The admin user credentials are not valid',
|
||||
json['message'])
|
||||
json['detail'])
|
||||
|
||||
def test_convert(self):
|
||||
self.login(READ_ACCESS_USER)
|
||||
|
@ -489,7 +498,7 @@ class TestCreateNewUser(ApiTestCase):
|
|||
email='test@example.com'),
|
||||
expected_code=400)
|
||||
|
||||
self.assertEquals('The username already exists', json['message'])
|
||||
self.assertEquals('The username already exists', json['detail'])
|
||||
|
||||
def test_trycreatetooshort(self):
|
||||
json = self.postJsonResponse(User,
|
||||
|
@ -499,7 +508,7 @@ class TestCreateNewUser(ApiTestCase):
|
|||
expected_code=400)
|
||||
|
||||
self.assertEquals('Invalid username a: Username must be between 4 and 30 characters in length',
|
||||
json['error_description'])
|
||||
json['detail'])
|
||||
|
||||
def test_trycreateregexmismatch(self):
|
||||
json = self.postJsonResponse(User,
|
||||
|
@ -509,7 +518,7 @@ class TestCreateNewUser(ApiTestCase):
|
|||
expected_code=400)
|
||||
|
||||
self.assertEquals('Invalid username auserName: Username must match expression [a-z0-9_]+',
|
||||
json['error_description'])
|
||||
json['detail'])
|
||||
|
||||
def test_createuser(self):
|
||||
data = self.postJsonResponse(User, data=NEW_USER_DETAILS, expected_code=200)
|
||||
|
@ -740,7 +749,7 @@ class TestCreateOrganization(ApiTestCase):
|
|||
expected_code=400)
|
||||
|
||||
self.assertEquals('A user or organization with this name already exists',
|
||||
json['message'])
|
||||
json['detail'])
|
||||
|
||||
def test_existingorg(self):
|
||||
self.login(ADMIN_ACCESS_USER)
|
||||
|
@ -750,7 +759,7 @@ class TestCreateOrganization(ApiTestCase):
|
|||
expected_code=400)
|
||||
|
||||
self.assertEquals('A user or organization with this name already exists',
|
||||
json['message'])
|
||||
json['detail'])
|
||||
|
||||
def test_createorg(self):
|
||||
self.login(ADMIN_ACCESS_USER)
|
||||
|
@ -845,7 +854,7 @@ class TestCreateOrganizationPrototypes(ApiTestCase):
|
|||
delegate={'kind': 'team', 'name': 'owners'}),
|
||||
expected_code=400)
|
||||
|
||||
self.assertEquals('Unknown activating user', json['message'])
|
||||
self.assertEquals('Unknown activating user', json['detail'])
|
||||
|
||||
|
||||
def test_missingdelegate(self):
|
||||
|
@ -1330,7 +1339,7 @@ class TestCreateRepo(ApiTestCase):
|
|||
description=''),
|
||||
expected_code=400)
|
||||
|
||||
self.assertEquals('Invalid repository name', json['error_description'])
|
||||
self.assertEquals('Invalid repository name', json['detail'])
|
||||
|
||||
def test_duplicaterepo(self):
|
||||
self.login(ADMIN_ACCESS_USER)
|
||||
|
@ -1341,7 +1350,7 @@ class TestCreateRepo(ApiTestCase):
|
|||
description=''),
|
||||
expected_code=400)
|
||||
|
||||
self.assertEquals('Repository already exists', json['message'])
|
||||
self.assertEquals('Repository already exists', json['detail'])
|
||||
|
||||
|
||||
def test_createrepo(self):
|
||||
|
|
Reference in a new issue