Exemple #1
0
class databaseTest(unittest.TestCase):
    def setUp(self):
        self.cdata = """
[database]
host = 127.0.0.1
user = postgres
password = postgres
database = floranet
"""
        self.db = Database()
        self.db.parser = ConfigParser.SafeConfigParser()
        self.db.parser.readfp(io.BytesIO(self.cdata))

    def test_parseConfig(self):

        # Mock the os calls and parser read.
        os.path.exists = MagicMock()
        os.path.isfile = MagicMock()
        self.db.parser.read = MagicMock()

        expected = ['127.0.0.1', 'postgres', 'postgres', 'floranet']
        self.db.parseConfig('path')
        result = [
            self.db.host, self.db.user, self.db.password, self.db.database
        ]

        self.assertEqual(expected, result)
Exemple #2
0
    def setUp(self):
        self.cdata = """
[database]
host = 127.0.0.1
user = postgres
password = postgres
database = floranet
"""
        self.db = Database()
        self.db.parser = ConfigParser.SafeConfigParser()
        self.db.parser.readfp(io.BytesIO(self.cdata))
Exemple #3
0
    def setUp(self):

        # Twistar requirem
        Registry.getConfig = MagicMock(return_value=None)
        db = Database()
        db.register()

        # Get factory default configuration
        with patch.object(Model, 'save', MagicMock()):
            config = yield Config.loadFactoryDefaults()

        self.server = NetServer(config)
        self.webserver = WebServer(self.server)
        self.restapi = self.webserver.restapi
    def setUp(self):
        # Mock Registry
        Registry.getConfig = MagicMock(return_value=None)

        # Initialise Database object to create relationships
        db = Database()
        db.register()

        # Load configuration defaults
        config = Config()
        config.defaults()

        self.server = NetServer(config)
        self.webserver = WebServer(self.server)
        self.restapi = self.webserver.restapi
    def setUp(self):

        # Bootstrap the database
        fpath = os.path.realpath(__file__)
        config = os.path.dirname(fpath) + '/database.cfg'

        db = Database()
        db.parseConfig(config)
        db.start()
        db.register()

        self.device = yield Device.find(where=['appname = ?', 'azuredevice02'],
                                        limit=1)
        self.app = yield Application.find(
            where=['appeui = ?', self.device.appeui], limit=1)
Exemple #6
0
                        database=db.database)
    
    connectable = create_engine(url, poolclass=pool.NullPool)

    with connectable.connect() as connection:
        context.configure(
            connection=connection,
            target_metadata=target_metadata
        )

        with context.begin_transaction():
            context.run_migrations()

# Get the database configuration file path
cpath = os.path.dirname(os.path.realpath(__file__)) + '/../../../config/database.cfg'
print 'Using database configuration file {cpath}'.format(cpath=os.path.abspath(cpath))

# Parse the database configuration
db = Database()
if not db.parseConfig(cpath):
    print 'Could not parse the database contiguration file.'
    exit(1)

# Check the database exists
if not check_database(db):
    print 'The database {database} does not exist on the host ' \
          '{host}.'.format(database=db.database, host=db.host)
    exit(1)

run_migrations(db)