Ejemplo n.º 1
0
    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")
Ejemplo n.º 2
0
    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")
Ejemplo n.º 3
0
    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")
Ejemplo n.º 4
0
    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")
Ejemplo n.º 5
0
    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")
Ejemplo n.º 6
0
    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")
Ejemplo n.º 7
0
    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")
Ejemplo n.º 8
0
    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")
Ejemplo n.º 9
0
    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")
Ejemplo n.º 10
0
    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")
Ejemplo n.º 11
0
    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")
Ejemplo n.º 12
0
    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")
Ejemplo n.º 13
0
    def testFileScannerJoinsConsumers(self):
        Uforia.fileScanner(self.testDir[0], self.consumers, None, None, None)

        self.consumers.join.assert_called_once_with()
Ejemplo n.º 14
0
    def testFileScannerJoinsConsumers(self):
        Uforia.fileScanner(self.testDir[0], self.consumers, None, None, None)

        self.consumers.join.assert_called_once_with()