Esempio n. 1
0
 def setUp(self):
     self.tempdir = mkdtemp()
     self.bhs = BloodhoundSetup({})
     self.basedata =  {'section': {'option1': 'option1value',
                           'option2': 'option2value',},}
Esempio n. 2
0
 def setUp(self):
     self.tempdir = mkdtemp()
     self.bhs = BloodhoundSetup({})
     self.basedata =  {'section': {'option1': 'option1value',
                           'option2': 'option2value',},}
Esempio n. 3
0
class BloodhoundSetupTest(unittest.TestCase):
    def setUp(self):
        self.tempdir = mkdtemp()
        self.bhs = BloodhoundSetup({})
        self.basedata =  {'section': {'option1': 'option1value',
                              'option2': 'option2value',},}

    def tearDown(self):
        shutil.rmtree(self.tempdir)

    def test_db_str_no_options(self):
        """Checks that giving no options at all has defaults enough to create
        a sqlite db string"""
        self.assertEqual(self.bhs._generate_db_str({}), 'sqlite:' +
                         os.path.join('db', 'bloodhound.db'))

    def test_db_str_provided_db_string(self):
        """Checks that if a dbstring is provided it will not be respected above
        other options"""
        dbstr = 'sillyexample'
        options = {'dbstring': dbstr,}
        self.assertEqual(self.bhs._generate_db_str(options), dbstr)

    def test_writeconfig_create_basic_config(self):
        filepath = os.path.join(self.tempdir, 'basic.ini')
        data =  [self.basedata]
        self.bhs.writeconfig(filepath, data)
        self.assert_(os.path.exists(filepath))
        #check the file
        with file(filepath) as f:
            fdata = f.read()
            self.assertIn('option1value', fdata)

    def test_writeconfig_update_config(self):
        """Checks that writing a new config with non-overlapping values updates
        an existing file"""
        filepath = os.path.join(self.tempdir, 'basic.ini')
        data =  [self.basedata]
        self.bhs.writeconfig(filepath, data)
        newdata = [{'section': {'option3': 'option3value',},}]
        self.bhs.writeconfig(filepath, newdata)
        #check the file
        with file(filepath) as f:
            fdata = f.read()
            self.assertIn('option3value', fdata)

    def test_writeconfig_update_config_overwrite_values(self):
        """Checks that writing a new config with non-overlapping values updates
        an existing file"""
        filepath = os.path.join(self.tempdir, 'basic.ini')
        data =  [self.basedata]
        self.bhs.writeconfig(filepath, data)
        newdata = [{'section': {'option2': 'newopt2value',},}]
        self.bhs.writeconfig(filepath, newdata)
        with file(filepath) as f:
            fdata = f.read()
            self.assertIn('newopt2value', fdata)
            self.assertNotIn('option2value', fdata)
Esempio n. 4
0
class BloodhoundSetupTest(unittest.TestCase):
    def setUp(self):
        self.tempdir = mkdtemp()
        self.bhs = BloodhoundSetup({})
        self.basedata =  {'section': {'option1': 'option1value',
                              'option2': 'option2value',},}
    
    def tearDown(self):
        shutil.rmtree(self.tempdir)
    
    def test_db_str_no_options(self):
        """Checks that giving no options at all has defaults enough to create
        a sqlite db string"""
        self.assertEqual(self.bhs._generate_db_str({}), 'sqlite:' +
                         os.path.join('db', 'bloodhound.db'))
    
    def test_db_str_provided_db_string(self):
        """Checks that if a dbstring is provided it will not be respected above
        other options"""
        dbstr = 'sillyexample'
        options = {'dbstring': dbstr,}
        self.assertEqual(self.bhs._generate_db_str(options), dbstr)
    
    def test_writeconfig_create_basic_config(self):
        filepath = os.path.join(self.tempdir, 'basic.ini')
        data =  [self.basedata]
        self.bhs.writeconfig(filepath, data)
        self.assert_(os.path.exists(filepath))
        #check the file
        with file(filepath) as f:
            fdata = f.read()
            self.assertIn('option1value', fdata)
    
    def test_writeconfig_update_config(self):
        """Checks that writing a new config with non-overlapping values updates
        an existing file"""
        filepath = os.path.join(self.tempdir, 'basic.ini')
        data =  [self.basedata]
        self.bhs.writeconfig(filepath, data)
        newdata = [{'section': {'option3': 'option3value',},}]
        self.bhs.writeconfig(filepath, newdata)
        #check the file
        with file(filepath) as f:
            fdata = f.read()
            self.assertIn('option3value', fdata)
    
    def test_writeconfig_update_config_overwrite_values(self):
        """Checks that writing a new config with non-overlapping values updates
        an existing file"""
        filepath = os.path.join(self.tempdir, 'basic.ini')
        data =  [self.basedata]
        self.bhs.writeconfig(filepath, data)
        newdata = [{'section': {'option2': 'newopt2value',},}]
        self.bhs.writeconfig(filepath, newdata)
        with file(filepath) as f:
            fdata = f.read()
            self.assertIn('newopt2value', fdata)
            self.assertNotIn('option2value', fdata)