Example #1
0
 def _check_exists_project(self, project_id: int) -> None:
     if not self.session.query(
         exists().where(Project.id == project_id)
     ).scalar():
         raise ProjectManagerException(
             EXC_PROJECT_DOESNT_EXISTS.format(project_id)
         )
 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_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_delete_project_when_it_doesnt_exists(self, client):
     test_data = {"id": 1}
     resp = client.delete(
         url_for("settings_project.project-delete"),
         data=json.dumps(test_data),
     )
     assert resp.status_code == 400
     assert resp.json == {
         "error": EXC_PROJECT_DOESNT_EXISTS.format(test_data.get("id"))
     }
Example #5
0
 def delete(self, project_id: int) -> None:
     """
     Deletes project instance.
     :param project_id: project id to delete
     """
     project = self.session.query(Project).filter_by(id=project_id).scalar()
     if not project:
         raise ProjectManagerException(
             EXC_PROJECT_DOESNT_EXISTS.format(project_id)
         )
     self.session.delete(project)
     self.session.commit()
    def test_update_project_when_it_doesnt_exists(self, client):
        test_title = "test_new_title"
        test_project_id = 101
        test_data = {"id": test_project_id, "title": test_title}
        resp = client.put(
            url_for("settings_project.project-update-title"),
            data=json.dumps(test_data),
        )

        assert resp.status_code == 400
        assert resp.json == {
            "error": EXC_PROJECT_DOESNT_EXISTS.format(test_project_id)
        }
Example #7
0
 def update(self, project_id: int, new_title: str) -> None:
     """
     Updates project instance title.
     :param project_id: project id to update
     :param new_title: new project title to update
     """
     project = self.session.query(Project).filter_by(id=project_id).scalar()
     if not project:
         raise ProjectManagerException(
             EXC_PROJECT_DOESNT_EXISTS.format(project_id)
         )
     project.title = new_title
     self.session.add(project)
     self.session.commit()
 def test_attach_project_when_it_doesnt_exists(
         self, client, create_services_group_test_data):
     test_project_id = 101
     test_services_group_id = 1
     test_data = {
         "project_id": test_project_id,
         "services_group_id": test_services_group_id,
     }
     resp = client.put(
         url_for("settings_project.project-attach"),
         data=json.dumps(test_data),
     )
     assert resp.status_code == 400
     assert resp.json == {
         "error": EXC_PROJECT_DOESNT_EXISTS.format(test_project_id)
     }