Esempio n. 1
0
def setup_db_deviceagent(data, initialize=True):
    """Create the database for DeviceAgent table testing.

    Args:
        None

    Returns:
        result: Tuple of (idx_device, idx_agent)

    """
    # Initialize key variables
    devicename = data['devicename']
    id_agent = data['id_agent']
    agent_name = data['agent']
    last_timestamp = data['timestamp']

    # Initialize database if requested
    if initialize is True:
        # Drop the database and create tables
        initialize_db()

    # Add record to the database
    record = Agent(id_agent=general.encode(id_agent),
                   name=general.encode(agent_name))
    database = db.Database()
    database.add(record, 1031)

    # Get idx_agent value from database
    agent_info = db_agent.GetIDAgent(id_agent)
    idx_agent = agent_info.idx_agent()

    # Add record to the database
    dev_record = Device(devicename=general.encode(devicename))
    database = db.Database()
    database.add(dev_record, 1034)

    # Get idx of newly added device
    device_info = db_device.GetDevice(devicename)
    idx_device = device_info.idx_device()

    # Update DeviceAgent table
    if hagent.device_agent_exists(idx_device, idx_agent) is False:
        # Add to DeviceAgent table
        da_record = DeviceAgent(idx_device=idx_device, idx_agent=idx_agent)
        database = db.Database()
        database.add(da_record, 1020)

    # Update DeviceAgent table with timestamp
    database = db.Database()
    session = database.session()
    record = session.query(DeviceAgent).filter(
        and_(DeviceAgent.idx_device == idx_device,
             DeviceAgent.idx_agent == idx_agent)).one()
    record.last_timestamp = last_timestamp
    database.commit(session, 1042)

    # Return
    result = (idx_device, idx_agent)
    return result
Esempio n. 2
0
def all_device_indices():
    """Get list of all device indexes in database.

    Args:
        None

    Returns:
        listing: List of indexes

    """
    idx_list = []

    # Establish a database session
    database = db.Database()
    session = database.session()
    result = session.query(RiderDeviceAgents.idx_riderdevice)

    # Add to the list of device idx values
    for instance in result:
        idx_list.append(instance.idx_riderdevice)

    # Return the session to the pool after processing
    database.close()

    # Return
    return list(set(idx_list))
Esempio n. 3
0
def agent_indices(idx_riderdevice):
    """Get list of all agent indexes for a specific device_idx.

    Args:
        None

    Returns:
        listing: List of indexes

    """
    idx_list = []

    # Fix values passed
    if isinstance(idx_riderdevice, int) is False:
        idx_riderdevice = None

    # Establish a database session
    database = db.Database()
    session = database.session()
    result = session.query(RiderDeviceAgents.idx_agent).filter(
        RiderDeviceAgents.idx_riderdevice == idx_riderdevice)

    # Add to the list of device idx values
    for instance in result:
        idx_list.append(instance.idx_agent)

    # Return the session to the pool after processing
    database.close()

    # Return
    return idx_list
Esempio n. 4
0
def get_all_device_agents():
    """Get list of all RiderDeviceAgents indexes.

    Args:
        None

    Returns:
        listing: List of indexes

    """
    data = []

    # Establish a database session
    database = db.Database()
    session = database.session()
    result = session.query(RiderDeviceAgents)

    # Add to the list of device idx values
    for instance in result:
        data_dict = {}
        data_dict['idx_riderdeviceagent'] = instance.idx_riderdeviceagent
        data_dict['idx_agent'] = instance.idx_agent
        data_dict['idx_riderdevice'] = instance.idx_riderdevice
        data.append(data_dict)

    # Return the session to the pool after processing
    database.close()

    # Return
    return data
Esempio n. 5
0
def setup_db_department():
    """Create the database for Department table testing.

    Args:
        None

    Returns:
        None

    """
    # Initialize key variables
    idx_department = 1

    # Create a dict of all the expected values
    expected = {
        'enabled': 1,
        'name': general.hashstring(general.randomstring()),
        'idx_department': idx_department,
        'code': general.hashstring(general.randomstring()),
    }

    # Drop the database and create tables
    initialize_db()

    # Insert data into database
    data = Department(code=general.encode(expected['code']),
                      name=general.encode(expected['name']))
    database = db.Database()
    database.add_all([data], 1048)

    # Return
    return expected
Esempio n. 6
0
    def __init__(self, idx_driverdevice):
        """Function for intializing the class.

        Args:
            idx_driverdevice: DriverDevice idx_driverdevice

        Returns:
            None

        """
        # Initialize important variables
        self.data_dict = defaultdict(dict)
        keys = [
            'idx_driverdevice', 'id_driverdevice', 'idx_driver', 'idx_route',
            'serial_driverdevice', 'idx_devicemodel', 'enabled']
        for key in keys:
            self.data_dict[key] = None
        self.data_dict['exists'] = False

        # Fix values passed
        if isinstance(idx_driverdevice, int) is False:
            idx_driverdevice = None

        # Only work if the value is an integer
        if (isinstance(idx_driverdevice, int) is True) and (
                idx_driverdevice is not None):
            # Get the result
            database = db.Database()
            session = database.session()
            result = session.query(DriverDevices).filter(
                DriverDevices.idx_driverdevice == idx_driverdevice)

            # Massage data
            if result.count() == 1:
                for instance in result:
                    self.data_dict['idx_driverdevice'] = idx_driverdevice
                    self.data_dict[
                        'idx_devicemodel'] = instance.idx_devicemodel
                    self.data_dict[
                        'idx_route'] = instance.idx_route
                    self.data_dict[
                        'serial_driverdevice'] = general.decode(
                            instance.serial_driverdevice)
                    self.data_dict[
                        'id_driverdevice'] = general.decode(
                            instance.id_driverdevice)
                    self.data_dict['idx_driver'] = instance.idx_driver
                    self.data_dict['enabled'] = bool(instance.enabled)
                    self.data_dict['exists'] = True
                    break

            # Return the session to the database pool after processing
            database.close()
Esempio n. 7
0
    def __init__(self, idx_driver):
        """Function for intializing the class.

        Args:
            idx_driver: Driver idx_driver

        Returns:
            None

        """
        # Initialize important variables
        self.data_dict = defaultdict(dict)
        keys = [
            'idx_driver', 'first_name', 'last_name', 'idx_drivercompany',
            'password', 'off_duty', 'idx_billaddress', 'idx_address', 'enabled'
        ]
        for key in keys:
            self.data_dict[key] = None
        self.data_dict['exists'] = False

        # Fix values passed
        if isinstance(idx_driver, int) is False:
            idx_driver = None

        # Only work if the value is an integer
        if isinstance(idx_driver, int) is True and idx_driver is not None:
            # Get the result
            database = db.Database()
            session = database.session()
            result = session.query(Drivers).filter(
                Drivers.idx_driver == idx_driver)

            # Massage data
            if result.count() == 1:
                for instance in result:
                    self.data_dict['idx_driver'] = idx_driver
                    self.data_dict['idx_address'] = instance.idx_address
                    self.data_dict[
                        'idx_billaddress'] = instance.idx_billaddress
                    self.data_dict['password'] = general.decode(
                        instance.password)
                    self.data_dict['first_name'] = general.decode(
                        instance.first_name)
                    self.data_dict['last_name'] = general.decode(
                        instance.last_name)
                    self.data_dict['off_duty'] = instance.off_duty
                    self.data_dict['enabled'] = bool(instance.enabled)
                    self.data_dict['exists'] = True
                    break

            # Return the session to the database pool after processing
            database.close()
Esempio n. 8
0
    def __init__(self, idx_drivercompanyrating):
        """Function for intializing the class.

        Args:
            idx_drivercompanyrating: DriverCompanyRatings
                idx_drivercompanyrating

        Returns:
            None

        """
        # Initialize important variables
        self.data_dict = defaultdict(dict)
        keys = [
            'idx_drivercompanyrating', 'rating_value', 'rating_timestamp',
            'idx_drivercompany', 'enabled'
        ]
        for key in keys:
            self.data_dict[key] = None
        self.data_dict['exists'] = False

        # Fix values passed
        if isinstance(idx_drivercompanyrating, int) is False:
            idx_drivercompanyrating = None

        # Only work if the value is an integer
        if (isinstance(idx_drivercompanyrating, int) is
                True) and (idx_drivercompanyrating is not None):
            # Get the result
            database = db.Database()
            session = database.session()
            result = session.query(DriverCompanyRatings).filter(
                DriverCompanyRatings.idx_drivercompanyrating ==
                idx_drivercompanyrating)

            # Massage data
            if result.count() == 1:
                for instance in result:
                    self.data_dict[
                        'idx_drivercompanyrating'] = idx_drivercompanyrating
                    self.data_dict['rating_value'] = instance.rating_value
                    self.data_dict[
                        'idx_drivercompany'] = instance.idx_drivercompany
                    self.data_dict[
                        'rating_timestamp'] = instance.rating_timestamp
                    self.data_dict['enabled'] = bool(instance.enabled)
                    self.data_dict['exists'] = True
                    break

            # Return the session to the database pool after processing
            database.close()
Esempio n. 9
0
    def __init__(self, idx_vehiclecategory):
        """Function for intializing the class.

        Args:
            idx_vehiclecategory: VehicleCategory idx_vehiclecategory

        Returns:
            None

        """
        # Initialize important variables
        self.data_dict = defaultdict(dict)
        keys = [
            'idx_vehiclecategory', 'vehiclecategory_name', 'idx_vehiclemodel',
            'enabled'
        ]
        for key in keys:
            self.data_dict[key] = None
        self.data_dict['exists'] = False

        # Fix values passed
        if isinstance(idx_vehiclecategory, int) is False:
            idx_vehiclecategory = None

        # Only work if the value is an integer
        if isinstance(idx_vehiclecategory,
                      int) is (True and idx_vehiclecategory is not None):
            # Get the result
            database = db.Database()
            session = database.session()
            result = session.query(VehicleCategories).filter(
                VehicleCategories.idx_vehiclecategory == idx_vehiclecategory)

            # Massage data
            if result.count() == 1:
                for instance in result:
                    self.data_dict['idx_vehiclecategory'] = idx_vehiclecategory
                    self.data_dict['vehiclecategory_name'] = general.decode(
                        instance.vehiclecategory_name)
                    self.data_dict[
                        'idx_vehiclemodel'] = instance.idx_vehiclemodel
                    self.data_dict['enabled'] = bool(instance.enabled)
                    self.data_dict['exists'] = True
                    break

            # Return the session to the database pool after processing
            database.close()
Esempio n. 10
0
    def __init__(self, idx_vehicle):
        """Function for intializing the class.

        Args:
            idx_vehicle: Vehicle idx_vehicle

        Returns:
            None

        """
        # Initialize important variables
        self.data_dict = defaultdict(dict)
        keys = [
            'idx_vehicle', 'license_plate', 'vehicle_seats', 'vehicle_year',
            'rating_value', 'enabled'
        ]
        for key in keys:
            self.data_dict[key] = None
        self.data_dict['exists'] = False

        # Fix values passed
        if isinstance(idx_vehicle, int) is False:
            idx_vehicle = None

        # Only work if the value is an integer
        if isinstance(idx_vehicle, int) is True and idx_vehicle is not None:
            # Get the result
            database = db.Database()
            session = database.session()
            result = session.query(Vehicles).filter(
                Vehicles.idx_vehicle == idx_vehicle)

            # Massage data
            if result.count() == 1:
                for instance in result:
                    self.data_dict['idx_vehicle'] = idx_vehicle
                    self.data_dict['license_plate'] = general.decode(
                        instance.license_plate)
                    self.data_dict['vehicle_year'] = instance.vehicle_year
                    self.data_dict['vehicle_seats'] = instance.vehicle_seats
                    self.data_dict['rating_value'] = instance.rating_value
                    self.data_dict['enabled'] = bool(instance.enabled)
                    self.data_dict['exists'] = True
                    break

            # Return the session to the database pool after processing
            database.close()
Esempio n. 11
0
    def __init__(self, idx_riderdeviceagent):
        """Function for intializing the class.

        Args:
            idx_riderdeviceagent: RiderDeviceAgents idx_riderdeviceagent

        Returns:
            None

        """
        # Initialize important variables
        self.data_dict = defaultdict(dict)
        keys = [
            'idx_riderdeviceagent', 'idx_agent', 'enabled', 'idx_riderdevice'
        ]
        for key in keys:
            self.data_dict[key] = None
        self.data_dict['exists'] = False

        # Fix values passed
        if isinstance(idx_riderdeviceagent, int) is False:
            idx_riderdeviceagent = None

        # Only work if the value is an integer
        if isinstance(idx_riderdeviceagent,
                      int) is True and (idx_riderdeviceagent is not None):
            # Get the result
            database = db.Database()
            session = database.session()
            result = session.query(RiderDeviceAgents).filter(
                RiderDeviceAgents.idx_riderdeviceagent == idx_riderdeviceagent)

            # Massage data
            if result.count() == 1:
                for instance in result:
                    self.data_dict[
                        'idx_riderdeviceagent'] = idx_riderdeviceagent
                    self.data_dict['idx_agent'] = instance.idx_agent
                    self.data_dict['enabled'] = bool(instance.enabled)
                    self.data_dict[
                        'idx_riderdevice'] = instance.idx_riderdevice
                    self.data_dict['exists'] = True
                    break

            # Return the session to the database pool after processing
            database.close()
Esempio n. 12
0
    def __init__(self, idx_riderdevice, idx_agent):
        """Method initializing the class.

        Args:
            idx_riderdevice: Device idx
            idx_agent: Agent idx

        Returns:
            None

        """
        # Initialize key variables
        self.data_dict = defaultdict(dict)
        keys = ['last_timestamp', 'idx_riderdeviceagent', 'enabled']
        for key in keys:
            self.data_dict[key] = None
        self.data_dict['exists'] = False

        # Fix values passed
        if isinstance(idx_riderdevice, int) is False:
            idx_riderdevice = None
        if isinstance(idx_agent, int) is False:
            idx_agent = None

        # Establish a database session
        database = db.Database()
        session = database.session()
        result = session.query(RiderDeviceAgents).filter(
            and_(RiderDeviceAgents.idx_riderdevice == idx_riderdevice,
                 RiderDeviceAgents.idx_agent == idx_agent))

        # Massage data
        if result.count() == 1:
            for instance in result:
                self.data_dict['last_timestamp'] = instance.last_timestamp
                self.data_dict[
                    'idx_riderdeviceagent'] = instance.idx_riderdeviceagent
                self.data_dict['enabled'] = bool(instance.enabled)
                self.data_dict['exists'] = True
                break

        # Return the session to the database pool after processing
        database.close()
Esempio n. 13
0
    def __init__(self, idx_georegion):
        """Function for intializing the class.

        Args:
            idx_georegion: GeoCity idx_georegion

        Returns:
            None

        """
        # Initialize important variables
        self.data_dict = defaultdict(dict)
        keys = ['idx_georegion', 'georegion_name', 'enabled']
        for key in keys:
            self.data_dict[key] = None
        self.data_dict['exists'] = False

        # Fix values passed
        if isinstance(idx_georegion, int) is False:
            idx_georegion = None

        # Only work if the value is an integer
        if (isinstance(idx_georegion, int) is True) and (idx_georegion
                                                         is not None):
            # Get the result
            database = db.Database()
            session = database.session()
            result = session.query(GeoRegions).filter(
                GeoRegions.idx_georegion == idx_georegion)

            # Massage data
            if result.count() == 1:
                for instance in result:
                    self.data_dict['idx_georegion'] = idx_georegion
                    self.data_dict['georegion_name'] = general.decode(
                        instance.georegion_name)
                    self.data_dict['enabled'] = bool(instance.enabled)
                    self.data_dict['exists'] = True
                    break

            # Return the session to the database pool after processing
            database.close()
Esempio n. 14
0
    def __init__(self, idx_billaddress):
        """Function for intializing the class.

        Args:
            idx_billaddress: BillAddress idx_billaddress

        Returns:
            None

        """
        # Initialize important variables
        self.data_dict = defaultdict(dict)
        keys = ['idx_billaddress', 'idx_geocity', 'enabled']
        for key in keys:
            self.data_dict[key] = None
        self.data_dict['exists'] = False

        # Fix values passed
        if isinstance(idx_billaddress, int) is False:
            idx_billaddress = None

        # Only work if the value is an integer
        if isinstance(idx_billaddress,
                      int) is True and idx_billaddress is not None:
            # Get the result
            database = db.Database()
            session = database.session()
            result = session.query(BillAddresses).filter(
                BillAddresses.idx_billaddress == idx_billaddress)

            # Massage data
            if result.count() == 1:
                for instance in result:
                    self.data_dict['idx_billaddress'] = idx_billaddress
                    self.data_dict['idx_geocity'] = instance.idx_geocity
                    self.data_dict['enabled'] = bool(instance.enabled)
                    self.data_dict['exists'] = True
                    break

            # Return the session to the database pool after processing
            database.close()
Esempio n. 15
0
    def __init__(self, config_key):
        """Function for intializing the class.

        Args:
            config_key: Configuration config_key

        Returns:
            None

        """
        # Initialize important variables
        value = config_key.encode()
        self.data_dict = defaultdict(dict)
        keys = ['idx_configuration', 'config_key', 'config_value', 'enabled']
        for key in keys:
            self.data_dict[key] = None
        self.data_dict['exists'] = False

        # Establish a database session
        database = db.Database()
        session = database.session()
        result = session.query(
            Configurations).filter(Configurations.config_key == value)

        # Massage data
        if result.count() == 1:
            for instance in result:
                self.data_dict[
                    'idx_configuration'] = instance.idx_configuration
                self.data_dict['config_key'] = config_key
                self.data_dict[
                    'config_value'] = general.decode(instance.config_value)
                self.data_dict['enabled'] = bool(instance.enabled)
                self.data_dict['exists'] = True
                break

        # Return the session to the database pool after processing
        database.close()
Esempio n. 16
0
    def __init__(self, id_agent):
        """Function for intializing the class.

        Args:
            id_agent: Identifier of agent

        Returns:
            None

        """
        # Initialize important variables
        self.data_dict = defaultdict(dict)
        keys = ['idx_agent', 'idx_agentname', 'enabled']
        for key in keys:
            self.data_dict[key] = None
        self.data_dict['exists'] = False

        # Encode the id_agent
        value = id_agent.encode()

        # Establish a database session
        database = db.Database()
        session = database.session()
        result = session.query(Agents).filter(Agents.id_agent == value)

        # Massage data
        if result.count() == 1:
            for instance in result:
                self.data_dict['id_agent'] = id_agent
                self.data_dict['idx_agent'] = instance.idx_agent
                self.data_dict['idx_agentname'] = instance.idx_agentname
                self.data_dict['enabled'] = bool(instance.enabled)
                self.data_dict['exists'] = True
                break

        # Return the session to the database pool after processing
        database.close()
Esempio n. 17
0
def get_all_agents():
    """Get data on all agents in the database.

    Args:
        None

    Returns:
        data: List of dicts of agent data.

    """
    # Initialize important variables
    data = []

    # Establish a database session
    database = db.Database()
    session = database.session()
    result = session.query(Agents)

    # Massage data
    for instance in result:
        # Get next record
        data_dict = defaultdict(dict)
        data_dict['id_agent'] = general.decode(instance.id_agent)
        data_dict['idx_agent'] = instance.idx_agent
        data_dict['idx_agentname'] = instance.idx_agentname
        data_dict['enabled'] = bool(instance.enabled)
        data_dict['exists'] = True

        # Append to list
        data.append(data_dict)

    # Return the session to the database pool after processing
    database.close()

    # Return
    return data
Esempio n. 18
0
def setup_db_agent():
    """Create the database for Agent table testing.

    Args:
        None

    Returns:
        None

    """
    # Initialize key variables
    idx_agent = 1

    # Get an agent ID
    id_agent = general.hashstring('_MDL_TEST_')

    # Create a dict of all the expected values
    expected = {
        'id_agent': id_agent,
        'name': general.hashstring(general.randomstring()),
        'idx_agent': idx_agent,
        'enabled': 1
    }

    # Drop the database and create tables
    initialize_db()

    # Insert data into database
    data = Agent(id_agent=general.encode(expected['id_agent']),
                 name=general.encode(expected['name']),
                 enabled=expected['enabled'])
    database = db.Database()
    database.add_all([data], 1045)

    # Return
    return (id_agent, expected)
Esempio n. 19
0
def setup_db_device():
    """Create the database for Device table testing.

    Args:
        None

    Returns:
        None

    """
    # Initialize key variables
    idx_device = 1

    # Create a dict of all the expected values
    expected = {
        'devicename': general.hashstring(general.randomstring()),
        'description': general.hashstring(general.randomstring()),
        'ip_address': general.hashstring('100.100.100.100'),
        'idx_device': idx_device,
        'exists': True,
        'enabled': 1
    }

    # Drop the database and create tables
    initialize_db()

    # Insert data into database
    data = Device(description=general.encode(expected['description']),
                  devicename=general.encode(expected['devicename']),
                  ip_address=general.encode(expected['ip_address']),
                  enabled=expected['enabled'])
    database = db.Database()
    database.add_all([data], 1019)

    # Return
    return expected
Esempio n. 20
0
    def _add_records(self):
        """Add initial records to database tables.

        Args:
            None

        Returns:
            None

        """
        # Insert GeoCountries
        if db_geocountries.idx_geocountry_exists(1) is False:
            record = GeoCountries(geocountry_name=general.encode(
                self.reserved),
                                  enabled=0)
            database = db.Database()
            database.add(record, 1046)

        # Insert GeoCities
        if db_geocities.idx_geocity_exists(1) is False:
            record = GeoCities(geocity_name=general.encode(self.reserved),
                               enabled=0)
            database = db.Database()
            database.add(record, 1051)

        # Insert Addresses
        if db_addresses.idx_address_exists(1) is False:
            record = Addresses(enabled=0)
            database = db.Database()
            database.add(record, 1054)

        # Insert BillAddresses
        if db_billaddresses.idx_billaddress_exists(1) is False:
            record = BillAddresses(enabled=0)
            database = db.Database()
            database.add(record, 1053)

        # Insert DeviceModel
        if db_devicemodels.idx_devicemodel_exists(1) is False:
            record = DeviceModels(model_name=general.encode(self.reserved),
                                  enabled=0)
            database = db.Database()
            database.add(record, 1033)

        # Insert VehicleModel
        if db_vehiclemodels.idx_vehiclemodel_exists(1) is False:
            record = VehicleModels(model_name=general.encode(self.reserved),
                                   enabled=0)
            database = db.Database()
            database.add(record, 1001)

        # Insert Vehicle
        if db_vehicles.idx_vehicle_exists(1) is False:
            record = Vehicles(license_plate=general.encode(self.reserved),
                              enabled=0)
            database = db.Database()
            database.add(record, 1024)

        # Insert DriverCompany
        if db_drivercompanies.idx_drivercompany_exists(1) is False:
            record = DriverCompanies(drivercompany_name=general.encode(
                self.reserved),
                                     enabled=0)
            database = db.Database()
            database.add(record, 1004)

        # Insert Driver
        if db_drivers.idx_driver_exists(1) is False:
            record = Drivers(first_name=general.encode(self.reserved),
                             last_name=general.encode(self.reserved),
                             password=general.encode(self.reserved),
                             enabled=0)
            database = db.Database()
            database.add(record, 1037)

        # Insert RiderDevice
        if db_riderdevices.idx_riderdevice_exists(1) is False:
            record = RiderDevices(id_riderdevice=general.encode(self.reserved),
                                  serial_riderdevice=general.encode(
                                      self.reserved),
                                  enabled=0)
            database = db.Database()
            database.add(record, 1006)

        # Insert DriverDevice
        if db_driverdevices.idx_driverdevice_exists(1) is False:
            record = DriverDevices(
                id_driverdevice=general.encode(self.reserved),
                serial_driverdevice=general.encode(self.reserved),
                enabled=0)
            database = db.Database()
            database.add(record, 1008)

        # Insert VehicleCategory
        if db_vehiclecategories.idx_vehiclecategory_exists(1) is False:
            record = VehicleCategories(vehiclecategory_name=general.encode(
                self.reserved),
                                       enabled=0)
            database = db.Database()
            database.add(record, 1041)

        # Insert DriverCompanyRatings
        if db_companyratings.idx_drivercompanyrating_exists(1) is False:
            record = DriverCompanyRatings(enabled=0)
            database = db.Database()
            database.add(record, 1011)

        # Insert VehicleRatings
        if db_vehicleratings.idx_vehiclerating_exists(1) is False:
            record = VehicleRatings(enabled=0)
            database = db.Database()
            database.add(record, 1012)

        # Insert DriverRatings
        if db_driverratings.idx_driverrating_exists(1) is False:
            record = DriverRatings(enabled=0)
            database = db.Database()
            database.add(record, 1044)

        # Insert Agents
        if db_agents.idx_agent_exists(1) is False:
            record = Agents(id_agent=general.encode(self.reserved), enabled=0)
            database = db.Database()
            database.add(record, 1047)

        # Insert RiderDeviceAgents
        if db_riderdeviceagents.idx_riderdeviceagent_exists(1) is False:
            record = RiderDeviceAgents(enabled=0)
            database = db.Database()
            database.add(record, 1029)

        # Insert DriverDeviceAgents
        if db_driverdeviceagents.idx_driverdeviceagent_exists(1) is False:
            record = DriverDeviceAgents(enabled=0)
            database = db.Database()
            database.add(record, 1070)
Esempio n. 21
0
    def _add_records(self):
        """Add records.

        Args:
            None

        Returns:
            None

        """
        # Insert CreditCard
        if db_creditcards.idx_creditcard_exists(1) is False:
            record = CreditCards(enabled=0)
            database = db.Database()
            database.add(record, 1026)

        # Insert DeviceMake
        if db_devicemakes.idx_devicemake_exists(1) is False:
            record = DeviceMakes(make_name=general.encode(self.reserved),
                                 enabled=0)
            database = db.Database()
            database.add(record, 1027)

        # Insert Route
        if db_routes.idx_route_exists(1) is False:
            record = Routes(route_name=general.encode(self.reserved),
                            enabled=0)
            database = db.Database()
            database.add(record, 1002)

        # Insert Rider
        if db_riders.idx_rider_exists(1) is False:
            record = Riders(first_name=general.encode(self.reserved),
                            last_name=general.encode(self.reserved),
                            password=general.encode(self.reserved),
                            enabled=0)
            database = db.Database()
            database.add(record, 1003)

        # Insert VehicleMake
        if db_vehiclemakes.idx_vehiclemake_exists(1) is False:
            record = VehicleMakes(make_name=general.encode(self.reserved),
                                  enabled=0)
            database = db.Database()
            database.add(record, 1032)

        # Insert GeoRegions
        if db_georegions.idx_georegion_exists(1) is False:
            record = GeoRegions(georegion_name=general.encode(self.reserved),
                                enabled=0)
            database = db.Database()
            database.add(record, 1038)

        # Insert AgentNames
        if db_agentnames.idx_agentname_exists(1) is False:
            record = AgentNames(agent_name=general.encode(self.reserved),
                                enabled=0)
            database = db.Database()
            database.add(record, 1007)

        # Insert CompanyCategory
        if db_companycategories.idx_companycategory_exists(1) is False:
            record = CompanyCategories(companycategory_name=general.encode(
                self.reserved),
                                       enabled=0)
            database = db.Database()
            database.add(record, 1040)
Esempio n. 22
0
def setup_db_datapoint():
    """Create the database for Datapoint table testing.

    Args:
        None

    Returns:
        results: List of dicts of values to expect

    """
    # Initialize key variables
    idx_datapoint = 1
    results = []
    timestamp = general.normalized_timestamp()
    id_datapoint = general.hashstring(general.randomstring())
    devicename = general.hashstring(general.randomstring())
    id_agent = general.hashstring(general.randomstring())
    devicename = general.randomstring()
    agent_name = general.randomstring()

    # Drop the database and create tables
    initialize_db()

    # Initialize agent variables
    agent_data = {}
    agent_data['devicename'] = devicename
    agent_data['id_agent'] = id_agent
    agent_data['agent'] = agent_name
    agent_data['timestamp'] = timestamp
    (idx_device, idx_agent) = setup_db_deviceagent(agent_data,
                                                   initialize=False)

    # Get DeviceAgent index value
    deviceagent = hagent.GetDeviceAgent(idx_device, idx_agent)
    idx_deviceagent = deviceagent.idx_deviceagent()

    # Create dict of expected results
    expected = {
        'value': 100,
        'idx_datapoint': idx_datapoint,
        'timestamp': timestamp
    }

    # Insert Department data into database
    dept_data = Department(code=general.randomstring().encode())
    database = db.Database()
    database.add_all([dept_data], 1035)

    # Insert Billcode data into database
    bill_data = Billcode(code=general.randomstring().encode())
    database = db.Database()
    database.add_all([bill_data], 1039)

    # Insert Datapoint data into database
    new_data = Datapoint(idx_deviceagent=idx_deviceagent,
                         id_datapoint=general.encode(id_datapoint))
    database = db.Database()
    database.add_all([new_data], 1072)

    # Add value to expected
    expected['id_datapoint'] = id_datapoint
    results.append(expected)

    # Return
    return results