Ejemplo n.º 1
0
    def test_accept_offer(self):
        student1 = Student(name='test', umail_address='test', facebook_id='test', fb_auth_token='test',
                           fb_profile_link='test', fb_picture_link='test')
        student2 = Student(name='test', umail_address='test', facebook_id='test', fb_auth_token='test',
                           fb_profile_link='test', fb_picture_link='test')
        lab1 = Lab(instructor='test', name='test', title='test', department='test',
                   location='test', days='test', time='test', max_spots='test', space='test')
        lab2 = Lab(instructor='test', name='test', title='test', department='test',
                   location='test', days='test', time='test', max_spots='test', space='test')

        db.session.add(student1)
        db.session.add(student2)
        db.session.add(lab1)
        db.session.add(lab2)
        db.session.commit()

        params = {}
        params['offerer_id'] = student1.id
        params['offeree_id'] = student2.id
        params['offer_type'] = 'lab'
        params['offerer_class_id'] = lab1.id
        params['offeree_class_id'] = lab2.id

        api.create_offer(**params)

        offer_id = student1.requested_offers[0].id

        api.accept_offer(student2.id, offer_id)

        self.assertEqual(student1.requested_offers[0].status, 'accepted')
Ejemplo n.º 2
0
def add_or_get_offers():
    wants_json = request_wants_json()
    params = json.loads(request.form['params'])
    try:
        if request.method == 'GET':
            offers = api.get_all_offers(json=wants_json)
            return jsonify({'offer': offers})
        elif request.method == 'POST':
            api.create_offer(**params)
            resp = jsonify(message='success!')
            resp.status_code = 201
            return resp
    except api.DbNotFoundError:
        abort(404)