Exemple #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)
Exemple #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)
    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)
Exemple #5
0
    def test_campgroup_save(self):
        name = 'falcons'
        color = 'yellow'

        camp_group = CampGroup(name, color)
        db.session.add(camp_group)
        db.session.commit()

        queried_camp_group = CampGroup.query.filter_by(name=name).one()
        self.assertTrue(queried_camp_group is not None)
Exemple #6
0
def submit_camper_group_management():
    """EndPoint for Adding, Editing and Deleting a Camper"""
    # a = request.get_json(force=True)
    form = request.form
    name = form["groupName"]
    color = form["color"]

    group = CampGroup(name=name, color=color)
    db.session.add(group)
    db.session.commit()

    return redirect(url_for('campers'))
    def test_post_event_on_calendar_db(self):
        """Tests whether event posted on calendar is saved into db"""
        camp_group = CampGroup('falcons', 'yellow')
        db.session.add(camp_group)
        db.session.commit()

        json_data = {
            'title': 'Test Event',
            'start': '2017-8-8T12:00:00',
            'end': '2017-8-8T12:00:00',
            'group_id': '1'
        }

        self.app.post("/saveEvent", data=json.dumps(json_data), content_type='application/json')
        events = CampEvent.query.all()
        self.assertEqual(len(events), 1)
Exemple #8
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)
Exemple #9
0
    def test_campgroup_relationship(self):
        group_name = 'falcons'
        group_color = 'yellow'
        camper_name = 'daniel'
        camper_age = 12

        camp_group = CampGroup(group_name, group_color)
        camper = Camper(camper_name, camper_age)
        camp_group.campers.append(camper)
        db.session.add(camp_group)
        db.session.add(camper)
        db.session.commit()

        queried_camp_group = Camper.query.filter_by(name=camper_name).one()\
            .campgroup
        self.assertEqual(queried_camp_group, camp_group)
Exemple #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'))