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)
def test_registration_request_duplicated_imeis(flask_app, db): # pylint: disable=unused-argument """Verify that the system does not allow the request approval when there are duplicated imeis in the request and responds properly. """ headers = {'Content-Type': 'application/json'} data = { 'device_count': 1, 'imei_per_device': 1, 'imeis': "[['00010673016999']]", 'm_location': 'local', 'user_name': 'reg req approve rev user 6', 'user_id': 'reg-req-approve-rev-user-6' } request = create_assigned_dummy_request(data, 'Registration', 'reg-req-approve-rev-user-6', 'reg req approve rev user 6') assert request request_id = request.id user_id = request.user_id # add duplicated imei to approvedimeis approved_imei = ApprovedImeis('00010673016999', 673739, 'whitelist', 'update') approved_imei.add() 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-6', 'reg req approve rev user 6', 6, request_id) RegComments.add('device_description', 'test comment on section', 'reg-req-approve-rev-user-6', 'reg req approve rev user 6', 6, request_id) RegComments.add('imei_classification', 'test comment on section', 'reg-req-approve-rev-user-6', 'reg req approve rev user 6', 6, request_id) RegComments.add('imei_registration', 'test comment on section', 'reg-req-approve-rev-user-6', 'reg req approve rev user 6', 6, request_id) RegComments.add('approval_documents', 'test comment on section', 'reg-req-approve-rev-user-6', 'reg req approve rev user 6', 6, request_id) body_data = { 'request_id': request_id, 'request_type': 'registration_request', 'reviewer_id': 'reg-req-approve-rev-user-6' } rv = flask_app.put(SUBMIT_REVIEW_API, data=json.dumps(body_data), headers=headers) assert rv.status_code == 400 data = json.loads(rv.data.decode('utf-8')) assert data['error'] == ['unable to approve case {0}, duplicated imeis found'.format(request_id)]
def test_registration_request_info_requested_status_priority(flask_app, db): # pylint: disable=unused-argument """Verify that the information requested section status has the 2nd highest priority means when any of the section is marked as information requested the whole case will be marked as information requested regardless of other section statuses. """ headers = {'Content-Type': 'application/json'} data = { 'device_count': 1, 'imei_per_device': 1, 'imeis': "[['44414441016777']]", 'm_location': 'local', 'user_name': 'reg req approve rev user 10', 'user_id': 'reg-req-approve-rev-user-10' } request = create_assigned_dummy_request(data, 'Registration', 'reg-req-approve-rev-user-10', 'reg req approve rev user 10') 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 # mark only one section as information requested RegComments.add('device_quota', 'test comment on section', 'reg-req-approve-rev-user-10', 'reg req approve rev user 10', 6, request_id) RegComments.add('device_description', 'test comment on section', 'reg-req-approve-rev-user-10', 'reg req approve rev user 10', 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-10' } 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
def test_registration_request_rejected_status_priority(flask_app, db): # pylint: disable=unused-argument """Verify that the rejected section status have highest priority means even if the first section is rejected, remaining are not reviewed, the system allows the review submission and mark the request as rejected. """ headers = {'Content-Type': 'application/json'} data = { 'device_count': 1, 'imei_per_device': 1, 'imeis': "[['33310001016666']]", 'm_location': 'local', 'user_name': 'reg req approve rev user 9', 'user_id': 'reg-req-approve-rev-user-9' } request = create_assigned_dummy_request(data, 'Registration', 'reg-req-approve-rev-user-9', 'reg req approve rev user 9') 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 # reject device quota and mark device_description as info-requested RegComments.add('device_quota', 'test comment on section', 'reg-req-approve-rev-user-9', 'reg req approve rev user 9', 7, request_id) RegComments.add('device_description', 'test comment on section', 'reg-req-approve-rev-user-9', 'reg req approve rev user 9', 5, request_id) body_data = { 'request_id': request_id, 'request_type': 'registration_request', 'reviewer_id': 'reg-req-approve-rev-user-9' } 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'] == 7 assert data['request_id'] == request_id
def test_registration_request_any_section_none(flask_app, db): # pylint: disable=unused-argument """Verify that the system does not allow to submit the review when any of the section is not reviewed or status is none. """ headers = {'Content-Type': 'application/json'} data = { 'device_count': 1, 'imei_per_device': 1, 'imeis': "[['22210376016777']]", 'm_location': 'local', 'user_name': 'reg req approve rev user 8', 'user_id': 'reg-req-approve-rev-user-8' } request = create_assigned_dummy_request(data, 'Registration', 'reg-req-approve-rev-user-8', 'reg req approve rev user 8') 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 only 2 section, leave rest of them none RegComments.add('device_quota', 'test comment on section', 'reg-req-approve-rev-user-8', 'reg req approve rev user 8', 6, request_id) RegComments.add('device_description', 'test comment on section', 'reg-req-approve-rev-user-8', 'reg req approve rev user 8', 6, request_id) body_data = { 'request_id': request_id, 'request_type': 'registration_request', 'reviewer_id': 'reg-req-approve-rev-user-8' } rv = flask_app.put(SUBMIT_REVIEW_API, data=json.dumps(body_data), headers=headers) assert rv.status_code == 400 data = json.loads(rv.data.decode('utf-8')) assert data['error'] == [ 'unable to update case {0}, complete review process'.format(request_id) ]
def add_comment(cls, section, comment, user_id, user_name, status, request_id): """Method to add comment on request.""" request = cls.get_by_id(request_id) RegComments.add(section, comment, user_id, user_name, status, request.id) try: db.session.add(request) db.session.commit() except Exception: db.session.rollback() raise Exception
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')
def get_section_by_state(cls, request_id, section_type): """Method to return most recent state of a section""" request = RegDetails.get_by_id(request_id) section_data = RegComments.get_all_by_section_type( request.id, section_type) # return data of latest section status if len(section_data) > 0: section_status = section_data[0].status section_type = section_type comments = [] for sec in section_data: comment = { 'user_id': sec.user_id, 'user_name': sec.user_name, 'comment': sec.comment, 'datetime': sec.added_at } comments.append(comment) return { 'section_type': section_type, 'section_status': section_status, 'comments': comments } else: return { 'section_type': section_type, 'section_status': None, 'comments': None }
def get_section_states(cls, request_id): """Method to return most recent state of the review-sections.""" request = RegDetails.get_by_id(request_id) sections = RegComments.get_all_by_regid(request.id) return sections
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