示例#1
0
    def test_delete_event_on_calendar_endpoint(self):
        """Tests whether event posted on calendar is saved into db"""
        camp_group = CampGroup('falcons', 'yellow')

        start = datetime.now()
        end = datetime.now()
        camp_event = CampEvent("basketball", start, end)
        camp_group.events.append(camp_event)
        db.session.add(camp_group)
        db.session.add(camp_event)
        db.session.commit()

        json_data = {
            'id':
            CampEvent.query.filter_by(title="basketball").first().id,
            'title':
            'basketball',
            'start':
            CampEvent.convert_py_datetime_to_iso_datetime(start),
            'end':
            CampEvent.convert_py_datetime_to_iso_datetime(end),
            'group_id':
            CampEvent.query.filter_by(title="basketball").first().group_id
        }

        response = self.app.delete("/saveEvent",
                                   data=json.dumps(json_data),
                                   content_type='application/json')
        self.assertTrue(response.status_code, 200)
示例#2
0
    def test_put_event_on_calendar_db(self):
        """Tests whether event posted on calendar is saved into db"""
        camp_group = CampGroup('falcons', 'yellow')

        start = datetime.now()
        end = datetime.now()
        camp_event = CampEvent("basketball", start, end)
        camp_group.events.append(camp_event)
        db.session.add(camp_group)
        db.session.add(camp_event)
        db.session.commit()

        new_title = 'soccer'
        json_data = {
            'id':
            CampEvent.query.filter_by(title="basketball").first().id,
            'title':
            new_title,
            'start':
            CampEvent.convert_py_datetime_to_iso_datetime(start),
            'end':
            CampEvent.convert_py_datetime_to_iso_datetime(end),
            'group_id':
            CampEvent.query.filter_by(title="basketball").first().group_id
        }

        self.app.put("/saveEvent",
                     data=json.dumps(json_data),
                     content_type='application/json')
        event = CampEvent.query.first()
        self.assertEqual(event.title, new_title)
示例#3
0
    def test_CampEvent_convert_calevent_to_campevent_args(self, mock_parser):
        full_cal_event = {
            'title': 'basketball',
            'start': '2017-10-10T12:00:05',
            'end': '2017-10-10T13:00:00',
            'group_id': '1'
        }

        CampEvent.convert_calevent_to_campevent(full_cal_event)
        mock_parser.assert_any_call(full_cal_event['start'])
        mock_parser.assert_any_call(full_cal_event['end'])
示例#4
0
def submit_handler():
    """EndPoint for creating, updating and deleting Calendar Events"""
    # a = request.get_json(force=True)

    if request.method == 'POST':
        event_data = request.json

        # save event to database
        event = CampEvent.convert_calevent_to_campevent(event_data)
        db.session.add(event)
        db.session.commit()

        # query database for group color and event id
        color = event.campgroup.color
        event_id = event.id

        return jsonify({'msg': 'success', 'color': color, 'id': event_id})

    elif request.method == 'PUT':
        print("Received a PUT request of event")
        event_data = request.json

        event_id = int(event_data['id'])
        new_title = event_data['title']
        new_start = CampEvent.convert_iso_datetime_to_py_datetime(
            event_data['start'])
        new_end = CampEvent.convert_iso_datetime_to_py_datetime(
            event_data['end'])
        new_group_id = int(event_data['group_id'])

        CampEvent.query.filter_by(id=event_id).update({
            'title': new_title,
            'start': new_start,
            'end': new_end,
            'group_id': new_group_id
        })
        db.session.commit()

        return jsonify({'msg': 'success'})

    elif request.method == 'DELETE':
        print('Received a Delete Request')
        event_data = request.json
        event_id = int(event_data['id'])

        event = CampEvent.query.filter_by(id=event_id).one()
        db.session.delete(event)
        db.session.commit()

        return jsonify({'msg': 'success'})
    def test_get_calendar_events_endpoint(self):
        event = CampEvent('Basketball', datetime.now(), datetime.now())
        group = CampGroup('falcons', 'green')
        group.events.append(event)
        db.session.add(group)
        db.session.add(event)
        db.session.commit()

        response = self.app.get('/getCampEvents?start=2013-12-01&end=2014-01-12')
        self.assertTrue(response.status_code, 200)
    def test_get_calendar_events_gets_data(self):
        event = CampEvent('Basketball', datetime.now(), datetime.now())
        group = CampGroup('falcons', 'green')
        group.events.append(event)
        db.session.add(group)
        db.session.add(event)
        db.session.commit()

        response = self.app.get('/getCampEvents?start=2014-12-01&end=2020-01-12')
        self.assertTrue(response.data is not None)
示例#7
0
    def test_campevent_save(self):
        title = "basketball"
        start = datetime.now()
        end = datetime.now()
        camp_event = CampEvent(title, start, end)
        db.session.add(camp_event)
        db.session.commit()

        queried_camp_event = CampEvent.query.filter_by(title=title).one()
        self.assertTrue(queried_camp_event is not None)
示例#8
0
    def test_CampEvent_convert_calevent_to_campevent(self):
        full_cal_event = {
            'title': 'basketball',
            'start': '2017-10-10T12:00:05',
            'end': '2017-10-10T13:00:00',
            'group_id': '1'
        }

        campevent = CampEvent.convert_calevent_to_campevent(full_cal_event)
        self.assertEqual(campevent.title, full_cal_event['title'])
        self.assertTrue(campevent.start is not None)
        self.assertTrue(campevent.end is not None)
        self.assertEqual(campevent.group_id, int(full_cal_event['group_id']))
示例#9
0
    def test_campevent_relationship(self):
        group_name = 'falcons'
        group_color = 'yellow'
        event_title = "basketball"
        event_start = datetime.now()
        event_end = datetime.now()

        camp_event = CampEvent(event_title, event_start, event_end)
        camp_group = CampGroup(group_name, group_color)
        camp_group.events.append(camp_event)
        db.session.add(camp_event)
        db.session.add(camp_group)
        db.session.commit()

        queried_camp_group = CampEvent.query.filter_by(title=event_title).one().campgroup
        self.assertEqual(queried_camp_group, camp_group)
示例#10
0
    def test_campevent_add_color(self):
        group_name = 'falcons'
        group_color = 'yellow'
        event_title = "basketball"
        event_start = datetime.now()
        event_end = datetime.now()

        camp_event = CampEvent(event_title, event_start, event_end)
        camp_group = CampGroup(group_name, group_color)
        db.session.add(camp_event)
        db.session.add(camp_group)
        db.session.commit()

        # no group yet, should fail
        camp_event.add_color_attr()
        self.assertTrue(camp_event.color is None)

        camp_group.events.append(camp_event)
        db.session.commit()

        camp_event.add_color_attr()
        self.assertTrue(hasattr(camp_event, 'color'))
示例#11
0
 def test_CampEvent_convert_ISO_py_datetime(self, mock_datetime):
     ISO_datetime = "2017-10-10T12:25:27"
     self.assertTrue(camperapp.models.datetime is mock_datetime)
     CampEvent.convert_iso_datetime_to_py_datetime(ISO_datetime)
     mock_datetime.strptime.assert_called_once_with(ISO_datetime, '%Y-%m-%dT%H:%M:%S')