Beispiel #1
0
 def post(self, **args):
     """Return full status of IMEI."""
     try:
         response = dict()
         imei = args.get('imei')
         tac = imei[:GlobalConfig['TacLength']]  # slice TAC from IMEI
         paginate_sub = args.get('subscribers')
         paginate_pairs = args.get('pairs')
         status = CommonResources.get_imei(imei=args.get('imei'))  # get imei response from core
         if status:
             gsma_data = CommonResources.get_tac(tac)  # get gsma data from tac
             registration = CommonResources.get_reg(imei)
             gsma = CommonResources.serialize_gsma_data(tac_resp=gsma_data, reg_resp=registration, status_type="full")
             subscribers = CommonResources.subscribers(status.get('imei_norm'), paginate_sub.get('start', 1), paginate_sub.get('limit', 10))  # get subscribers data
             pairings = CommonResources.pairings(status.get('imei_norm'), paginate_pairs.get('start', 1), paginate_pairs.get('limit', 10))  # get pairing data
             response['imei'] = status.get('imei_norm')
             response['classification_state'] = status['classification_state']
             response['registration_status'] = CommonResources.get_status(status['registration_status'], "registration")
             response['stolen_status'] = CommonResources.get_status(status['stolen_status'], "stolen")
             compliance = CommonResources.compliance_status(status, "full")  # get compliance status
             response = dict(response, **gsma, **subscribers, **pairings, **compliance)
             return Response(json.dumps(response), status=RESPONSES.get('OK'), mimetype=MIME_TYPES.get('JSON'))
         else:
             return custom_response("Failed to retrieve IMEI response from core system.", RESPONSES.get('SERVICE_UNAVAILABLE'), mimetype=MIME_TYPES.get('JSON'))
     except Exception as e:
         app.logger.info("Error occurred while retrieving full status.")
         app.logger.exception(e)
         return custom_response("Failed to retrieve full status.", RESPONSES.get('SERVICE_UNAVAILABLE'), mimetype=MIME_TYPES.get('JSON'))
def test_p_non_compliant_imei(mocked_imei_data):
    """Tests provisionally non compliant IMEI"""
    p_non_complaint_imei_response = mocked_imei_data[
        'provisionally_non_compliant']
    response = CommonResources.compliance_status(p_non_complaint_imei_response,
                                                 'basic')
    assert "Provisionally non compliant" in response['compliant']['status']
def test_local_stolen_imei(mocked_imei_data):
    """Tests IMEI meeting local stolen condition"""
    local_stolen_imei_response = mocked_imei_data['local_stolen_imei']
    response = CommonResources.compliance_status(local_stolen_imei_response, 'basic')
    assert 'Device is stolen' in response['compliant']['inactivity_reasons']
def test_duplicate_imei(mocked_imei_data):
    """Tests IMEI meeting duplicate condition"""
    dupliacte_imei_response = mocked_imei_data['duplicate_imei']
    response = CommonResources.compliance_status(dupliacte_imei_response, 'basic')
    assert 'IMEI is duplicate' in response['compliant']['inactivity_reasons']
def test_gsma_not_found_imei(mocked_imei_data):
    """Tests IMEI meeting gsma not found condition"""
    gsma_not_found_imei_response = mocked_imei_data['gsma_not_found_imei']
    response = CommonResources.compliance_status(gsma_not_found_imei_response, 'basic')
    assert 'GSMA not found' in response['compliant']['inactivity_reasons']
def test_non_compliant_imei(mocked_imei_data):
    """Tests non compliant IMEI"""
    non_compliant_imei_response = mocked_imei_data['non_compliant_imei']
    response = CommonResources.compliance_status(non_compliant_imei_response, 'basic')
    assert "Non compliant" in response['compliant']['status']