Some fixes for code review.
This commit is contained in:
parent
f15b3d5b84
commit
14eb3005b6
4 changed files with 26 additions and 27 deletions
|
@ -2,10 +2,7 @@ from data.database import Messages
|
||||||
|
|
||||||
|
|
||||||
def get_messages():
|
def get_messages():
|
||||||
messages = []
|
return Messages.select()
|
||||||
for message in Messages.select():
|
|
||||||
messages.append({'id': message.id, 'content': message.content})
|
|
||||||
return messages
|
|
||||||
|
|
||||||
def create(messages):
|
def create(messages):
|
||||||
for message in messages:
|
for message in messages:
|
||||||
|
|
|
@ -820,9 +820,10 @@ class SuperUserServiceKeyApproval(ApiResource):
|
||||||
|
|
||||||
abort(403)
|
abort(403)
|
||||||
|
|
||||||
|
|
||||||
@resource('/v1/messages')
|
@resource('/v1/messages')
|
||||||
@show_if(features.SUPER_USERS)
|
@show_if(features.SUPER_USERS)
|
||||||
class Messages(ApiResource):
|
class SuperUserMessages(ApiResource):
|
||||||
""" Resource for getting a list of super user messages """
|
""" Resource for getting a list of super user messages """
|
||||||
|
|
||||||
schemas = {
|
schemas = {
|
||||||
|
@ -831,21 +832,17 @@ class Messages(ApiResource):
|
||||||
'type': 'object',
|
'type': 'object',
|
||||||
'description': 'Messages that a super user has saved in the past',
|
'description': 'Messages that a super user has saved in the past',
|
||||||
'properties': {
|
'properties': {
|
||||||
'messages': {
|
'message': {
|
||||||
'type': 'array',
|
'type': 'object',
|
||||||
'description': 'Array of message',
|
'description': 'A single message',
|
||||||
'items': {
|
'properties': {
|
||||||
'type': 'object',
|
'id': {
|
||||||
'description': 'A single message',
|
'type': 'integer',
|
||||||
'properties': {
|
'description': 'The message id',
|
||||||
'id':{
|
},
|
||||||
'type': 'integer',
|
'content': {
|
||||||
'description': 'The message id',
|
'type': 'string',
|
||||||
},
|
'description': 'The actual message',
|
||||||
'content': {
|
|
||||||
'type': 'string',
|
|
||||||
'description': 'The actual message',
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -856,9 +853,9 @@ class Messages(ApiResource):
|
||||||
@nickname('getMessages')
|
@nickname('getMessages')
|
||||||
def get(self):
|
def get(self):
|
||||||
""" Return a super users messages """
|
""" Return a super users messages """
|
||||||
messages = model.message.get_messages()
|
messages = list(model.message.get_messages())
|
||||||
return {
|
return {
|
||||||
'messages': messages,
|
'messages': [message_view(m) for m in messages],
|
||||||
}
|
}
|
||||||
|
|
||||||
@require_scope(scopes.SUPERUSER)
|
@require_scope(scopes.SUPERUSER)
|
||||||
|
@ -867,4 +864,7 @@ class Messages(ApiResource):
|
||||||
def post(self):
|
def post(self):
|
||||||
""" Create a message """
|
""" Create a message """
|
||||||
body = request.get_json()
|
body = request.get_json()
|
||||||
model.message.create(body['messages'])
|
model.message.create([body['message']])
|
||||||
|
|
||||||
|
def message_view(message):
|
||||||
|
return {'id': message.id, 'content': message.content}
|
||||||
|
|
|
@ -776,7 +776,7 @@ def populate_database(minimal=False, with_storage=False):
|
||||||
'trigger_id': trigger.uuid, 'config': json.loads(trigger.config),
|
'trigger_id': trigger.uuid, 'config': json.loads(trigger.config),
|
||||||
'service': trigger.service.name})
|
'service': trigger.service.name})
|
||||||
|
|
||||||
model.message.create([{'content': 'We love you Quay customers!'}])
|
model.message.create([{'content': 'We love you, Quay customers!'}])
|
||||||
|
|
||||||
fake_queue = WorkQueue('fakequeue', tf)
|
fake_queue = WorkQueue('fakequeue', tf)
|
||||||
fake_queue.put(['canonical', 'job', 'name'], '{}')
|
fake_queue.put(['canonical', 'job', 'name'], '{}')
|
||||||
|
|
|
@ -66,7 +66,7 @@ from endpoints.api.permission import (RepositoryUserPermission, RepositoryTeamPe
|
||||||
from endpoints.api.superuser import (SuperUserLogs, SuperUserList, SuperUserManagement,
|
from endpoints.api.superuser import (SuperUserLogs, SuperUserList, SuperUserManagement,
|
||||||
SuperUserServiceKeyManagement, SuperUserServiceKey,
|
SuperUserServiceKeyManagement, SuperUserServiceKey,
|
||||||
SuperUserServiceKeyApproval, SuperUserTakeOwnership,
|
SuperUserServiceKeyApproval, SuperUserTakeOwnership,
|
||||||
Messages)
|
SuperUserMessages)
|
||||||
from endpoints.api.secscan import RepositoryImageSecurity
|
from endpoints.api.secscan import RepositoryImageSecurity
|
||||||
from endpoints.api.suconfig import (SuperUserRegistryStatus, SuperUserConfig, SuperUserConfigFile,
|
from endpoints.api.suconfig import (SuperUserRegistryStatus, SuperUserConfig, SuperUserConfigFile,
|
||||||
SuperUserCreateInitialSuperUser)
|
SuperUserCreateInitialSuperUser)
|
||||||
|
@ -4283,11 +4283,13 @@ class TestSuperUserManagement(ApiTestCase):
|
||||||
self.login(ADMIN_ACCESS_USER)
|
self.login(ADMIN_ACCESS_USER)
|
||||||
|
|
||||||
# Create a message
|
# Create a message
|
||||||
self.postJsonResponse(Messages, data=dict(messages=[{"content": "new message"}]))
|
self.postJsonResponse(SuperUserMessages, data=dict(message={"content": "new message"}))
|
||||||
|
|
||||||
json = self.getJsonResponse(Messages)
|
json = self.getJsonResponse(SuperUserMessages)
|
||||||
|
|
||||||
self.assertEquals(len(json['messages']), 2)
|
self.assertEquals(len(json['messages']), 2)
|
||||||
|
self.assertEquals(json['messages'][1]["content"], "new message")
|
||||||
|
self.assertEquals(json['messages'][1]["id"], 2)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
Reference in a new issue