def get_all_documents_from_db(): """ Returns: All document objects from the database """ conn = db_conn.get_database_connection() cur = conn.cursor() cur.execute("SELECT * FROM documents") doc_records = cur.fetchall() doc_list = [] for doc in doc_records: document = Document(doc[1], doc[2], doc[3]) document.set_doc_id(doc[0]) doc_list.append(document) cur.close() return doc_list
def get_document_from_db(doc_id): """ Args: doc_id: Document id to be retreived from the database Returns: Document object given the id """ conn = db_conn.get_database_connection() cur = conn.cursor() cur.execute("SELECT * FROM documents WHERE id=?", (doc_id, )) doc_query_object = cur.fetchall()[0] # Construct Document object with params: project, customer, file doc = Document(doc_query_object[1], doc_query_object[2], doc_query_object[3]) doc.set_doc_id(doc_query_object[0]) cur.close() return doc
def test_set_document_id(self): doc = Document("Test", "Customer", "testfile.PDF") doc.set_doc_id(1) self.assertEqual(doc.document_id, 1) doc.set_doc_id(2) self.assertEqual(doc.document_id, 2)