Exemple #1
0
    def setUp(self):
        """
    Load the scanner, which helps to set up the test environment.
    """
        # Move to the project directory.
        project_dir = os.path.join(os.path.dirname(__file__), os.pardir)
        os.chdir(project_dir)

        conf_file = os.path.join('conf', CONFIG_FILE)
        config = SafeConfigParser()
        config.read(conf_file)

        self.scanner = Scanner(config)
        self.scanner.log_dir = os.path.join(self.scanner.logroot_dir,
                                            'testlog')
        self.scanner.tmp_dir = 'testtmp'
        self.scanner.creative_db = 'sqlite:///%s/creative.db' % self.scanner.log_dir
        self.scanner.max_scan = 1

        # Turn on the debug mode to temporarily allow the private network.
        self.scanner.debug = True

        self.scanner.setup_environment()
        self.copy_resources(self.scanner.workspace.dirname)

        self.hostname = socket.gethostname()
Exemple #2
0
    def setUp(self):
        """
    Load the scanner, which helps to set up the test environment.
    """
        # Move to the project directory.
        project_dir = os.path.join(os.path.dirname(__file__), os.pardir)
        os.chdir(project_dir)

        conf_file = os.path.join('conf', CONFIG_FILE)
        config = SafeConfigParser()
        config.read(conf_file)

        self.scanner = Scanner(config)
        self.scanner.log_dir = os.path.join(self.scanner.logroot_dir,
                                            'testlog')
        self.scanner.tmp_dir = 'testtmp'
        self.scanner.creative_db = 'sqlite:///%s/creative.db' % self.scanner.log_dir
        self.scanner.setup_environment()
Exemple #3
0
def main():
    """
  The main method to launch the scanner.
  """
    # Move to the project directory.
    project_dir = os.path.join(os.path.dirname(__file__), os.pardir, os.pardir)
    os.chdir(project_dir)

    conf_file = os.path.join('conf', CONFIG_FILE)
    config = SafeConfigParser()
    config.read(conf_file)

    scanner = Scanner(config)
    scanner.setup_environment()

    if get_boolean(config, 'Steps', 'download_new_creative_ids'):
        scanner.download_new_creative_ids()

    if get_boolean(config, 'Steps', 'download_creatives'):
        scanner.download_creatives()

    if get_boolean(config, 'Steps', 'browse_creatives'):
        scanner.browse_creatives('https')

    if get_boolean(config, 'Steps', 'browse_creatives_over_http'):
        scanner.browse_creatives('http')

    if get_boolean(config, 'Steps', 'check_compliance'):
        scanner.check_compliance()

    if get_boolean(config, 'Steps', 'upload_creatives'):
        scanner.upload_creatives()

    if get_boolean(config, 'Steps', 'compress_log_file'):
        scanner.compress_log_file()

    if get_boolean(config, 'Steps', 'remove_temp_files'):
        scanner.remove_temp_files()

    sys.exit(0)
Exemple #4
0
    def test_setup_environment_and_remove_temp_files(self):
        """
    Test if the temporary files are deleted.
    """
        conf_file = os.path.join('conf', CONFIG_FILE)
        config = SafeConfigParser()
        config.read(conf_file)

        scanner = Scanner(config)
        scanner.log_dir = os.path.join(scanner.logroot_dir,
                                       'test_remove_temp_files')
        scanner.tmp_dir = 'test_remove_temp_files'
        scanner.creative_db = 'sqlite:///%s/creative.db' % scanner.log_dir

        scanner.setup_environment()
        assert os.path.exists(scanner.workspace.dirname)

        scanner.remove_temp_files()
        self.assertFalse(os.path.exists(scanner.workspace.dirname))

        adscan.fs.rmdirs(scanner.log_dir)
        adscan.fs.rmdirs(scanner.tmp_dir)
Exemple #5
0
    def test_compress_log_file(self):
        """
    Test if the log file is compressed.
    """
        conf_file = os.path.join('conf', CONFIG_FILE)
        config = SafeConfigParser()
        config.read(conf_file)

        scanner = Scanner(config)
        scanner.log_dir = os.path.join(scanner.logroot_dir,
                                       'test_compress_log_file')

        tarname = '%s.tgz' % scanner.log_dir

        scanner.setup_environment()
        assert os.path.exists(scanner.log_dir)
        if os.path.exists(tarname):
            os.remove(tarname)

        scanner.compress_log_file()
        assert os.path.exists(tarname)

        adscan.fs.rmdirs(scanner.log_dir)
        os.remove(tarname)