def local_client(): if os.path.isdir(Config.STATIC_STORAGE_DIR): shutil.rmtree(Config.STATIC_STORAGE_DIR) app = create_app(TEST_MODE) with app.app_context(): db.reflect() db.drop_all() db.create_all() user = User(username=ADMIN_USERNAME, email='email@test_upload.com') user.set_password(ADMIN_PWD) db.session.add(user) db.session.commit() project = Project(project_name='test/test', created_by=user.id) db.session.add(project) db.session.commit() permission = ProjectPermission(access_type=AccessTypeEnum.READ_WRITE) user.project_permissions.append(permission) project.permissions.append(permission) user = User(username=ANNOTATOR_USERNAME, email='email2@test_upload.com') user.set_password(ANNOTATOR_PWD) db.session.add(user) db.session.commit() user = User( username=ANNOTATOR_USERNAME2, email='email1@test_upload.com') user.set_password(ANNOTATOR_PWD) db.session.add(user) db.session.commit() client = app.test_client() yield client
def local_client(): app = create_app(TEST_MODE) with app.app_context(): db.reflect() db.drop_all() db.create_all() user_1 = User(username='******', email='email_1@test_upload.com', privileges=PrivilegesEnum.ADMIN) user_1.set_password('TestTest1') user_2 = User(username='******', email='email_2@test_upload.com', privileges=PrivilegesEnum.ANNOTATOR) user_2.set_password('TestTest2') user_3 = User(username='******', email='*****@*****.**', privileges=PrivilegesEnum.ANNOTATOR) user_3.set_password('TestTest3') user_4 = User(username='******', email='*****@*****.**', privileges=PrivilegesEnum.ADMIN) user_4.set_password('TestTest4') db.session.add(user_1) db.session.add(user_2) db.session.add(user_3) db.session.add(user_4) db.session.commit() client = app.test_client() yield client
def local_client(): app = create_app(TEST_MODE) with app.app_context(): db.reflect() db.drop_all() db.create_all() admin = User(username='******', email='email@test_load.com', privileges=PrivilegesEnum.ADMIN) admin.set_password('TestTest1') db.session.add(admin) db.session.commit() annotator = User(username='******', email='email2@test_load.com', privileges=PrivilegesEnum.ANNOTATOR) annotator.set_password('TestTest2') db.session.add(annotator) db.session.commit() annotator_2 = User(username='******', email='email3@test_load.com') annotator_2.set_password('TestTest3') db.session.add(annotator_2) db.session.commit() client = app.test_client() yield client
def test_invalid_project(): app = create_app(TEST_MODE) with app.app_context(): db.reflect() db.drop_all() db.create_all() db.create_all() with open('tests/cat.jpg', 'rb') as fd: img = FileStorage(fd) image = Image(project_id=0) try: image.save_image_to_project(img) assert False except HTTPException as exception: assert 400 == exception.code
def local_client(): app = create_app(TEST_MODE) with app.app_context(): db.reflect() db.drop_all() db.create_all() user = User( username=ADMIN_USERNAME, email='email@test_upload.com', privileges=PrivilegesEnum.ADMIN) user.set_password(ADMIN_PWD) db.session.add(user) db.session.commit() project = Project(project_name='test/test1', created_by=user.id) db.session.add(project) db.session.commit() project = Project(project_name='test/test2', created_by=user.id) db.session.add(project) db.session.commit() # first annotator user = User(username=ANNOTATOR1_USERNAME, email=ANNOTATOR1_EMAIL) user.set_password(ANNOTATOR_PWD) db.session.add(user) db.session.commit() # second annotator user = User(username=ANNOTATOR2_USERNAME, email=ANNOTATOR2_EMAIL) user.set_password(ANNOTATOR_PWD) db.session.add(user) db.session.commit() client = app.test_client() yield client
def cleardb(mode): app = create_app(mode) with app.app_context(): db.reflect() db.drop_all()
def local_client(): if os.path.isdir(Config.STATIC_STORAGE_DIR): shutil.rmtree(Config.STATIC_STORAGE_DIR) app = create_app(TEST_MODE) with app.app_context(): db.reflect() db.drop_all() db.create_all() rw_permission = ProjectPermission( access_type=AccessTypeEnum.READ_WRITE) r_permission = ProjectPermission(access_type=AccessTypeEnum.READ_ONLY) admin = User(username='******', email='email@test_load.com', privileges=PrivilegesEnum.ADMIN) admin.set_password('TestTest1') admin.project_permissions.append(rw_permission) db.session.add(admin) db.session.commit() annotator = User(username='******', email='email2@test_load.com', privileges=PrivilegesEnum.ANNOTATOR) annotator.set_password('TestTest2') annotator.project_permissions.append(r_permission) db.session.add(annotator) db.session.commit() annotator_2 = User(username='******', email='email3@test_load.com') annotator_2.set_password('TestTest3') db.session.add(annotator_2) db.session.commit() project = Project(project_name='TestProject', created_by=admin.id) db.session.add(project) db.session.commit() project.permissions.append(rw_permission) project.permissions.append(r_permission) test_image = Image(image_name='cat.jpg', image_url='test_dir/test_dir_2/cat.jpg', project_id=project.id) db.session.add(test_image) db.session.commit() test_image_2 = Image(image_name='dog.png', image_url='test_dir/test_dir_2/dog.png', project_id=project.id) db.session.add(test_image_2) db.session.commit() test_image_3 = Image(image_name='cat.jpg', image_url='tests/cat.jpg', image_storage_path='tests/cat.jpg', project_id=project.id) db.session.add(test_image_3) db.session.commit() client = app.test_client() yield client
def get_project_fixture(): app = create_app(TEST_MODE) with app.app_context(): db.reflect() db.drop_all() db.create_all() user = User(username=ADMIN_USERNAME, email='success@test_project.com', privileges=PrivilegesEnum.ADMIN) user.set_password(ADMIN_PWD) db.session.add(user) db.session.commit() project = Project(project_name='test1', created_by=user.id) db.session.add(project) db.session.commit() image1 = Image(project_id=1, image_name='cracked_building.png') db.session.add(image1) db.session.commit() label1 = Label(label_name='asdf1', project_id=project.id) db.session.add(label1) label2 = Label(label_name='asdf2', project_id=project.id) db.session.add(label2) db.session.commit() annotation1 = Annotation(image_id=1, project_id=1, creator_id=1, label_id=1, data=b'1234', vector=b'1234') db.session.add(annotation1) annotation2 = Annotation(image_id=1, project_id=1, creator_id=1, label_id=2, data=b'1234', vector=b'1234') db.session.add(annotation2) db.session.commit() # Create project directory if not os.path.isdir('static-dir/1'): os.makedirs('static-dir/1') permission = ProjectPermission(access_type=AccessTypeEnum.READ_WRITE) user.project_permissions.append(permission) project.permissions.append(permission) user = User(username=ANNOTATOR_USERNAME, email='no_privilege@test_project.com', privileges=PrivilegesEnum.ANNOTATOR) user.set_password(ANNOTATOR_PWD) db.session.add(user) db.session.commit() permission = ProjectPermission(access_type=AccessTypeEnum.READ_ONLY) user.project_permissions.append(permission) project.permissions.append(permission) db.session.commit() client = app.test_client() yield client