Пример #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)
Пример #2
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')