Some fixes for code review.

This commit is contained in:
charltonaustin 2016-10-10 12:55:00 -04:00
parent f15b3d5b84
commit 14eb3005b6
4 changed files with 26 additions and 27 deletions

View file

@ -2,10 +2,7 @@ from data.database import Messages
def get_messages():
messages = []
for message in Messages.select():
messages.append({'id': message.id, 'content': message.content})
return messages
return Messages.select()
def create(messages):
for message in messages:

View file

@ -820,9 +820,10 @@ class SuperUserServiceKeyApproval(ApiResource):
abort(403)
@resource('/v1/messages')
@show_if(features.SUPER_USERS)
class Messages(ApiResource):
class SuperUserMessages(ApiResource):
""" Resource for getting a list of super user messages """
schemas = {
@ -831,10 +832,7 @@ class Messages(ApiResource):
'type': 'object',
'description': 'Messages that a super user has saved in the past',
'properties': {
'messages': {
'type': 'array',
'description': 'Array of message',
'items': {
'message': {
'type': 'object',
'description': 'A single message',
'properties': {
@ -846,7 +844,6 @@ class Messages(ApiResource):
'type': 'string',
'description': 'The actual message',
},
},
}
},
},
@ -856,9 +853,9 @@ class Messages(ApiResource):
@nickname('getMessages')
def get(self):
""" Return a super users messages """
messages = model.message.get_messages()
messages = list(model.message.get_messages())
return {
'messages': messages,
'messages': [message_view(m) for m in messages],
}
@require_scope(scopes.SUPERUSER)
@ -867,4 +864,7 @@ class Messages(ApiResource):
def post(self):
""" Create a message """
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}

View file

@ -776,7 +776,7 @@ def populate_database(minimal=False, with_storage=False):
'trigger_id': trigger.uuid, 'config': json.loads(trigger.config),
'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.put(['canonical', 'job', 'name'], '{}')

View file

@ -66,7 +66,7 @@ from endpoints.api.permission import (RepositoryUserPermission, RepositoryTeamPe
from endpoints.api.superuser import (SuperUserLogs, SuperUserList, SuperUserManagement,
SuperUserServiceKeyManagement, SuperUserServiceKey,
SuperUserServiceKeyApproval, SuperUserTakeOwnership,
Messages)
SuperUserMessages)
from endpoints.api.secscan import RepositoryImageSecurity
from endpoints.api.suconfig import (SuperUserRegistryStatus, SuperUserConfig, SuperUserConfigFile,
SuperUserCreateInitialSuperUser)
@ -4283,11 +4283,13 @@ class TestSuperUserManagement(ApiTestCase):
self.login(ADMIN_ACCESS_USER)
# 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(json['messages'][1]["content"], "new message")
self.assertEquals(json['messages'][1]["id"], 2)
if __name__ == '__main__':
unittest.main()