Example #1
0
 def test_config(self):
     config.set("test_flag", False)
     config.save()
     
     # Get a hash of the file
     with open(config.config_path) as f:
         file_hash = hash(f.read())
     
     # Get a value
     r = config.get("test_flag")
     not_r = not r
     
     # Innit should not override the existing value
     config.init("test_flag", not_r)
     self.assertNotEqual(not_r, config.get("test_flag"))
     
     config.set("test_flag", not_r)
     
     # Ensure everything is still as it was
     with open(config.config_path) as f:
         self.assertEqual(file_hash, hash(f.read()))
     
     # Now try to save it
     config.save()
     
     with open(config.config_path) as f:
         self.assertNotEqual(file_hash, hash(f.read()))
     
     # Now try to set a new property
     config.delete("test_flag2")
     self.assertEqual(config.check("test_flag2"), False)
     
     # Lets set it and then delete it, just to be sure
     config.set("test_flag2", False)
     self.assertEqual(config.check("test_flag2"), True)
     
     # Now save it, it should have a diffrent hash
     config.save()
     with open(config.config_path) as f:
         self.assertNotEqual(file_hash, hash(f.read()))
     
     # Delete the check
     config.delete("test_flag2")
     
     # Check it's all back to how it started
     config.set("test_flag", False)
     config.save()
     with open(config.config_path) as f:
         self.assertEqual(file_hash, hash(f.read()))
Example #2
0
    password    = ""
    dbname      = ""
    
    config.init("mock_db_host",       "localhost")
    config.init("mock_db_username",   "username")
    config.init("mock_db_password",   "password")
    config.init("mock_db_name",       "profiteer")
    
    config.init("db_host",            "localhost")
    config.init("db_username",        "username")
    config.init("db_password",        "password")
    config.init("db_name",            "profiteer_mock")
    
    config.init("use_mock_db",            False)
    
    config.save()

except Exception as e:
    raise

def query(cursor, *queries):
    for q in queries:
        if type(q) == list or type(q) == tuple:
            query(cursor, *q)
        else:
            if q[0:2] == "--": continue
            if q.strip() == "": continue
            try: cursor.execute(q)
            except Exception as e:
                raise Exception("Database error: %s\nQuery: %s" % (str(e.args[0]).replace("\n",""), q))