def test_create_project_with_exists_title(self, session,
                                           create_project_team_test_data):
     test_title = "test_project_1"
     with pytest.raises(ProjectManagerException) as excinfo:
         ProjectManager(session).create(title=test_title)
     assert EXC_PROJECT_ALREADY_EXISTS.format(test_title) in str(
         excinfo.value)
 def test_detach_project_when_service_group_doesnt_exists(self, session):
     test_services_group_id = 4
     with pytest.raises(ProjectManagerException) as excinfo:
         ProjectManager(session).detach_from_services_group(
             services_group_id=test_services_group_id)
     assert EXC_SERVICES_GROUP_DOESNT_EXISTS.format(
         test_services_group_id) in str(excinfo.value)
 def test_update_project_when_it_doesnt_exists(self, session):
     test_new_title = "test_new_title"
     test_project_id = 1
     with pytest.raises(ProjectManagerException) as excinfo:
         ProjectManager(session).update(project_id=test_project_id,
                                        new_title=test_new_title)
     assert EXC_PROJECT_DOESNT_EXISTS.format(test_project_id) in str(
         excinfo.value)
 def test_detach_project(self, session, create_project_team_test_data):
     test_services_group_id = 4
     ProjectManager(session).detach_from_services_group(
         services_group_id=test_services_group_id)
     services_group_project_id = (session.query(
         ServicesGroup.project_id).filter_by(
             id=test_services_group_id).scalar())
     assert services_group_project_id is None
    def test_update_project(self, session, create_project_team_test_data):
        test_new_title = "test_new_title"
        test_project_id = 1

        ProjectManager(session).update(project_id=test_project_id,
                                       new_title=test_new_title)
        project_title = (session.query(
            Project.title).filter_by(id=test_project_id).scalar())
        assert project_title == test_new_title
 def test_attach_project_when_it_doesnt_exists(self, session):
     test_project_id = 1
     test_services_group_id = 2
     with pytest.raises(ProjectManagerException) as excinfo:
         ProjectManager(session).attach_to_services_group(
             project_id=test_project_id,
             services_group_id=test_services_group_id,
         )
     assert EXC_PROJECT_DOESNT_EXISTS.format(test_project_id) in str(
         excinfo.value)
 def test_attach_project(self, session, create_project_team_test_data):
     test_project_id = 1
     test_services_group_id = 2
     ProjectManager(session).attach_to_services_group(
         project_id=test_project_id,
         services_group_id=test_services_group_id)
     services_group_project_id = (session.query(
         ServicesGroup.project_id).filter_by(
             id=test_services_group_id).scalar())
     assert services_group_project_id == test_project_id
 def test_attach_project_when_services_group_doesnt_exists(
         self, session, create_project_team_test_data):
     test_project_id = 1
     test_services_group_id = 201
     with pytest.raises(ProjectManagerException) as excinfo:
         ProjectManager(session).attach_to_services_group(
             project_id=test_project_id,
             services_group_id=test_services_group_id,
         )
     assert EXC_SERVICES_GROUP_DOESNT_EXISTS.format(
         test_services_group_id) in str(excinfo.value)
Beispiel #9
0
    def dispatch_request(self):
        data_for_delete = json.loads(request.data)

        if "id" in data_for_delete:
            try:
                valid_data_for_delete = UpdateProjectTeamModel(
                    **data_for_delete)
            except ValidationError as e:
                return jsonify({"error": e.errors()}), 400
            try:
                ProjectManager(
                    db.session).delete(project_id=valid_data_for_delete.id)
            except ProjectManagerException as exc:
                return jsonify({"error": exc.error_text}), 400
            return jsonify({"success": True})
        return jsonify({"error": EXC_FIELD_IS_REQUIRED.format("id")}), 400
Beispiel #10
0
    def dispatch_request(self):
        data_for_create = json.loads(request.data)

        if "title" in data_for_create:
            try:
                valid_data_for_create = UpdateProjectTeamModel(
                    **data_for_create)
            except ValidationError as e:
                return jsonify({"error": e.errors()}), 400
            try:
                new_project = ProjectManager(
                    db.session).create(title=valid_data_for_create.title)
            except ProjectManagerException as exc:
                return jsonify({"error": exc.error_text}), 400
            return jsonify({
                "success": True,
                "id": new_project.id,
                "title": new_project.title,
            })
        return jsonify({"error": EXC_FIELD_IS_REQUIRED.format("title")}), 400
Beispiel #11
0
    def dispatch_request(self):
        data_for_detach = json.loads(request.data)

        for parameter in PARAMETERS_DETACH_PROJECT_TEAM:
            if parameter not in data_for_detach:
                return (
                    jsonify({"error":
                             EXC_FIELD_IS_REQUIRED.format(parameter)}),
                    400,
                )
        try:
            valid_data_for_detach = AttachDetachProjectTeamModel(
                **data_for_detach)
        except ValidationError as e:
            return jsonify({"error": e.errors()}), 400
        try:
            ProjectManager(db.session).detach_from_services_group(
                services_group_id=valid_data_for_detach.services_group_id)
        except ProjectManagerException as exc:
            return jsonify({"error": exc.error_text}), 400
        return jsonify({"success": True})
Beispiel #12
0
    def dispatch_request(self):
        data_for_update = json.loads(request.data)

        for parameter in PARAMETERS_PROJECT_TEAM:
            if parameter not in data_for_update:
                return (
                    jsonify({"error":
                             EXC_FIELD_IS_REQUIRED.format(parameter)}),
                    400,
                )
        try:
            valid_data_for_update = UpdateProjectTeamModel(**data_for_update)
        except ValidationError as e:
            return jsonify({"error": e.errors()}), 400
        try:
            ProjectManager(db.session).update(
                project_id=valid_data_for_update.id,
                new_title=valid_data_for_update.title,
            )
        except ProjectManagerException as exc:
            return jsonify({"error": exc.error_text}), 400
        return jsonify({"success": True})
 def test_delete_project(self, session, create_project_team_test_data):
     test_project_id = 1
     ProjectManager(session).delete(project_id=test_project_id)
     assert not session.query(
         exists().where(Project.id == test_project_id)).scalar()
 def test_create_project(self, session):
     test_title = "test_project_1"
     ProjectManager(session).create(title=test_title)
     assert session.query(
         exists().where(Project.title == test_title)).scalar()