Example #1
0
 def setUpClass(cls):
     host = os.environ['POSTGRES_HOST']
     port = os.environ['POSTGRES_PORT']
     password = os.environ['POSTGRES_PASSWORD']
     schema = os.environ['POSTGRES_SCHEMA']
     cls.db_string = f'postgresql://{schema}:{password}@{host}:{port}/{schema}'
     cls.engine = create_engine(
         cls.db_string).execution_options(isolation_level="AUTOCOMMIT")
     cls.Session = sessionmaker(bind=cls.engine)
     cls.user_id = "00000000-0000-0000-0000-000000000001"
     cls.email = '*****@*****.**'
     # register
     app.test_client().post("/register",
                            data={
                                'registration_code': 'code1',
                                'email': '*****@*****.**',
                                'password': '******'
                            })
     res = app.test_client().get("/get-auth-token",
                                 headers={
                                     "Authorization":
                                     _basic_auth_str(
                                         "*****@*****.**", "student1")
                                 })
     cls.token = json.loads(res.data.decode('ascii'))['token']
Example #2
0
 def test_get_courses(self):
     with app.test_client() as client:
         client.set_cookie('localhost', 'token', self.token)
         # client.set_cookie('localhost', 'user_id', self.user_id)
         result = client.get('/courses')
         self.assertEqual(result.data,
                          b'{"course_name_1":["description"]}\n')
Example #3
0
 def test_get_group(self):
     with app.test_client() as client:
         client.set_cookie('localhost', 'token', self.token)
         # client.set_cookie('localhost', 'user_id', self.user_id)
         result = client.get('/groups')
         self.assertEqual(
             result.data,
             b'{"00000000-0000-0000-0000-000000000001":["student1_first_name","student1_middle_name","student1_last_name"],"00000000-0000-0000-0000-000000000002":["student2_first_name","student2_middle_name","student2_last_name"]}\n'
         )
Example #4
0
 def test_get_solutions(self):
     with app.test_client() as client:
         client.set_cookie('localhost', 'token', self.token)
         # client.set_cookie('localhost', 'user_id', self.user_id)
         result = client.get(
             '/solutions/00000000-0000-0000-0004-000000000001')
         self.assertEqual(
             result.data,
             b'{"00000000-0000-0000-0006-000000000001":["00000000-0000-0000-0005-000000000001","00000000-0000-0000-0001-000000000001","00000000-0000-0000-0004-000000000001","description"]}\n'
         )
Example #5
0
 def test_get_profile(self):
     with app.test_client() as client:
         client.set_cookie('localhost', 'token', self.token)
         # client.set_cookie('localhost', 'user_id', self.user_id)
         result = client.get(
             '/profile/00000000-0000-0000-0000-000000000001')
         self.assertEqual(
             result.data,
             b'{"00000000-0000-0000-0000-000000000001":["student1_first_name","student1_middle_name","student1_last_name","*****@*****.**","+7-900-111-22-33","Moscow","","vk.com/exmaple","facebook.com/exmaple","instagram.com/exmaple","day"]}\n'
         )
Example #6
0
 def test_post_solution(self):
     with app.test_client() as client:
         client.set_cookie('localhost', 'token', self.token)
         # client.set_cookie('localhost', 'user_id', self.user_id)
         post_data = {
             'homework_id': '00000000-0000-0000-0005-000000000001',
             'student_id': '00000000-0000-0000-0001-000000000001',
             'course_id': '00000000-0000-0000-0004-000000000001',
             'description': 'very good solution'
         }
         result = client.post('/solution', data=post_data)
         self.assertEqual(result.data, b'OK')
Example #7
0
 def test_post_material(self):
     with app.test_client() as client:
         client.set_cookie('localhost', 'token', self.token)
         # client.set_cookie('localhost', 'user_id', self.user_id)
         post_data = {
             'material_name': 'material2_name',
             'material_content': 'material2_name',
             'add_date': 'material2_name',
             'course_id': '00000000-0000-0000-0004-000000000001',
         }
         result = client.post('/material', data=post_data)
         self.assertEqual(result.data, b'OK')
Example #8
0
 def test_post_homework(self):
     with app.test_client() as client:
         client.set_cookie('localhost', 'token', self.token)
         # client.set_cookie('localhost', 'user_id', self.user_id)
         post_data = {
             'homeworks_name': 'homework9',
             'homework_start_date': '19.12.2020',
             'homework_end_date': '26.12.2020',
             'description': 'very hard homework',
             'course_id': '00000000-0000-0000-0004-000000000001'
         }
         result = client.post('/homework', data=post_data)
         self.assertEqual(result.data, b'OK')
Example #9
0
 def test_post_profile(self):
     with app.test_client() as client:
         client.set_cookie('localhost', 'token', self.token)
         # client.set_cookie('localhost', 'user_id', self.user_id)
         post_data = {
             'email': '*****@*****.**',
             'phone_number': '+79001112233',
             'city': 'Moscow',
             'about': 'myself',
             'vk_link': 'https://vk.com/kek',
             'facebook_link': 'https://facebook.com/hh',
             'instagram_link': 'https://instagram.com/hh',
         }
         result = client.post(
             '/profile/00000000-0000-0000-0000-000000000001',
             data=post_data)
         self.assertEqual(result.data, b'OK')