示例#1
0
    def test_get_application_list_pagination(self, test_client, db_session, auth_headers):
        """Should return paginated records"""

        batch_size = PER_PAGE_DEFAULT + 1
        NOWApplicationFactory.create_batch(size=batch_size)

        get_resp = test_client.get('/now-submissions/applications', headers=auth_headers['full_auth_header'])
        get_data = json.loads(get_resp.data.decode())

        assert get_resp.status_code == 200
        assert len(get_data['records']) == PER_PAGE_DEFAULT
        assert get_data['current_page'] == PAGE_DEFAULT
        assert get_data['total'] == batch_size
示例#2
0
    def test_get_now_application_list_filter_by_trackingnumber(self, test_client, db_session, auth_headers):
        """Should return the records filtered by trackingnumber"""

        application_1 = NOWApplicationFactory(trackingnumber=1)
        application_2 = NOWApplicationFactory(trackingnumber=1)
        application_3 = NOWApplicationFactory(trackingnumber=12)
        application_4 = NOWApplicationFactory(trackingnumber=10305)

        get_resp = test_client.get(f'now-submissions/applications?trackingnumber=1',
                                   headers=auth_headers['full_auth_header'])
        get_data = json.loads(get_resp.data.decode())

        assert get_resp.status_code == 200
        assert len(get_data['records']) == 2
        assert all(
            str(application.application_guid) in map(lambda x: x['application_guid'], get_data['records'])
            for application in [application_1, application_2])
        assert all(
            str(application.application_guid) not in map(lambda x: x['application_guid'], get_data['records'])
            for application in [application_3, application_4])
示例#3
0
    def test_get_now_application_list_filter_by_noticeofworktype(self, test_client, db_session, auth_headers):
        """Should return the records filtered by noticeofworktype"""

        application_1 = NOWApplicationFactory(noticeofworktype='dog')
        application_2 = NOWApplicationFactory(noticeofworktype='dog')
        application_3 = NOWApplicationFactory(noticeofworktype='cat')
        application_4 = NOWApplicationFactory(noticeofworktype='parrot')

        get_resp = test_client.get(f'now-submissions/applications?noticeofworktype=dog',
                                   headers=auth_headers['full_auth_header'])
        get_data = json.loads(get_resp.data.decode())

        assert get_resp.status_code == 200
        assert len(get_data['records']) == 2
        assert all(
            str(application.application_guid) in map(lambda x: x['application_guid'], get_data['records'])
            for application in [application_1, application_2])
        assert all(
            str(application.application_guid) not in map(lambda x: x['application_guid'], get_data['records'])
            for application in [application_3, application_4])
示例#4
0
    def test_get_now_application_list_filter_by_status(self, test_client, db_session, auth_headers):
        """Should return the records filtered by status"""

        application_1 = NOWApplicationFactory(status='Approved')
        application_2 = NOWApplicationFactory(status='Received')
        application_3 = NOWApplicationFactory(status='Rejected')
        application_4 = NOWApplicationFactory(status='Rejected')

        get_resp = test_client.get(f'now-submissions/applications?status=app,rec',
                                   headers=auth_headers['full_auth_header'])
        get_data = json.loads(get_resp.data.decode())

        assert get_resp.status_code == 200
        assert len(get_data['records']) == 2
        assert all(
            str(application.application_guid) in map(lambda x: x['application_guid'], get_data['records'])
            for application in [application_1, application_2])
        assert all(
            str(application.application_guid) not in map(lambda x: x['application_guid'], get_data['records'])
            for application in [application_3, application_4])
示例#5
0
    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"""

        application_1 = NOWApplicationFactory(status='Rejected', noticeofworktype='dog', trackingnumber=1)
        application_2 = NOWApplicationFactory(status='Received', noticeofworktype='cat', trackingnumber=1)
        application_3 = NOWApplicationFactory(status='Rejected', noticeofworktype='dog', trackingnumber=12)
        application_4 = NOWApplicationFactory(status='Approved', noticeofworktype='cat', trackingnumber=10305)

        get_resp = test_client.get(
            f'now-submissions/applications?status=app,rej&noticeofworktype=dog&trackingnumber=1',
            headers=auth_headers['full_auth_header'])
        get_data = json.loads(get_resp.data.decode())

        assert get_resp.status_code == 200
        assert len(get_data['records']) == 1
        assert all(
            str(application.application_guid) in map(lambda x: x['application_guid'], get_data['records'])
            for application in [application_1])
        assert all(
            str(application.application_guid) not in map(lambda x: x['application_guid'], get_data['records'])
            for application in [application_2, application_3, application_4])
示例#6
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 = NOWApplicationFactory.create_batch(size=batch_size)
        mine = MineFactory(minimal=True)
        application_1 = NOWApplicationFactory(mine=mine)
        application_2 = NOWApplicationFactory(mine=mine)

        get_resp = test_client.get(f'mines/{mine.mine_guid}/now-submissions/applications',
                                   headers=auth_headers['full_auth_header'])
        get_data = json.loads(get_resp.data.decode())

        assert get_resp.status_code == 200
        assert len(get_data['records']) == 2
        assert all(
            str(application.application_guid) not in map(lambda x: x['application_guid'], get_data['records'])
            for application in other_applications)
        assert all(
            str(application.application_guid) in map(lambda x: x['application_guid'], get_data['records'])
            for application in [application_1, application_2])
示例#7
0
    def test_get_now_application_by_guid_success(self, test_client, db_session,
                                                 auth_headers):
        """Should return the correct records with a 200 response code"""

        application = NOWApplicationFactory()
        get_resp = test_client.get(
            f'/now-submissions/applications/{application.application_guid}',
            headers=auth_headers['full_auth_header'])
        get_data = json.loads(get_resp.data.decode())
        assert get_resp.status_code == 200
        assert get_data['application_guid'] is not None
        assert get_data['application_guid'] == str(
            application.application_guid)
示例#8
0
    def test_get_now_application_by_guid_documents(self, test_client,
                                                   db_session, auth_headers):
        """Should include the correct documents"""

        application = NOWApplicationFactory()
        get_resp = test_client.get(
            f'/now-submissions/applications/{application.application_guid}',
            headers=auth_headers['full_auth_header'])
        get_data = json.loads(get_resp.data.decode())
        assert get_resp.status_code == 200
        assert get_data['documents'][0]['filename'] is not None
        assert get_data['documents'][0]['filename'] in list(
            map(lambda x: x.filename, application.documents))
示例#9
0
    def test_get_now_application_by_guid_submitter(self, test_client,
                                                   db_session, auth_headers):
        """Should include the correct submitter"""

        submitter = NOWClientFactory()
        application = NOWApplicationFactory(submitter=submitter)
        get_resp = test_client.get(
            f'/now-submissions/applications/{application.application_guid}',
            headers=auth_headers['full_auth_header'])
        get_data = json.loads(get_resp.data.decode())
        assert get_resp.status_code == 200
        assert get_data['submitter']['type'] is not None
        assert get_data['submitter']['type'] == submitter.type
示例#10
0
    def test_get_now_application_by_guid_mine_name(self, test_client,
                                                   db_session, auth_headers):
        """Should include the correct mine name"""

        mine = MineFactory()
        application = NOWApplicationFactory(mine=mine)
        get_resp = test_client.get(
            f'/now-submissions/applications/{application.application_guid}',
            headers=auth_headers['full_auth_header'])
        get_data = json.loads(get_resp.data.decode())
        assert get_resp.status_code == 200
        assert get_data['mine_name'] is not None
        assert get_data['mine_name'] == mine.mine_name
示例#11
0
    def test_get_now_application_by_guid_proposed_settling_pond(
            self, test_client, db_session, auth_headers):
        """Should include the correct proposed_settling_pond"""

        application = NOWApplicationFactory()
        get_resp = test_client.get(
            f'/now-submissions/applications/{application.application_guid}',
            headers=auth_headers['full_auth_header'])
        get_data = json.loads(get_resp.data.decode())
        assert get_resp.status_code == 200
        assert get_data['proposed_settling_pond'][0]['pondid'] is not None
        assert get_data['proposed_settling_pond'][0]['pondid'] in list(
            map(lambda x: x.pondid, application.proposed_settling_pond))
    def test_get_now_application_review_success(self, test_client, db_session,
                                                auth_headers):
        now_application = NOWApplicationFactory()
        now_application_identity = NOWApplicationIdentityFactory(
            now_application=now_application)

        post_resp = test_client.get(
            f'/now-applications/{now_application_identity.now_application_guid}/reviews',
            headers=auth_headers['full_auth_header'])
        assert post_resp.status_code == 200, post_resp.response
        post_data = json.loads(post_resp.data.decode())
        assert len(post_data['records']) > 0
        assert 'response_date' in post_data['records'][0]
示例#13
0
    def test_get_now_application_by_guid_existing_placer_activity(
            self, test_client, db_session, auth_headers):
        """Should include the correct existing_placer_activity"""

        application = NOWApplicationFactory()
        get_resp = test_client.get(
            f'/now-submissions/applications/{application.application_guid}',
            headers=auth_headers['full_auth_header'])
        get_data = json.loads(get_resp.data.decode())
        assert get_resp.status_code == 200
        assert get_data['existing_placer_activity'][0]['type'] is not None
        assert get_data['existing_placer_activity'][0]['type'] in list(
            map(lambda x: x.type, application.existing_placer_activity))
示例#14
0
    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')
        application_1 = NOWApplicationFactory(mine=mine)
        application_2 = NOWApplicationFactory(mine=mine)
        application_3 = NOWApplicationFactory(mine=mine2)
        application_4 = NOWApplicationFactory(mine=mine2)

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

        assert get_resp.status_code == 200
        assert len(get_data['records']) == 2
        assert all(
            str(application.application_guid) in map(lambda x: x['application_guid'], get_data['records'])
            for application in [application_1, application_2])
        assert all(
            str(application.application_guid) not in map(lambda x: x['application_guid'], get_data['records'])
            for application in [application_3, application_4])
示例#15
0
    def test_get_now_application_list_success(self, test_client, db_session, auth_headers):
        """Should return the correct records with a 200 response code"""

        batch_size = 5
        applications = NOWApplicationFactory.create_batch(size=batch_size)

        get_resp = test_client.get('/now-submissions/applications', headers=auth_headers['full_auth_header'])
        get_data = json.loads(get_resp.data.decode())

        assert get_resp.status_code == 200
        assert len(get_data['records']) == batch_size
        assert get_data['total'] == batch_size
        assert all(
            str(application.application_guid) in map(lambda x: x['application_guid'], get_data['records'])
            for application in applications)
示例#16
0
 def test_post_now_application_progress_success(self, test_client,
                                                db_session, auth_headers):
     now_application = NOWApplicationFactory(application_progress=None)
     now_application_identity = NOWApplicationIdentityFactory(
         now_application=now_application)
     test_progress_data = {
         'application_progress_status_code': 'REV',
     }
     post_resp = test_client.post(
         f'/now-applications/{now_application_identity.now_application_guid}/progress',
         json=test_progress_data,
         headers=auth_headers['full_auth_header'])
     assert post_resp.status_code == 201, post_resp.response
     post_data = json.loads(post_resp.data.decode())
     assert post_data[
         'application_progress_status_code'] == test_progress_data[
             'application_progress_status_code']
    def test_post_now_application_review_success(self, test_client, db_session,
                                                 auth_headers):
        now_application = NOWApplicationFactory()
        now_application_identity = NOWApplicationIdentityFactory(
            now_application=now_application)

        test_progress_data = {
            'now_application_review_type_code': 'REF',
            'referee_name': 'Fred',
        }
        post_resp = test_client.post(
            f'/now-applications/{now_application_identity.now_application_guid}/reviews',
            json=test_progress_data,
            headers=auth_headers['full_auth_header'])
        assert post_resp.status_code == 201, post_resp.response
        post_data = json.loads(post_resp.data.decode())
        assert post_data[
            'now_application_review_type_code'] == test_progress_data[
                'now_application_review_type_code']
示例#18
0
文件: commands.py 项目: kulpree/mds
 def _create_data(num):
     User._test_mode = True
     with app.app_context():
         for _ in range(int(num)):
             mine = MineFactory()
             eor = MinePartyAppointmentFactory(
                 mine=mine, mine_party_appt_type_code='EOR')
             mine_manager = MinePartyAppointmentFactory(
                 mine=mine, mine_party_appt_type_code='MMG')
             permitee = MinePartyAppointmentFactory(
                 mine=mine,
                 mine_party_appt_type_code='PMT',
                 party__company=True)
             NOWApplicationFactory(mine=mine)
         try:
             db.session.commit()
             print(f'Created {num} random mines with related data.')
         except DBAPIError:
             db.session.rollback()
             raise
示例#19
0
    def test_post_now_application_progress_duplicate_type(
            self, test_client, db_session, auth_headers):
        mine = MineFactory(major_mine_ind=True)
        now_application = NOWApplicationFactory(application_progress=None)
        now_application_identity = NOWApplicationIdentityFactory(
            now_application=now_application, mine=mine)
        test_progress_data = {
            'application_progress_status_code': 'REV',
        }
        post_resp = test_client.post(
            f'/now-applications/{now_application_identity.now_application_guid}/progress',
            json=test_progress_data,
            headers=auth_headers['full_auth_header'])
        assert post_resp.status_code == 201, post_resp.response

        post_resp = test_client.post(
            f'/now-applications/{now_application_identity.now_application_guid}/progress',
            json=test_progress_data,
            headers=auth_headers['full_auth_header'])
        assert post_resp.status_code == 400, post_resp.response