class BluecoatTest(unittest.TestCase):
    def setUp(self):
        self.temp_directory = tempfile.mkdtemp()
        config_path = os.path.join(test_dir, "data", "daemon.conf")

        mydir = os.path.dirname(os.path.abspath(__file__))
        binaries_dir = os.path.join(mydir, 'data', 'binary_data')
        self.mock_server = get_mocked_server(binaries_dir)
        self.mock_server_thread = threading.Thread(target=self.mock_server.run, args=['127.0.0.1', 7982])
        self.mock_server_thread.daemon = True
        self.mock_server_thread.start()
        sleep_till_available(('127.0.0.1', 7982))

        self.daemon = BluecoatConnector('bluecoat-test',
                                    configfile=config_path, work_directory=self.temp_directory,
                                    logfile=os.path.join(self.temp_directory, 'test.log'), debug=True)
        self.daemon.validate_config()

        self.daemon.initialize_queue()

    def test_bluecoat(self):
        CbAPIProducerThread(self.daemon.work_queue, self.daemon.cb, self.daemon.name, rate_limiter=0,
                            stop_when_done=True).run()

        dirty_flag = threading.Event()
        t = DeepAnalysisThread(self.daemon.work_queue, self.daemon.cb, self.daemon.get_provider(),
                               dirty_event=dirty_flag)
        t.start()

        unanalyzed = self.daemon.work_queue.number_unanalyzed()
        while unanalyzed:
            print unanalyzed
            sleep(.1)
            unanalyzed = self.daemon.work_queue.number_unanalyzed()

        t.stop()
        t.join()
    def setUp(self):
        self.temp_directory = tempfile.mkdtemp()
        config_path = os.path.join(test_dir, "data", "daemon.conf")

        mydir = os.path.dirname(os.path.abspath(__file__))
        binaries_dir = os.path.join(mydir, 'data', 'binary_data')
        self.mock_server = get_mocked_server(binaries_dir)
        self.mock_server_thread = threading.Thread(target=self.mock_server.run, args=['127.0.0.1', 7982])
        self.mock_server_thread.daemon = True
        self.mock_server_thread.start()
        sleep_till_available(('127.0.0.1', 7982))

        self.daemon = BluecoatConnector('bluecoat-test',
                                    configfile=config_path, work_directory=self.temp_directory,
                                    logfile=os.path.join(self.temp_directory, 'test.log'), debug=True)
        self.daemon.validate_config()

        self.daemon.initialize_queue()