Exemplo n.º 1
0
class TestMessageRepository(DbTest):
    def setUp(self):
        self.repository = MessageRepository()

    def test_create_message(self):
        message = self.repository.create_message(
            Message(
                sender="Jeremy",
                recipient="Jeremy",
                content="Hello World",
                state=MessageState.PENDING
            )
        )
        self.assertEqual(message.sender, 'Jeremy')

    def test_retrieve_message(self):
        message = self.repository.create_message(
            Message(
                sender="Jeremy",
                recipient="Jeremy",
                content="Hello World",
                state=MessageState.PENDING
            )
        )
        self.assertEqual(message.sender, 'Jeremy')
        messages = self.repository.retrieve_messages()
        self.assertGreater(len(messages), 1)
Exemplo n.º 2
0
def retrieve():
    identifier = g.get('identifier', None)
    message_repository = MessageRepository()
    results = message_repository.retrieve_messages_by_sender(identifier)
    result = Response(ResponseWrapper.wrap(identifier, 'messages.retrieve',
                                           results),
                      status=200,
                      mimetype='application/json')
    return result
Exemplo n.º 3
0
def update():
    identifier = g.get('identifier', None)
    message_parameters = request.get_json()
    message_repository = MessageRepository()
    message = message_repository.update_message(
        message_parameters['identifier'],
        message_parameters['recipient_received'], MessageState.RECEIVED)
    result = Response(ResponseWrapper.wrap(identifier, 'messages.update',
                                           message),
                      status=200,
                      mimetype='application/json')
    return result
Exemplo n.º 4
0
def index():
    message_repository = MessageRepository()
    message_repository.create_message(
        Message(sender="Jeremy",
                recipient="Jeremy",
                content="Hello World",
                state=MessageState.PENDING))
    messages = message_repository.retrieve_messages()
    outputs = [shortcuts.model_to_dict(message) for message in messages]
    return Response(json.dumps(outputs, cls=DateTimeEncoder),
                    status=200,
                    mimetype='application/json')
Exemplo n.º 5
0
def create():
    identifier = g.get('identifier', None)
    message_parameters = request.get_json()
    message_repository = MessageRepository()
    message = message_repository.create_message(
        Message(identifier=RandomUtility.random_string(32),
                sender=identifier,
                recipient=message_parameters['recipient'],
                content=message_parameters['content'],
                state=MessageState.PENDING,
                created=TimestampUtility.parse(message_parameters['created']),
                received=TimestampUtility.now(),
                recipient_received=None))
    result = Response(ResponseWrapper.wrap(identifier, 'messages.create',
                                           message),
                      status=200,
                      mimetype='application/json')
    return result
 def setUp(self):
     self.repository = MessageRepository()