Beispiel #1
0
    def put(self, mine_guid, variance_guid):
        variance = Variance.find_by_mine_guid_and_variance_guid(
            mine_guid, variance_guid)
        if variance is None:
            raise NotFound('Unable to fetch variance')

        data = self.parser.parse_args()

        inspector_party_guid = data.get('inspector_party_guid')
        if inspector_party_guid:
            inspector = Party.find_by_party_guid(inspector_party_guid)
            if not inspector:
                raise BadRequest('Unable to find new inspector.')
            if not 'INS' in inspector.business_roles_codes:
                raise BadRequest('Party is not an inspector.')

            variance.inspector_party_guid = inspector_party_guid

        for key, value in data.items():
            if key in ['inspector_party_guid']:
                continue
            setattr(variance, key, value)

        # A manual check to prevent a stack trace dump on a foreign key /
        # constraint error because global error handling doesn't currently work
        # with these errors
        Variance.validate_status_with_other_values(
            status=variance.variance_application_status_code,
            issue=variance.issue_date,
            expiry=variance.expiry_date,
            inspector=variance.inspector_party_guid)

        variance.save()
        return variance
Beispiel #2
0
def test_variance_model_find_by_mine_guid_and_variance_guid(db_session):
    variance = VarianceFactory()

    fetched_variance = Variance.find_by_mine_guid_and_variance_guid(
        variance.mine_guid, variance.variance_guid)
    assert fetched_variance.mine_guid == variance.mine_guid
    assert fetched_variance.variance_guid == variance.variance_guid
Beispiel #3
0
def test_validate_applicant_guid_invalid(db_session):
    variance = VarianceFactory()
    with pytest.raises(AssertionError) as e:
        Variance(compliance_article_id=variance.compliance_article_id,
                 mine_guid=variance.mine_guid,
                 applicant_guid='abc123')
    assert 'Invalid applicant_guid' in str(e.value)
Beispiel #4
0
    def put(self, mine_guid, variance_guid):
        parser = CustomReqparser()
        # Arguments required by MineDocument
        parser.add_argument('document_name', type=str, required=True)
        parser.add_argument('document_manager_guid', type=str, required=True)
        parser.add_argument('variance_document_category_code', type=str, required=True)

        variance = Variance.find_by_variance_guid(variance_guid)

        if not variance:
            raise NotFound('Unable to fetch variance.')

        data = parser.parse_args()
        document_name = data.get('document_name')
        document_manager_guid = data.get('document_manager_guid')

        # Register new file upload
        mine_doc = MineDocument(mine_guid=mine_guid,
                                document_manager_guid=document_manager_guid,
                                document_name=document_name)

        if not mine_doc:
            raise BadRequest('Unable to register uploaded file as document')

        # Associate Variance & MineDocument to create Variance Document
        # Add fields specific to Variance Documents
        mine_doc.save()
        variance_doc = VarianceDocumentXref(
            mine_document_guid=mine_doc.mine_document_guid,
            variance_id=variance.variance_id,
            variance_document_category_code=data.get('variance_document_category_code'))

        variance.documents.append(variance_doc)
        variance.save()
        return variance
Beispiel #5
0
 def delete(self, mine_guid, variance_guid):
     variance = Variance.find_by_mine_guid_and_variance_guid(
         mine_guid, variance_guid)
     if variance is None:
         raise NotFound('Mine variance not found')
     variance.soft_delete()
     return None, 204
    def put(self, mine_guid, variance_guid):
        parser = CustomReqparser()
        # Arguments required by MineDocument
        parser.add_argument('document_name', type=str, required=True)
        parser.add_argument('document_manager_guid', type=str, required=True)

        variance = Variance.find_by_variance_guid(variance_guid)

        if not variance:
            raise NotFound('Unable to fetch variance.')

        data = parser.parse_args()
        document_name = data.get('document_name')
        document_manager_guid = data.get('document_manager_guid')

        # Register new file upload
        mine_doc = MineDocument(mine_guid=mine_guid,
                                document_manager_guid=document_manager_guid,
                                document_name=document_name)

        if not mine_doc:
            raise BadRequest('Unable to register uploaded file as document')

        variance.mine_documents.append(mine_doc)
        variance.save()
        return variance
Beispiel #7
0
    def get(self, mine_guid, variance_guid):
        variance = Variance.find_by_mine_guid_and_variance_guid(
            mine_guid, variance_guid)

        if variance is None:
            raise NotFound('Unable to fetch variance')

        return variance
Beispiel #8
0
    def post(self, mine_guid):
        data = self.parser.parse_args()
        compliance_article_id = data['compliance_article_id']
        received_date = data['received_date']
        inspector_party_guid = data.get('inspector_party_guid')

        mine = Mine.find_by_mine_guid(mine_guid)
        if mine is None:
            raise NotFound('Mine')

        # A manual check to prevent a stack trace dump on a foreign key /
        # constraint error because global error handling doesn't currently work
        # with these errors
        variance_application_status_code = data.get(
            'variance_application_status_code') or 'REV'
        issue_date = data.get('issue_date')
        expiry_date = data.get('expiry_date')
        Variance.validate_status_with_other_values(
            status=variance_application_status_code,
            issue=issue_date,
            expiry=expiry_date,
            inspector=inspector_party_guid)

        variance = Variance.create(
            compliance_article_id=compliance_article_id,
            mine_guid=mine_guid,
            received_date=received_date,
            # Optional fields
            variance_application_status_code=variance_application_status_code,
            applicant_guid=data.get('applicant_guid'),
            inspector_party_guid=inspector_party_guid,
            note=data.get('note'),
            parties_notified_ind=data.get('parties_notified_ind'),
            issue_date=issue_date,
            expiry_date=expiry_date)

        if not variance:
            raise BadRequest('Error: Failed to create variance')

        variance.save()
        return variance
Beispiel #9
0
    def get(self, mine_guid):
        variances = Variance.find_by_mine_guid(mine_guid)

        if variances is None:
            raise BadRequest(
                'Unable to fetch variances. Confirm you\'ve provided a valid mine_guid')

        if len(variances) == 0:
            mine = Mine.find_by_mine_guid(mine_guid)
            if mine is None:
                raise NotFound('Mine')

        return variances
    def delete(self, mine_guid, variance_guid, mine_document_guid):
        variance = Variance.find_by_mine_guid_and_variance_guid(
            mine_guid, variance_guid)
        mine_document = MineDocument.find_by_mine_document_guid(
            mine_document_guid)

        if variance is None:
            raise NotFound('Variance not found.')
        if mine_document is None:
            raise NotFound('Mine document not found.')
        if mine_document not in variance.mine_documents:
            raise NotFound('Mine document not found on variance.')

        variance.mine_documents.remove(mine_document)
        variance.save()

        return ('', 204)
Beispiel #11
0
def test_variance_model_find_by_mine_guid(db_session):
    init_mine_guid = VarianceFactory().mine_guid

    variances = Variance.find_by_mine_guid(init_mine_guid)
    assert variances[0].mine_guid == init_mine_guid
Beispiel #12
0
def test_variance_model_find_by_variance_id_fail(db_session):
    variance = Variance.find_by_variance_id(42)
    assert variance is None
Beispiel #13
0
def test_validate_mine_guid_missing(db_session):
    with pytest.raises(AssertionError) as e:
        Variance(compliance_article_id=RandomComplianceArticleId,
                 mine_guid=None)
    assert str(e.value) == MISSING_MINE_GUID
Beispiel #14
0
def test_validate_mine_guid_invalid(db_session):
    with pytest.raises(AssertionError) as e:
        Variance(compliance_article_id=RandomComplianceArticleId,
                 mine_guid='abc123')
    assert str(e.value) == INVALID_MINE_GUID
Beispiel #15
0
def test_variance_model_find_by_mine_guid_and_variance_guid_fail(db_session):
    mine = MineFactory()
    with pytest.raises(AssertionError) as e:
        Variance.find_by_mine_guid_and_variance_guid(mine.mine_guid, 42)
    assert str(e.value) == INVALID_VARIANCE_GUID
Beispiel #16
0
def test_variance_model_find_by_mine_guid_invalid(db_session):
    with pytest.raises(AssertionError) as e:
        variances = Variance.find_by_mine_guid('jflkjfsdl')
    assert str(e.value) == INVALID_MINE_GUID
Beispiel #17
0
def test_variance_model_find_by_variance_guid_invalid(db_session):
    with pytest.raises(AssertionError) as e:
        Variance.find_by_variance_guid('abc123')
    assert str(e.value) == INVALID_VARIANCE_GUID
Beispiel #18
0
def test_variance_model_find_by_variance_guid_fail(db_session):
    variance = Variance.find_by_variance_guid(uuid.uuid4())
    assert variance is None
Beispiel #19
0
def test_variance_model_find_by_variance_guid(db_session):
    init_variance_guid = VarianceFactory().variance_guid

    variance = Variance.find_by_variance_guid(init_variance_guid)
    assert variance.variance_guid == init_variance_guid