class CreateDatabaseTest(unittest.TestCase): def setUp(self): print 'setUp' self.createDatabase = CreateDatabase() # self.createDatabase.creatingDatabase() def tearDown(self): print 'tearDown' @unittest.skip("demonstrating skipping") def testFindBook(self): print 'testFindBook' createDatabase = CreateDatabase() book = Book() book.name = 'java' # book.isbn='java' dbBookObj = Book() dbBookObj.bookName = book.name dbBookObj.isbn_13 = book.isbn books = createDatabase.findBook(dbBookObj) for book in books: print book pass @unittest.skip("demonstrating skipping") def testAddingData(self): print 'testAddingData' self.createDatabase.creatingDatabase() self.createDatabase.addingData() def testRemoveBook(self): print 'testRemoveBook' book = Book() book.id = 1 isSuccessfulDelete = self.createDatabase.removeBook(book) print isSuccessfulDelete
class FindingBook(): ''' This class searches book detail in Opal database.this database would be created in workspace(Opal library). ''' def __init__(self, libraryPath=None): self.libraryPath = libraryPath self.createDatabase = CreateDatabase(libraryPath=libraryPath) pass def searchingBook(self, searchText=None, exactSearchFlag=False, pageSize=10, offset=0): ''' This method return list of books matching with search text. @param searchText: may be a book name ''' books = list() if searchText != None and searchText != '': os.chdir(self.libraryPath) if exactSearchFlag: books, count = self.createDatabase.findByBookName(searchText) else: books, count = self.createDatabase.findBySimlarBookName(bookName=searchText, limit=pageSize, offset=0) else: books, count = self.findAllBooks() return books, count def countAllBooks(self): bookCount = self.createDatabase.countAllBooks() return bookCount def findBookByNextMaxId(self, bookId=None): return self.createDatabase.findBookByNextMaxId(bookId) def findBookByPreviousMaxId(self, bookId=None): return self.createDatabase.findBookByPreviousMaxId(bookId) def findAllBooks(self, pageSize=None, offset=0): ''' This method will give all the books list in book library. ''' books = list() os.chdir(self.libraryPath) books, count = self.createDatabase.findAllBook(pageSize=pageSize, offset=offset) return books, count def findBookByIsbn(self, isbn_13): bs = self.createDatabase.findBookByIsbn(isbn_13) return bs def getMaxBookId(self): os.chdir(self.libraryPath) def deleteBook(self, book): ''' removing book from database and files. @param book: book object ''' bookPath = book.bookPath isSuccessfulDatabaseDelete = self.createDatabase.removeBook(book) if isSuccessfulDatabaseDelete: BookTerminal().removeBook(bookPath=bookPath) def findFolderWithoutBook(self): ''' this method will find all the folder without book. ''' directory_name = self.libraryPath os.chdir(directory_name) listOfDir = [ name for name in os.listdir(directory_name) if os.path.isdir(os.path.join(directory_name, name)) ] if listOfDir: listOfDir.sort(key=int) defaulterList = list() for dir in listOfDir: lst = list() levelOne = os.path.join(directory_name, dir) for sName in os.listdir(levelOne): if os.path.isfile(os.path.join(levelOne, sName)): lst.append(sName.split('.')[-1:][0]) # if 'pdf' not in lst: # defaulterList.append(levelOne) if len(lst) < 3: defaulterList.append(levelOne)