Ejemplo n.º 1
0
    def test_crud(self):
        with self.app_context():
            # Create event and assert that it is not in the database
            mock_event = EventTest.create_mock_event()
            self.assertIsNone(EventModel.find_by_id(mock_event.id))

            # Save event to database and assert that it is in the database
            mock_event.save_to_db()
            self.assertIsNotNone(EventModel.find_by_id(mock_event.id))

            # Update event details and save to database then assert that details have been updated
            mock_event.title = "Updated title"
            mock_event.description = "Updated description"
            mock_event.set_occurred_on("1755-01-11")
            mock_event.save_to_db()
            updated_mock_event = EventModel.find_by_id(mock_event.id)
            self.assertEqual("Updated title", updated_mock_event.title)
            self.assertEqual("Updated description",
                             updated_mock_event.description)
            self.assertEqual("Sat Jan 11 00:00:00 1755",
                             updated_mock_event.occurred_on.ctime())

            # Delete event from database and assert event is no longer in database
            updated_mock_event.delete_from_db()
            self.assertIsNone(EventModel.find_by_id(updated_mock_event.id))
Ejemplo n.º 2
0
    def get(self, id_all):

        event_data = Event.find_by_id(id_all) or Event.find_by_author(id_all)

        if event_data:
            return event_data.json()
        else:
            return {'message': 'Event not found'}, 404
Ejemplo n.º 3
0
 def mutate_and_get_payload(cls, root, info, **event_input):
     status = None
     event = EventModel.find_by_id(event_input.get('id'))
     if event is not None:
         event.delete_from_db()
         status = "ok"
     else:
         status = "event with ID {} not found.".format(event_input.get('id'))
     return DeleteEvent(status=status)
Ejemplo n.º 4
0
 def mutate_and_get_payload(cls, root, info, **event_input):
     status = None
     event = EventModel.find_by_id(event_input.get('id'))
     if event is not None:
         event.title = event_input.get('title')
         event.description = event_input.get('description')
         event.set_occurred_on(event_input.get('occurred_on'))
         event.save_to_db()
         status = "ok"
     else:
         status = "event with ID {} not found.".format(event_input.get('id'))
     return UpdateEvent(event=event, status=status)
Ejemplo n.º 5
0
    def delete(self, id_all):

        event_data = Event.find_by_id(id_all)

        if event_data:
            try:
                event_data.delete_to_db()
            except:
                return {"message": "An error occurred update the event."}, 500

            return {'message': 'Event succes delete'}, 200
        else:
            return {'message': 'Event succes delete'}, 404
Ejemplo n.º 6
0
    def put(self, id_all):

        data = Events.parse.parse_args()
        event_data = Event.find_by_id(id_all)

        if event_data:
            event_data.title = data['title']
            event_data.content = data['content']

            try:
                event_data.save_to_db()
            except:
                return {"message": "An error occurred update the event."}, 500

            return {'message': 'event succes update'}, 200
        else:
            return {'message': 'event not found'}, 404