def testDbworkerClosesConnection(self): dbqueue = mock.Mock() dbqueue.get.side_effect = self.testdata Uforia.dbworker(dbqueue, self.db) self.assertTrue(self.db.connection.close.called, "database connection was not closed")
def testDbworkerStopsWithNoTasks(self): dbqueue = mock.Mock() dbqueue.get.return_value = self.sentinel Uforia.dbworker(dbqueue, self.db) self.assertTrue(dbqueue.task_done.called, "dbqueue task must be set as done")
def testDbWorkerDoesNotStoreWithNoTasks(self): dbqueue = mock.Mock() dbqueue.get.return_value = self.sentinel Uforia.dbworker(dbqueue, self.db) self.assertFalse(self.db.store.called, "db.store was called while sentinel value was sent")
def testFileScannerHashIdsAreUnique(self): Uforia.fileScanner(self.testDir[0], self.consumers, None, None, None) hashIds = [] for args, kwargs in self.consumers.apply_async.call_args_list: hashIds.append(kwargs['args'][0][1]) self.assertTrue(len(hashIds) == len(set(hashIds)), "hash id contain duplicate values")
def testFileScannerHandlesAllFiles(self): self.assertTrue(os.walk == self.MockOsWalk) Uforia.fileScanner(self.testDir[0], self.consumers, None, None, None) fullPaths = [] for args, kwargs in self.consumers.apply_async.call_args_list: fullPaths.append(kwargs['args'][0][0]) for i, fullPath in enumerate(fullPaths): self.assertTrue(fullPath.endswith(self.testDir[0][2][i]), "not all files have been processed")
def testDbworkerStoresDataCorrectly(self): dbqueue = mock.Mock() # side_effect allows us to return a different value each time # the method is called dbqueue.get.side_effect = self.testdata Uforia.dbworker(dbqueue, self.db) expected = [mock.call(*self.testdata[0]), mock.call(*self.testdata[1])] self.assertTrue(self.db.store.call_args_list == expected, "data was not written correctly or in the same order")
def testDbworkerStoresDataCorrectly(self): dbqueue = mock.Mock() # side_effect allows us to return a different value each time # the method is called dbqueue.get.side_effect = self.testdata Uforia.dbworker(dbqueue, self.db) expected = [ mock.call(*self.testdata[0]), mock.call(*self.testdata[1])] self.assertTrue(self.db.store.call_args_list == expected, "data was not written correctly or in the same order")
def testFileScannerJoinsConsumers(self): Uforia.fileScanner(self.testDir[0], self.consumers, None, None, None) self.consumers.join.assert_called_once_with()