示例#1
0
def test_del_user_api_case1(admin_login, username):
    client, app = admin_login
    with app.app_context():
        id = User.get_user_by_username(username).id
    rv = client.post("/api/user/delete", data={"id": id})
    d = rv.get_json()
    assert d['status'] == 200
    with app.app_context():
        user = User.get_user_by_username(username)
        assert user is None
示例#2
0
def test_update_user_noadmin_case2(user_login):
    client, app = user_login
    email = "*****@*****.**"
    with app.app_context():
        id = current_user.id
    rv = client.post("/api/user/update", data={"email": email, "id": id})
    d = rv.get_json()
    assert d['status'] == 200
    with app.app_context():
        assert current_user.email == "*****@*****.**"
        user = User.get_user_by_id(id)
        assert user.email == email
示例#3
0
def test_update_user_case1(admin_login, username, email):
    client, app = admin_login
    with app.app_context():
        id = current_user.id
    rv = client.post("/api/user/update",
                     data={
                         "username": username,
                         "email": email,
                         "id": id
                     })
    d = rv.get_json()
    print(rv.data.decode("utf8"))
    assert d['status'] != 200
    with app.app_context():
        user = User.get_user_by_id(id)
        assert user.username != username or user.email != email
示例#4
0
def test_block_search(app):
    with app.app_context():
        block = Block.create_block(1, "无可奉告", "2019-01-01 1:1:1",
                                   "2019-02-02 2:2:2")
        block = Block.get_block_list_by_user_id(1)
        assert isinstance(block, list)
        assert block[0].user_id == 1
示例#5
0
 def setUp(self):
     app = self.create_app()
     self.app = app.test_client()
     with app.app_context():
         self.init_db()
     self.req = ({'username': '******', 'password': '******'})
     self.bucketlist_url = '/api/v1/bucketlists/'
 def test_upload_dup_stats(self):
     """Test to use the POST method on the stat route with a valid file"""
     with app.app_context():
         file = FileStorage(
             stream=open(
                 './tests/Close Long Strafes Invincible - Challenge - 2019.10.21-12.31.26 Stats.csv',
                 "rb"),
             filename=
             './tests/Close Long Strafes Invincible - Challenge - 2019.10.21-12.31.26 Stats.csv',
             content_type='text/csv',
         )
         status, data = self.post(
             '{}/{}/{}'.format(USERS_URL, self.app.config.get('TEST_USER'),
                               'stats'), {'files': file})
         self.assertEqual(status, 204)
         file = FileStorage(
             stream=open(
                 './tests/Close Long Strafes Invincible - Challenge - 2019.10.21-12.31.26 Stats.csv',
                 "rb"),
             filename=
             './tests/Close Long Strafes Invincible - Challenge - 2019.10.21-12.31.26 Stats.csv',
             content_type='text/csv',
         )
         status, data = self.post(
             '{}/{}/{}'.format(USERS_URL, self.app.config.get('TEST_USER'),
                               'stats'), {'files': file})
         self.assertEqual(status, 400)
示例#7
0
 def test_add_user1(self,app):
     with app.app_context():
         user=User.create_user(username='******',password='******',salt='kxxh',email='test@test',activation='act',type=2,status=2)
         assert user is not None
         user=User.get_user_by_username('zjm')
         assert user is not None
         assert user.salt=="kxxh"
 def test_users_delete(self):
     """Test to delete a user"""
     with app.app_context():
         User.create('todelete', '*****@*****.**', 'password')
         db.session.commit()
     status, data = self.delete('{}/{}'.format(USERS_URL, 'todelete'))
     self.assertEqual(status, 204)
示例#9
0
def test_del_user_api_case2(admin_login):
    client, app = admin_login
    with app.app_context():
        id = current_user.id
    rv = client.post("/api/user/delete", data={"id": id})
    code = rv.status_code
    assert code == 401
示例#10
0
 def test_upload_stats_without_files(self):
     """Test to use the POST method on the stat route but without actually sending any files"""
     with app.app_context():
         status, data = self.post(
             '{}/{}/{}'.format(USERS_URL, self.app.config.get('TEST_USER'),
                               'stats'), {})
         self.assertEqual(status, 400)
示例#11
0
def test_block_add(app):
    with app.app_context():
        block = Block.create_block(1, "无可奉告", "2019-01-01 1:1:1",
                                   "2019-02-02 2:2:2")
        assert block is not None
        assert block.user_id == 1
        assert block.is_active == False
示例#12
0
 def setUp(self):
     app = self.create_app()
     self.app = app.test_client()
     with app.app_context():
         self.init_db()
     self.reg_url = '/api/v1/auth/register'
     self.login_url = '/api/v1/auth/login'
     self.bucketlist_url = '/api/v1/bucketlists'
示例#13
0
def test_update_user_admin_case2(admin_login, id, email):
    client, app = admin_login
    rv = client.post("/api/user/update", data={"email": email, "id": id})
    d = rv.get_json()
    assert d['status'] == 200
    with app.app_context():
        user = User.get_user_by_id(id)
        assert user.email == email
示例#14
0
def test_update_user_admin_case1(admin_login, id, username):
    client, app = admin_login
    rv = client.post("/api/user/update", data={"username": username, "id": id})
    d = rv.get_json()
    assert d['status'] == 200
    with app.app_context():
        user = User.get_user_by_id(id)
        assert user.username == username
示例#15
0
 def setUp(self):
     app = self.create_app()
     self.app = app.test_client()
     with app.app_context():
         self.init_db()
     self.user = ({'username': '******', 'password': '******'})
     self.bucketlist = ({'name': 'Before the end of the Year'})
     self.item_url = '/api/v1/bucketlists/1/items/'
示例#16
0
 def test_add_stu1(self, app):
     with app.app_context():
         Student.add_student(user_id='1',
                             school_number='1111',
                             real_name='五五开',
                             college='ART',
                             banji='1',
                             contact='110')
         stu = Student.get_student_id(1)
         assert stu is not None
示例#17
0
 def test_users_change_password_wrong_code(self):
     """Test to change the password of the test user  but provide a wrong code"""
     with app.app_context():
         status, data = self.post(
             '{}/{}/{}'.format(USERS_URL, self.app.config.get('TEST_USER'),
                               'recover'), {
                                   'recovery_code': 'non-existent',
                                   'new_password': '******'
                               })
         self.assertEqual(status, 403)
示例#18
0
 def test_user_delete1(self, app):
     with app.app_context():
         Student.add_student(user_id='2',
                             school_number='2312',
                             real_name='PDD',
                             college='CS',
                             banji='1',
                             contact='120')
         stu = Student.get_student_id(2)
         assert stu is not None
         stu.delete_student()
示例#19
0
 def test_upload_wrong_stats(self):
     """Test to use the POST method on the stat route with a valid file"""
     file = FileStorage(
         stream=open('./tests/wrong_file.csv', "rb"),
         filename='./tests/wrong_file.csv',
         content_type='text/csv',
     )
     with app.app_context():
         status, data = self.post(
             '{}/{}/{}'.format(USERS_URL, self.app.config.get('TEST_USER'),
                               'stats'), {'files': file})
         self.assertEqual(status, 400)
示例#20
0
def test_block_getter(app):
    with app.app_context():
        block = Block.create_block(1, "无可奉告", "2019-01-01 1:1:1",
                                   "2019-02-02 2:2:2")
        print(block)
        str(block)
        assert block.id
        assert block.reason
        assert block.start_time
        assert block.end_time
        assert block.user_id
        assert block.user.username == "test1"
示例#21
0
def test_add_user_api_case1(admin_login, username, password, email):
    client, app = admin_login
    rv = client.post("/api/user/add",
                     data={
                         "username": username,
                         "password": password,
                         "email": email
                     })
    d = rv.get_json()
    assert d['status'] == 200
    with app.app_context():
        user = User.get_user_by_username(username)
        assert user.check_password(password)
示例#22
0
 def test_get_stats(self):
     """Test to get all the stats for a user"""
     file = FileStorage(
         stream=open(
             './tests/Close Long Strafes Invincible - Challenge - 2019.10.21-12.31.26 Stats.csv',
             "rb"),
         filename=
         './tests/Close Long Strafes Invincible - Challenge - 2019.10.21-12.31.26 Stats.csv',
         content_type='text/csv',
     )
     with app.app_context():
         self.post(
             '{}/{}/{}'.format(USERS_URL, self.app.config.get('TEST_USER'),
                               'stats'), {'files': file})
         status, data = self.get('{}/{}/{}'.format(
             USERS_URL, self.app.config.get('TEST_USER'), 'stats'))
         self.assertEqual(status, 200)
         self.assertEqual(len(data), 2)
示例#23
0
 def test_users_full_password_change_with_code_renewing(self):
     """Test to change the password of the test user after the 1st code has expired"""
     with app.app_context():
         self.get('{}/{}/{}'.format(USERS_URL,
                                    self.app.config.get('TEST_USER'),
                                    'recover'))
         user = User.from_db(self.app.config.get('TEST_USER'))
         delta = datetime.timedelta(
             minutes=self.app.config.get('RECOVERY_CODE_DURATION'))
         user.recovery_code.expiration_date = user.recovery_code.expiration_date - delta
         db.session.commit()
         self.get('{}/{}/{}'.format(USERS_URL,
                                    self.app.config.get('TEST_USER'),
                                    'recover'))
         user = User.from_db(self.app.config.get('TEST_USER'))
         code = user.recovery_code.value
         status, data = self.post(
             '{}/{}/{}'.format(USERS_URL, self.app.config.get('TEST_USER'),
                               'recover'), {
                                   'recovery_code': code,
                                   'new_password': '******'
                               })
         self.assertEqual(status, 204)
示例#24
0
 def test_select1_id(self, app):
     with app.app_context():
         stu = Student.get_student_id(251)
         assert stu is None
示例#25
0
 def test_modify_contact(self, app):
     with app.app_context():
         stu = Student.get_student_id(2)
         stu.update_contact = '13890254777'
         stu = Student.get_student_id(2)
         assert stu.update_contact == '13890254777'
示例#26
0
 def test_modify_banji1(self, app):
     with app.app_context():
         stu = Student.get_student_id(1)
         stu.update_banji = 6
         stu = Student.get_student_id(1)
         assert stu.update_banji == '6'
示例#27
0
 def test_modify_college(self, app):
     with app.app_context():
         stu = Student.get_student_id(1)
         stu.update_college = 'AABB'
         stu = Student.get_student_id(1)
         assert stu.update_college == 'AABB'
示例#28
0
 def test_select3_real_name(self, app):
     with app.app_context():
         stu = Student.get_student_real_name('金咕咕')
         assert stu is None
示例#29
0
 def test_select2_real_name(self, app, value):
     with app.app_context():
         stu = Student.get_student_real_name(value)
         assert stu is not None
示例#30
0
 def test_user_delete1(self,app):
     with app.app_context():
         user=User.get_user_by_username("test2")
         assert user is not None
         user.delete_user()