Ejemplo n.º 1
0
    def test_project_fails(self) -> None:
        """Ensure projects fail to be created or loaded under failure conditions"""
        assert self.db is not None, "No db initialized"
        db: MephistoDB = self.db

        # Cant get non-existent entry
        with self.assertRaises(EntryDoesNotExistException):
            project = Project(db, self.get_fake_id("Project"))

        project_name = "test_project"
        project_id = db.new_project(project_name)

        # Can't create same project again
        with self.assertRaises(EntryAlreadyExistsException):
            project_id = db.new_project(project_name)

        # Can't use reserved name
        with self.assertRaises(MephistoDBException):
            project_id = db.new_project(NO_PROJECT_NAME)

        # Can't use no name
        with self.assertRaises(MephistoDBException):
            project_id = db.new_project("")

        # Ensure no projects were created
        projects = db.find_projects()
        self.assertEqual(len(projects), 1)
Ejemplo n.º 2
0
    def test_project(self) -> None:
        """Ensure projects can be created and queried as expected"""
        assert self.db is not None, "No db initialized"
        db: MephistoDB = self.db

        # Check creation and retrieval of a project
        project_name = "test_project"
        project_id = db.new_project(project_name)
        self.assertIsNotNone(project_id)
        self.assertTrue(isinstance(project_id, str))
        project_row = db.get_project(project_id)
        self.assertEqual(project_row["project_name"], project_name)
        project = Project(db, project_id)
        self.assertEqual(project.project_name, project_name)

        # Check finding for projects
        projects = db.find_projects()
        self.assertEqual(len(projects), 1)
        self.assertTrue(isinstance(projects[0], Project))
        self.assertEqual(projects[0].db_id, project_id)
        self.assertEqual(projects[0].project_name, project_name)

        # Check finding for specific projects
        projects = db.find_projects(project_name=project_name)
        self.assertEqual(len(projects), 1)
        self.assertTrue(isinstance(projects[0], Project))
        self.assertEqual(projects[0].db_id, project_id)
        self.assertEqual(projects[0].project_name, project_name)

        projects = db.find_projects(project_name="fake_name")
        self.assertEqual(len(projects), 0)
Ejemplo n.º 3
0
 def get_project(self) -> Optional[Project]:
     """
     Get the project for this task, if it exists
     """
     if self.project_id is not None:
         return Project(self.db, self.project_id)
     else:
         return None
Ejemplo n.º 4
0
 def find_projects(self, project_name: Optional[str] = None) -> List[Project]:
     """
     Try to find any project that matches the above. When called with no arguments,
     return all projects.
     """
     with self.table_access_condition:
         conn = self._get_connection()
         c = conn.cursor()
         c.execute(
             """
             SELECT * from projects
             WHERE (?1 IS NULL OR project_name = ?1)
             """,
             (project_name,),
         )
         rows = c.fetchall()
         return [Project(self, str(r["project_id"]), row=r) for r in rows]