def test_get_now_application_list_filter_by_multiple_filters(self, test_client, db_session,
                                                                 auth_headers):
        """Should return the records filtered by status, noticeofworktype, and tracking email"""

        now_submission_1 = NOWSubmissionFactory(status='Rejected', noticeofworktype='dog')
        identity_1 = NOWApplicationIdentityFactory(
            now_submission=now_submission_1, submission_only=True)
        now_submission_2 = NOWSubmissionFactory(status='Received', noticeofworktype='cat')
        identity_2 = NOWApplicationIdentityFactory(
            now_submission=now_submission_2, submission_only=True)
        now_submission_3 = NOWSubmissionFactory(status='Rejected', noticeofworktype='dog')
        identity_3 = NOWApplicationIdentityFactory(
            now_submission=now_submission_3, submission_only=True)
        now_submission_4 = NOWSubmissionFactory(status='Approved', noticeofworktype='cat')
        identity_4 = NOWApplicationIdentityFactory(
            now_submission=now_submission_4, submission_only=True)

        get_resp = test_client.get(
            f'now-applications?now_application_status_description=Approved&now_application_status_description=Rejected&notice_of_work_type_description=dog',
            headers=auth_headers['full_auth_header'])
        assert get_resp.status_code == 200, get_resp.response
        get_data = json.loads(get_resp.data.decode())
        assert len(get_data['records']) == 2
        assert all(
            str(submission.now_application_guid) in map(lambda x: x['now_application_guid'],
                                                        get_data['records'])
            for submission in [now_submission_1, now_submission_3])
        assert all(
            str(submission.now_application_guid) not in map(lambda x: x['now_application_guid'],
                                                            get_data['records'])
            for submission in [now_submission_2, now_submission_4])
    def test_get_now_application_list_filter_by_status(self, test_client, db_session, auth_headers):
        """Should return the records filtered by status"""

        now_submission_1 = NOWSubmissionFactory(status='Approved')
        identity_1 = NOWApplicationIdentityFactory(now_submission=now_submission_1)
        now_submission_2 = NOWSubmissionFactory(status='Received')
        identity_2 = NOWApplicationIdentityFactory(now_submission=now_submission_2)
        now_submission_3 = NOWSubmissionFactory(status='Rejected')
        identity_3 = NOWApplicationIdentityFactory(now_submission=now_submission_3)
        now_submission_4 = NOWSubmissionFactory(status='Rejected')
        identity_4 = NOWApplicationIdentityFactory(now_submission=now_submission_4)

        get_resp = test_client.get(
            f'now-applications?now_application_status_description=Approved&now_application_status_description=Received',
            headers=auth_headers['full_auth_header'])
        assert get_resp.status_code == 200, get_resp.response
        get_data = json.loads(get_resp.data.decode())

        assert len(get_data['records']) == 2
        assert all(
            str(submission.now_application_guid) in map(lambda x: x['now_application_guid'],
                                                        get_data['records'])
            for submission in [now_submission_1, now_submission_2])
        assert all(
            str(submission.now_application_guid) not in map(lambda x: x['now_application_guid'],
                                                            get_data['records'])
            for submission in [now_submission_3, now_submission_4])
    def test_get_now_application_list_filter_by_mine_region(self, test_client, db_session,
                                                            auth_headers):
        """Should return the records filtered by mine_region"""

        mine = MineFactory(mine_region='SE')
        mine2 = MineFactory(mine_region='NW')
        now_submission_1 = NOWSubmissionFactory(mine=mine)
        identity_1 = NOWApplicationIdentityFactory(now_submission=now_submission_1, mine=mine)
        now_submission_2 = NOWSubmissionFactory(mine=mine)
        identity_2 = NOWApplicationIdentityFactory(now_submission=now_submission_2, mine=mine)
        now_submission_3 = NOWSubmissionFactory(mine=mine2)
        identity_3 = NOWApplicationIdentityFactory(now_submission=now_submission_3, mine=mine2)
        now_submission_4 = NOWSubmissionFactory(mine=mine2)
        identity_4 = NOWApplicationIdentityFactory(now_submission=now_submission_4, mine=mine2)

        get_resp = test_client.get(
            f'now-applications?mine_region={mine.mine_region}',
            headers=auth_headers['full_auth_header'])
        assert get_resp.status_code == 200, get_resp.response
        get_data = json.loads(get_resp.data.decode())

        assert len(get_data['records']) == 2
        assert all(
            str(submission.now_application_guid) in map(lambda x: x['now_application_guid'],
                                                        get_data['records'])
            for submission in [now_submission_1, now_submission_2])
        assert all(
            str(submission.now_application_guid) not in map(lambda x: x['now_application_guid'],
                                                            get_data['records'])
            for submission in [now_submission_3, now_submission_4])
예제 #4
0
    def test_get_mine_application_list_success(self, test_client, db_session,
                                               auth_headers):
        """Should return the records for the mine with a 200 response code"""

        batch_size = 5
        other_applications = NOWApplicationIdentityFactory.create_batch(
            size=batch_size)
        mine = MineFactory(minimal=True)
        now_submission_1 = NOWSubmissionFactory(mine=mine)
        identity_1 = NOWApplicationIdentityFactory(
            now_submission=now_submission_1, mine=mine)
        now_submission_2 = NOWSubmissionFactory(mine=mine)
        identity_2 = NOWApplicationIdentityFactory(
            now_submission=now_submission_2, mine=mine)

        get_resp = test_client.get(
            f'now-applications?mine_guid={mine.mine_guid}',
            headers=auth_headers['full_auth_header'])
        assert get_resp.status_code == 200, get_resp.response
        get_data = json.loads(get_resp.data.decode())

        assert len(get_data['records']) == 2
        assert all(
            str(submission.now_application_guid) not in map(
                lambda x: x['now_application_guid'], get_data['records'])
            for submission in other_applications)
        assert all(
            str(submission.now_application_guid) in map(
                lambda x: x['now_application_guid'], get_data['records'])
            for submission in [now_submission_1, now_submission_1])
예제 #5
0
    def test_get_mine_application_list_filter_by_status(
            self, test_client, db_session, auth_headers):
        """Should return the records filtered by status"""

        mine = MineFactory(minimal=True)
        now_submission_1 = NOWSubmissionFactory(mine=mine, status='Accepted')
        identity_1 = NOWApplicationIdentityFactory(
            now_submission=now_submission_1, mine=mine)
        now_submission_2 = NOWSubmissionFactory(mine=mine, status='Withdrawn')
        identity_2 = NOWApplicationIdentityFactory(
            now_submission=now_submission_2, mine=mine)
        now_submission_3 = NOWSubmissionFactory(mine=mine, status='Withdrawn')
        identity_3 = NOWApplicationIdentityFactory(
            now_submission=now_submission_3, mine=mine)
        now_submission_4 = NOWSubmissionFactory(mine=mine, status='Withdrawn')
        identity_4 = NOWApplicationIdentityFactory(
            now_submission=now_submission_4, mine=mine)

        get_resp = test_client.get(
            f'now-applications?mine_guid={mine.mine_guid}&now_application_status_description=Accepted&now_application_status_description=Withdrawn',
            headers=auth_headers['full_auth_header'])
        assert get_resp.status_code == 200, get_resp.response
        get_data = json.loads(get_resp.data.decode())

        assert len(get_data['records']) == 2
        assert all(
            str(submission.now_application_guid) in map(
                lambda x: x['now_application_guid'], get_data['records'])
            for submission in [now_submission_1, now_submission_2])
        assert all(
            str(submission.now_application_guid) not in map(
                lambda x: x['now_application_guid'], get_data['records'])
            for submission in [now_submission_3, now_submission_4])
예제 #6
0
    def test_get_mine_application_list_filter_by_noticeofworktype(self, test_client, db_session,
                                                                  auth_headers):
        """Should return the records filtered by noticeofworktype"""

        mine = MineFactory(minimal=True)
        now_submission_1 = NOWSubmissionFactory(mine=mine, noticeofworktype='dog')
        identity_1 = NOWApplicationIdentityFactory(
            now_submission=now_submission_1, mine=mine, submission_only=True)
        now_submission_2 = NOWSubmissionFactory(mine=mine, noticeofworktype='dog')
        identity_2 = NOWApplicationIdentityFactory(
            now_submission=now_submission_2, mine=mine, submission_only=True)
        now_submission_3 = NOWSubmissionFactory(mine=mine, noticeofworktype='cat')
        identity_3 = NOWApplicationIdentityFactory(
            now_submission=now_submission_3, mine=mine, submission_only=True)
        now_submission_4 = NOWSubmissionFactory(mine=mine, noticeofworktype='parrot')
        identity_4 = NOWApplicationIdentityFactory(
            now_submission=now_submission_4, mine=mine, submission_only=True)

        get_resp = test_client.get(
            f'now-applications?mine_guid={mine.mine_guid}&notice_of_work_type_description=dog',
            headers=auth_headers['full_auth_header'])
        assert get_resp.status_code == 200, get_resp.response
        get_data = json.loads(get_resp.data.decode())

        assert len(get_data['records']) == 2
        assert all(
            str(submission.now_application_guid) in map(lambda x: x['now_application_guid'],
                                                        get_data['records'])
            for submission in [now_submission_1, now_submission_2])
        assert all(
            str(submission.now_application_guid) not in map(lambda x: x['now_application_guid'],
                                                            get_data['records'])
            for submission in [now_submission_3, now_submission_4])
    def test_post_now_application_messageid_in_use(self, test_client, db_session, auth_headers):
        """Should return a 400 messageid in use"""

        mine = MineFactory()
        application = NOWSubmissionFactory(mine=mine)
        NOW_APPLICATION_DATA['minenumber'] = mine.mine_no
        NOW_APPLICATION_DATA['messageid'] = application.messageid

        post_resp = test_client.post(
            '/now-submissions/applications',
            json=NOW_APPLICATION_DATA,
            headers=auth_headers['nros_vfcbc_auth_header'])

        assert post_resp.status_code == 400, post_resp.response
    def test_get_now_application_status_by_now_number_success(
            self, test_client, db_session, auth_headers):
        """Should return the correct record with a 200 response code"""

        now_submission = NOWSubmissionFactory()
        identity = NOWApplicationIdentityFactory(now_submission=now_submission)
        get_resp = test_client.get(
            f'/now-submissions/applications/{identity.now_number}/status',
            headers=auth_headers['full_auth_header'])
        assert get_resp.status_code == 200, get_resp.response

        get_data = json.loads(get_resp.data.decode())
        assert get_data['now_application_status_code'] is not None
        assert get_data[
            'now_application_status_code'] == identity.now_application.now_application_status_code
    def test_get_now_application_status_updates_since_success(
            self, test_client, db_session, auth_headers):
        """Should return the correct records with a 200 response code"""
        today = datetime.datetime.today()
        status_updated_date = today
        identities = []
        for i in range(3):
            now_submission = NOWSubmissionFactory()
            identity = NOWApplicationIdentityFactory(
                now_submission=now_submission)
            identity.now_application.status_updated_date = status_updated_date
            status_updated_date = status_updated_date + datetime.timedelta(
                days=+1)
            identity.save()
            identities.append(identity)

        get_resp = test_client.get(
            f'/now-submissions/applications/status?status_updated_date_since={today}',
            headers=auth_headers['full_auth_header'])
        assert get_resp.status_code == 200, get_resp.response
        get_data = json.loads(get_resp.data.decode())
        assert len(get_data) == 3

        status_updated_date = today
        for identity in identities:
            identity.now_application.status_updated_date = status_updated_date
            status_updated_date = status_updated_date + datetime.timedelta(
                days=-1)
            identity.save()

        get_resp = test_client.get(
            f'/now-submissions/applications/status?status_updated_date_since={today}',
            headers=auth_headers['full_auth_header'])
        assert get_resp.status_code == 200, get_resp.response
        get_data = json.loads(get_resp.data.decode())
        assert len(get_data) == 1

        get_resp = test_client.get(
            f'/now-submissions/applications/status?status_updated_date_since={today + datetime.timedelta(days=+42)}',
            headers=auth_headers['full_auth_header'])
        assert get_resp.status_code == 200, get_resp.response
        get_data = json.loads(get_resp.data.decode())
        assert len(get_data) == 0