Example #1
0
 def post_class(payload):
     try:
         data = request.get_json()
         name = data['class_name']
         address = data['address']
         inst = data['instructor']
         new_class = Classes(class_name=name,
                             address=address,
                             instructor=inst)
         new_class.insert()
     except Exception:
         abort(400)
     return jsonify({'success': True, 'classes': new_class.format()})
Example #2
0
 def test_get_timetable_class_id_and_accepted(self):
     """ Test for get Timetable with class id and accepted"""
     resp_register = self.register_user(self, '*****@*****.**',
                                        '123456')
     a_class = Classes(name="Default test class", )
     a_class.insert()
     some_class = Classes.query.filter(
         Classes.name == "Default test class").first()
     user = User.query.filter(User.email == '*****@*****.**').first()
     response1 = self.client().post('/login',
                                    json={
                                        "email": '*****@*****.**',
                                        "password": '******'
                                    },
                                    content_type='application/json')
     response3 = self.client().post(
         '/timetable',
         headers=dict(
             Authorization='Bearer' +
             json.loads(resp_register.data.decode())['auth_token']),
         json={
             "name": 'Mathematics Trigonometry',
             "time": '2020-06-17 15:00',
             "teacher_id": user.id,
             "class_id": some_class.id,
             "link": 'somezoomlink.com'
         },
         content_type='application/json')
     print(json.loads(response3.data.decode()))
     response4 = self.client().put(
         '/timetable/accept',
         headers=dict(
             Authorization='Bearer' +
             json.loads(resp_register.data.decode())['auth_token']),
         json={
             "teacher_id": user.id,
             "id": json.loads(response3.data.decode())['id'],
         },
     )
     response = self.client().get(
         '/timetable?class_id={}&accepted={}'.format(some_class.id, True),
         headers=dict(
             Authorization='Bearer' +
             json.loads(resp_register.data.decode())['auth_token']),
         content_type='application/json')
     data = json.loads(response.data.decode())
     self.assertTrue(data['status'] == 'success')
     self.assertTrue(len(data['data']) >= 1)
     self.assertEqual(response.status_code, 200)
Example #3
0
    def create_class(payload):
        name = request.get_json()['name']
        start_time = request.get_json()['start_time']
        teacher_id = request.get_json()['teacher_id']
        course_id = request.get_json()['course_id']
        try:
            claass = Classes(name=name,
                             start_time=start_time,
                             teacher_id=teacher_id,
                             course_id=course_id)
            claass.insert()

            return jsonify({"success": True, "Courses": claass.format()})
        except BaseException:
            abort(422)
Example #4
0
    def add_class():
        data = request.json
        education_id = data.get('education_id', None)
        sub_category_id = data.get('sub_category_id', None)

        if ((data.get('name', '') == '')):
            abort(422)
        try:
            classes = Classes(name=data.get('name'))
            classes.rank = data.get('rank')
            if education_id or sub_category_id:
                if education_id:
                    classes.education_id = int(data.get('education_id'))
                if sub_category_id:
                    classes.sub_category_id = int(data.get('sub_category_id'))
            else:
                abort(422)
        except Exception:
            abort(422)
        classes.insert()

        return jsonify({'message': 'success', 'id': classes.id})
Example #5
0
 def test_add_timetable(self):
     """ Test for Add Timetable"""
     resp_register = self.register_user(self, '*****@*****.**',
                                        '123456')
     a_class = Classes(name="Default test class", )
     a_class.insert()
     user = User.query.filter(User.email == '*****@*****.**').first()
     response = self.client().post(
         '/timetable',
         headers=dict(
             Authorization='Bearer' +
             json.loads(resp_register.data.decode())['auth_token']),
         json={
             "name": 'Mathematics Trigonometry',
             "time": '2020-06-17 15:00',
             "teacher_id": user.id,
             "class_id": a_class.id,
             "link": 'somezoomlink.com'
         },
         content_type='application/json')
     data = json.loads(response.data.decode())
     print(data)
     self.assertTrue(data['status'] == 'success')
     self.assertEqual(response.status_code, 200)