Ejemplo n.º 1
0
def test_remove_user_from_observable_project(observable_projects_fixture):
    project = observable_projects_fixture.project

    ProjectsService.addUserToProject(project.id, "newUser")
    assert len(project.users) == 2
    ProjectsService.removeUserFromProject(project.id, "newUser")
    assert len(project.users) == 1
Ejemplo n.º 2
0
def test_remove_missing_user_failure(projects_fixture):
    ProjectsService.addUserToProject(projects_fixture.id, "newUser")
    assert len(projects_fixture.users) == 2
    with pytest.raises(ApiException):
        ProjectsService.removeUserFromProject(projects_fixture.id,
                                              "someOtherUser")
    assert len(projects_fixture.users) == 2
Ejemplo n.º 3
0
 def post(self, projectId: int):
     payload = request.json
     username = payload["username"]
     logger.info("Add user:{} to project:{} for user:{}".format(
         username,
         projectId,
         request.current_user.username))
     ProjectsService.addUserToProject(projectId, username)
     return "ok"
Ejemplo n.º 4
0
def test_remove_last_user_with_jwt_from_observable_project_failure(
        observable_projects_fixture):
    project = observable_projects_fixture.project

    ProjectsService.addUserToProject(project.id, "newUser")
    assert len(project.users) == 2
    with pytest.raises(ApiException):
        ProjectsService.removeUserFromProject(project.id,
                                              project.users[0].username)
    assert len(project.users) == 2
Ejemplo n.º 5
0
def test_add_new_user_to_project(userdata):
    user = UserService.getUser("test1", "test")
    data = {
        'project': {
            'name': 'new project',
            'description': 'test'
        },
    }
    proj = ProjectsService.create(data, user)
    ProjectsService.addUserToProject(proj.id, "newUser")
    proj = ProjectsService.get(project_id=proj.id)
    assert len(proj.users) == 2
Ejemplo n.º 6
0
def test_get_features_filter_type(projects_fixture, feature_fixture,
                                  image_feature_fixture):
    project_features = ProjectsService.getFeatures(projects_fixture.id)
    assert len(project_features['features']) == 2

    query = {'assetType': 'image'}
    project_features = ProjectsService.getFeatures(projects_fixture.id, query)
    assert len(project_features['features']) == 1

    query = {'assetType': 'video'}
    project_features = ProjectsService.getFeatures(projects_fixture.id, query)
    assert len(project_features['features']) == 0
Ejemplo n.º 7
0
def test_projects_for_user(userdata):
    user = UserService.getUser("test1", "test")
    data = {
        'project': {
            'name': 'new project',
            'description': 'test'
        },
    }
    ProjectsService.create(data, user)
    myProjects = ProjectsService.list(user)
    assert len(myProjects) == 1
    assert myProjects[0].name == 'new project'
Ejemplo n.º 8
0
 def delete(self, projectId: int, username: str):
     logger.info("Delete user:{} from project:{} for user:{}".format(
         username,
         projectId,
         request.current_user.username))
     return ProjectsService.removeUserFromProject(projectId,
                                                  username)
Ejemplo n.º 9
0
 def put(self, projectId: int):
     u = request.current_user
     logger.info("Update project:{} for user:{}".format(projectId,
                                                        u.username))
     return ProjectsService.update(user=u,
                                   projectId=projectId,
                                   data=api.payload)
Ejemplo n.º 10
0
def test_create_observable_project_already_exists(
        observable_projects_fixture, agave_utils_with_geojson_file_mock,
        import_from_agave_mock, get_system_users_mock):
    user = db_session.query(User).get(1)
    data = {
        'project': {
            'name': 'Renamed Project',
            'description': 'New Description',
            'system_id': observable_projects_fixture.system_id,
            'system_path': observable_projects_fixture.path,
            'system_file': 'file_name'
        },
        'observable': True,
        'watch_content': True
    }

    with pytest.raises(ObservableProjectAlreadyExists):
        ProjectsService.create(data, user)
Ejemplo n.º 11
0
def test_update_project(projects_fixture):
    user = db_session.query(User).get(1)
    data = {
        'project': {
            'name': 'new name',
            'description': 'new description',
        },
    }
    proj = ProjectsService.update(user, projects_fixture.id, data)
    assert proj.name == "new name"
    assert proj.description == "new description"
Ejemplo n.º 12
0
 def wrapper(*args, **kwargs):
     projectId = kwargs.get("projectId")
     proj = ProjectsService.get(projectId)
     if not proj:
         abort(404, "No project found")
     featureId = kwargs.get("featureId")
     feature = FeaturesService.get(featureId)
     if not feature:
         abort(404, "No feature found!")
     if feature.project_id != projectId:
         abort(404, "Feature not part of project")
     return fn(*args, **kwargs)
Ejemplo n.º 13
0
 def wrapper(*args, **kwargs):
     projectId = kwargs.get("projectId")
     proj = ProjectsService.get(projectId)
     if not proj:
         abort(404, "No project found")
     pointCloudId = kwargs.get("pointCloudId")
     point_cloud = PointCloudService.get(pointCloudId)
     if not point_cloud:
         abort(404, "No point cloud found!")
     if point_cloud.project_id != projectId:
         abort(404, "Point cloud not part of project")
     return fn(*args, **kwargs)
Ejemplo n.º 14
0
def test_create_project():
    user = db_session.query(User).get(1)
    data = {
        'project': {
            'name': "test name",
            'description': "test description",
        },
    }
    proj = ProjectsService.create(data, user)
    assert proj.id is not None
    assert len(proj.users) == 1
    assert proj.name == "test name"
    assert proj.description == "test description"
Ejemplo n.º 15
0
def check_access_and_get_project(current_user,
                                 allow_public_use=False,
                                 project_id=None,
                                 uuid=None):
    """
    Check if user (authenticated or anonymous) can access a project id and *aborts* if there is no access.
    :param project_id: int
    :param uid: str
    :param current_user: User
    :param allow_public_use: boolean
    :return: project: Project
    """
    proj = ProjectsService.get(
        project_id=project_id) if project_id else ProjectsService.get(
            uuid=uuid)
    if not proj:
        abort(404, "No project found")
    if not allow_public_use or not proj.public:
        access = False if is_anonymous(
            current_user) else UserService.canAccess(current_user, proj.id)
        if not access:
            abort(403, "Access denied")
    return proj
Ejemplo n.º 16
0
    def get(self):
        u = request.current_user
        query = self.parser.parse_args()
        uuid_subset = query.get("uuid")

        if uuid_subset:
            logger.info("Get a subset of projects for user:{} projects:{}".format(u.username, uuid_subset))
            # Check each project and abort if user (authenticated or anonymous) can't access the project
            subset = [check_access_and_get_project(request.current_user, uuid=uuid, allow_public_use=True) for uuid in uuid_subset]
            return subset
        else:
            if is_anonymous(u):
                abort(403, "Access denied")
            logger.info("Get all projects for user:{}".format(u.username))
            return ProjectsService.list(u)
Ejemplo n.º 17
0
def test_create_observable_project(userdata, get_system_users_mock,
                                   agave_utils_with_geojson_file_mock,
                                   import_from_agave_mock):
    user = db_session.query(User).get(1)
    data = {
        'project': {
            'name': 'Renamed Project',
            'description': 'New Description',
            'system_id': 'system',
            'system_path': '/path',
            'system_file': 'file_name'
        },
        'observable': True,
        'watch_content': True
    }

    proj = ProjectsService.create(data, user)
    assert len(proj.users) == 2
Ejemplo n.º 18
0
 def delete(self, projectId: int):
     u = request.current_user
     logger.info("Delete project:{} for user:{}".format(projectId,
                                                        u.username))
     return ProjectsService.delete(u, projectId)
Ejemplo n.º 19
0
def test_remove_user(projects_fixture):
    ProjectsService.addUserToProject(projects_fixture.id, "newUser")
    assert len(projects_fixture.users) == 2
    ProjectsService.removeUserFromProject(projects_fixture.id, "newUser")
    assert len(projects_fixture.users) == 1
Ejemplo n.º 20
0
def test_get_features(projects_fixture, feature_fixture):
    project_features = ProjectsService.getFeatures(projects_fixture.id)
    assert len(project_features['features']) == 1
Ejemplo n.º 21
0
def test_get_missing_argument(projects_fixture):
    with pytest.raises(ValueError):
        ProjectsService.get()
Ejemplo n.º 22
0
def test_get_with_uid(projects_fixture):
    project = ProjectsService.get(uuid=projects_fixture.uuid)
    assert project.uuid == projects_fixture.uuid
Ejemplo n.º 23
0
 def get(self, projectId: int):
     return ProjectsService.get(project_id=projectId)
Ejemplo n.º 24
0
 def get(self, projectId: int):
     logger.info("Get features of project:{} for user:{}".format(
         projectId, request.current_user.username))
     query = self.parser.parse_args()
     return ProjectsService.getFeatures(projectId, query)
Ejemplo n.º 25
0
def test_remove_user_with_only_one_user_failure(projects_fixture):
    with pytest.raises(ApiException):
        ProjectsService.removeUserFromProject(projects_fixture.id, "test1")
    assert len(projects_fixture.users) == 1
Ejemplo n.º 26
0
 def get(self, projectId: int):
     return ProjectsService.getUsers(projectId)
Ejemplo n.º 27
0
def test_get_with_project_id(projects_fixture):
    project = ProjectsService.get(project_id=projects_fixture.id)
    assert project.id == projects_fixture.id
Ejemplo n.º 28
0
 def post(self):
     u = request.current_user
     logger.info("Create project for user:{} : {}".format(u.username,
                                                          api.payload))
     return ProjectsService.create(api.payload, u)