def test_exist_users(db, session):  # pylint: disable=unused-argument
    """Verify that the exist_user() work correctly."""
    # add a notification for user
    user_id = 'notf-user'
    request_id = 223
    request_type = 'registration'
    request_status = 3
    message = 'this is a test notification'
    notification = Notification(user_id=user_id,
                                request_id=request_id,
                                request_type=request_type,
                                request_status=request_status,
                                message=message)
    notification.add()
    user_exists_bool = Notification.exist_users(user_id)

    # check if it really exists in db
    res = exists_user_notifications(session, user_id)
    assert res is user_exists_bool

    # remove the above notification and then check again
    assert delete_user_notifications(session, user_id)
    user_exists_bool = Notification.exist_users(user_id)
    res = exists_user_notifications(session, user_id)
    assert res is user_exists_bool
Esempio n. 2
0
def test_registration_request_information_requested(flask_app, db):  # pylint: disable=unused-argument
    """Verify that when any of the section is marked as information requested the
    system automatically mark the whole request as information requested.
    """
    headers = {'Content-Type': 'application/json'}
    data = {
        'device_count': 1,
        'imei_per_device': 1,
        'imeis': "[['11110673016888']]",
        'm_location': 'local',
        'user_name': 'reg req approve rev user 7',
        'user_id': 'reg-req-approve-rev-user-7'
    }
    request = create_assigned_dummy_request(data, 'Registration',
                                            'reg-req-approve-rev-user-7', 'reg req approve rev user 7')
    assert request
    request_id = request.id
    user_id = request.user_id

    device_data = {
        'brand': 'samsung',
        'operating_system': 'android',
        'model_name': 's9',
        'model_num': '30jjd',
        'device_type': 'Smartphone',
        'technologies': '2G,3G,4G',
        'reg_id': request.id
    }
    request = create_dummy_devices(device_data, 'Registration', request)
    assert request

    # create user quota
    quota = DeviceQuota.create(user_id, 'individual')
    assert quota

    # approve all sections manually
    RegComments.add('device_quota', 'test comment on section', 'reg-req-approve-rev-user-7',
                    'reg req approve rev user 7', 6, request_id)
    RegComments.add('device_description', 'test comment on section', 'reg-req-approve-rev-user-7',
                    'reg req approve rev user 7', 6, request_id)
    RegComments.add('imei_classification', 'test comment on section', 'reg-req-approve-rev-user-7',
                    'reg req approve rev user 7', 5, request_id)
    RegComments.add('imei_registration', 'test comment on section', 'reg-req-approve-rev-user-7',
                    'reg req approve rev user 7', 6, request_id)
    RegComments.add('approval_documents', 'test comment on section', 'reg-req-approve-rev-user-7',
                    'reg req approve rev user 7', 6, request_id)

    body_data = {
        'request_id': request_id,
        'request_type': 'registration_request',
        'reviewer_id': 'reg-req-approve-rev-user-7'
    }
    rv = flask_app.put(SUBMIT_REVIEW_API, data=json.dumps(body_data), headers=headers)
    assert rv.status_code == 201
    data = json.loads(rv.data.decode('utf-8'))
    assert data['status'] == 5
    assert data['request_id'] == request_id
    assert data['message'] == 'case {0} updated successfully'.format(request_id)
    assert data['request_type'] == 'registration_request'
    assert Notification.exist_users(user_id)
Esempio n. 3
0
    def put(self, **kwargs):
        """Put method handler for notification route."""
        user_id = kwargs.get('user_id')
        notification_id = kwargs.get('notification_id')

        if NotificationModel.exist_users(user_id):
            if NotificationModel.exists(notification_id):
                notification = NotificationModel.get_single(notification_id)
                if notification.user_id == user_id:
                    NotificationModel.mark_read(notification_id)
                    return Response(status=201, mimetype='application/json')
                else:
                    res = {'error': ['invalid user id']}
                    return Response(json.dumps(ErrorResponse().dump(res).data),
                                    status=400,
                                    mimetype='application/json')
            else:
                res = {
                    'error': [
                        'notification {id} does not exists'.format(
                            id=notification_id)
                    ]
                }
                return Response(json.dumps(ErrorResponse().dump(res).data),
                                status=400,
                                mimetype='application/json')
        else:
            res = {'error': ['user {id} does not exists'.format(id=user_id)]}
            return Response(json.dumps(ErrorResponse().dump(res).data),
                            status=400,
                            mimetype='application/json')
def test_registration_request_rejected_section(flask_app, db):  # pylint: disable=unused-argument
    """Verify that the registration request gets rejected when anyone of the section
    is marked as rejected, imeis are removed from approvedimeis and notification is
    being generated.
    """
    # only one section is reviewed and rejected
    headers = {'Content-Type': 'application/json'}
    data = {
        'device_count': 1,
        'imei_per_device': 1,
        'imeis': "[['23010403010533']]",
        'm_location': 'local',
        'user_name': '23423423rev user 1',
        'user_id': 'assign-rev23442342-user-1'
    }
    request = create_assigned_dummy_request(data, 'Registration', 'rev230987',
                                            'rev 230987')
    assert request
    request_id = request.id
    device_data = {
        'brand': 'samsung',
        'operating_system': 'android',
        'model_name': 's9',
        'model_num': '30jjd',
        'device_type': 'Smartphone',
        'technologies': '2G,3G,4G',
        'reg_id': request.id
    }
    request = create_dummy_devices(device_data, 'Registration', request)
    assert request
    # add one section with rejected status
    RegComments.add('device_quota', 'test comment on section', 'rev230987',
                    'rev 230987', 7, request_id)
    body_data = {
        'request_id': request_id,
        'request_type': 'registration_request',
        'reviewer_id': 'rev230987'
    }
    rv = flask_app.put(SUBMIT_REVIEW_API,
                       data=json.dumps(body_data),
                       headers=headers)
    assert rv.status_code == 201
    response = json.loads(rv.data.decode('utf-8'))
    assert response['status'] == 7
    assert response['request_id'] == request_id
    assert response['message'] == 'case {0} updated successfully'.format(
        request_id)
    assert response['request_type'] == 'registration_request'
    imei = ApprovedImeis.get_imei('23010403010533')
    assert imei.status == 'removed'
    assert imei.delta_status == 'remove'
    assert Notification.exist_users('assign-rev23442342-user-1')
Esempio n. 5
0
def test_de_registration_request_rejected_section(flask_app, db, app):
    """Verify that the de_registration request gets rejected when anyone of the section
        is marked as rejected, imeis are removed from approvedimeis and notification is
        being generated.
        """
    # de registration request
    headers = {'Content-Type': 'application/json'}
    de_registration_data = {
        'file': 'de-reg-test-file.txt',
        'device_count': 1,
        'user_id': 'dereg-section-submit-assign-rev-user-1',
        'user_name': 'submit assign rev user 1',
        'reason': 'because we have to run tests successfully'
    }
    request = create_assigned_dummy_request(de_registration_data, 'De_Registration', 'dereg-rejected-section-rev',
                                            'de reg rev')
    device_data = {
        'devices': """[
               {
                   "tac": "95762201",
                   "model_name": "TA-1034",
                   "brand_name": "NOKIA",
                   "model_num": "TA-1034",
                   "technology": "NONE",
                   "device_type": "Mobile Phone/Feature phone",
                   "count": 2,
                   "operating_system": "N/A"
               }
           ]""",
        'dereg_id': request.id
    }
    request = create_dummy_devices(device_data, 'De_Registration', request, db, file_content=['957622010005119'],
                                   file_path='{0}/{1}/{2}'.format(app.config['DRS_UPLOADS'], request.tracking_id,
                                                                  de_registration_data.get('file')))
    assert request
    request_id = request.id
    DeRegComments.add('device_description', 'test comment on section', 'dereg-rejected-section-rev', 'rev 230987', 7,
                      request_id)
    body_data = {
        'request_id': request_id,
        'request_type': 'de_registration_request',
        'reviewer_id': 'dereg-rejected-section-rev'
    }
    rv = flask_app.put(SUBMIT_REVIEW_API, data=json.dumps(body_data), headers=headers)
    assert rv.status_code == 201
    response = json.loads(rv.data.decode('utf-8'))
    assert response['status'] == 7
    assert response['request_id'] == request_id
    assert response['message'] == 'case {0} updated successfully'.format(request_id)
    assert response['request_type'] == 'de_registration_request'
    assert Notification.exist_users('dereg-section-submit-assign-rev-user-1')
Esempio n. 6
0
def test_registration_request_approval(flask_app, db):  # pylint: disable=unused-argument
    """Verify that the api behave properly upon approval of the request."""
    # only one section is reviewed and rejected
    headers = {'Content-Type': 'application/json'}
    data = {
        'device_count': 1,
        'imei_per_device': 1,
        'imeis': "[['94310813016000']]",
        'm_location': 'local',
        'user_name': 'reg req approve rev user 5',
        'user_id': 'reg-req-approve-rev-user-5'
    }
    request = create_assigned_dummy_request(data, 'Registration',
                                            'reg-req-approve-rev-user-5', 'reg req approve rev user 5')
    assert request
    request_id = request.id
    user_id = request.user_id
    device_data = {
        'brand': 'samsung',
        'operating_system': 'android',
        'model_name': 's9',
        'model_num': '30jjd',
        'device_type': 'Smartphone',
        'technologies': '2G,3G,4G',
        'reg_id': request.id
    }
    request = create_dummy_devices(device_data, 'Registration', request)
    assert request

    # create user quota
    quota = DeviceQuota.create(user_id, 'individual')
    assert quota
    user_reg_quota = quota.reg_quota

    # approve all sections manually
    RegComments.add('device_quota', 'test comment on section', 'reg-req-approve-rev-user-5',
                    'reg req approve rev user 5', 6, request_id)
    RegComments.add('device_description', 'test comment on section', 'reg-req-approve-rev-user-5',
                    'reg req approve rev user 5', 6, request_id)
    RegComments.add('imei_classification', 'test comment on section', 'reg-req-approve-rev-user-5',
                    'reg req approve rev user 5', 6, request_id)
    RegComments.add('imei_registration', 'test comment on section', 'reg-req-approve-rev-user-5',
                    'reg req approve rev user 5', 6, request_id)
    RegComments.add('approval_documents', 'test comment on section', 'reg-req-approve-rev-user-5',
                    'reg req approve rev user 5', 6, request_id)

    body_data = {
        'request_id': request_id,
        'request_type': 'registration_request',
        'reviewer_id': 'reg-req-approve-rev-user-5'
    }
    rv = flask_app.put(SUBMIT_REVIEW_API, data=json.dumps(body_data), headers=headers)
    assert rv.status_code == 201
    data = json.loads(rv.data.decode('utf-8'))
    assert data['status'] == 6
    assert data['request_id'] == request_id
    assert data['message'] == 'case {0} updated successfully'.format(request_id)
    assert data['request_type'] == 'registration_request'
    imei = ApprovedImeis.get_imei('94310813016000')
    assert imei.status == 'whitelist'
    assert imei.delta_status == 'add'
    assert Notification.exist_users(user_id)
    assert DeviceQuota.get(user_id).reg_quota == user_reg_quota - 1