def get(self):
        """GET method handler for server-configs."""
        technologies = Technologies.get_technologies()
        device_types = DeviceType.get_device_types()
        status_types = Status.get_status_types()

        system_configs = {
            'label': 'automate_imei_request',
            'flag': app.config['AUTOMATE_IMEI_CHECK']
        },\
        {
            'label': 'overwrite_device_info',
            'flag': app.config['USE_GSMA_DEVICE_INFO']
        }

        documents = {
            'registration': Documents.get_documents('registration'),
            'de_registration': Documents.get_documents('deregistration')
        }

        response = ServerConfigSchema().dump(dict(technologies=technologies,
                                                  documents=documents,
                                                  status_types=status_types,
                                                  device_types=device_types,
                                                  system_config=system_configs)).data

        return Response(json.dumps(response), status=200, mimetype='application/json')
Beispiel #2
0
 def create(cls, args):
     """Create a new registration device."""
     try:
         reg_device = cls(args)
         device_type = DeviceType.get_device_type_id(args.get('device_type'))
         reg_device.device_types_id = device_type
         reg_device.reg_details_id = args.get('reg_details_id')
         reg_device.save()
         return reg_device
     except Exception:
         raise Exception
 def serialize_data(self, data):
     """Serializes/transforms data before dumping."""
     technologies_list = []
     if data.device_technologies:
         technologies = DeviceTechnology.get_device_technologies(data.id)
         for tech in technologies:
             tech_type = Technologies.get_technology_by_id(tech.technology_id)
             technologies_list.append(tech_type)
     data.technologies = technologies_list
     if data.device_types_id:
         device_type = DeviceType.get_device_type_by_id(data.device_types_id)
         data.device_type = device_type
    def get(self):
        """GET method handler for server-configs."""
        technologies = Technologies.get_technologies()
        device_types = DeviceType.get_device_types()
        status_types = Status.get_status_types()
        documents = {
            'registration': Documents.get_documents('registration'),
            'de_registration': Documents.get_documents('deregistration')
        }

        response = ServerConfigSchema().dump(dict(technologies=technologies,
                                                  documents=documents,
                                                  status_types=status_types,
                                                  device_types=device_types)).data
        return Response(json.dumps(response), status=200, mimetype='application/json')
Beispiel #5
0
 def update(cls, reg_device, args):
     """Update the current registration device."""
     try:
         if 'brand' in args:
             reg_device.brand = args.get('brand')
         if 'model_name' in args:
             reg_device.model_name = args.get('model_name')
         if 'model_num' in args:
             reg_device.model_num = args.get('model_num')
         if 'operating_system' in args:
             reg_device.operating_system = args.get('operating_system')
         if 'device_type' in args:
             device_type = DeviceType.get_device_type_id(args.get('device_type'))
             reg_device.device_types_id = device_type
         reg_device.save()
         if 'technologies' in args:
             reg_device.technologies = DeviceTechnology.update(reg_device, args.get('technologies'))
         return reg_device
     except Exception:
         raise Exception
def test_server_config_api(flask_app, db):  # pylint: disable=unused-argument
    """To verify that the server config apis response is correct as
    per data in database.
    """
    # get data from database
    status_types = Status.get_status_types()
    device_types = DeviceType.get_device_types()
    technologies = Technologies.get_technologies()
    documents = {
        'registration': Documents.get_documents('registration'),
        'de_registration': Documents.get_documents('deregistration')
    }
    expected_response = ServerConfigsSchema().dump(dict(technologies=technologies,
                                                        documents=documents,
                                                        status_types=status_types,
                                                        device_types=device_types)).data

    rv = flask_app.get(SERVER_CONFIGS)
    assert rv.status_code == 200
    data = json.loads(rv.data.decode('utf-8'))
    assert data == expected_response