Exemple #1
0
def report(context, case_id, report_path, update):
    """Add delivery report to an existing case."""
    adapter = context.obj['adapter']
    try:
        updated_case = load_report(adapter, case_id, report_path, update)
    except IntegrityError as err:
        LOG.warning(err)
        context.abort()
    except ValidationError as err:
        LOG.warning(err)
        LOG.info("Use flag --update if it should be overwritten")
        context.abort()
Exemple #2
0
def test_load_report_non_existing_case(adapter):
    ## GIVEN a database with a case without case report
    case_id = 'test_case'
    case = {'_id':case_id}
    
    adapter._add_case(case)
    
    case_obj = adapter.case_collection.find_one()
    
    delivery_path = 'here'
    
    assert 'delivery_report' not in case_obj
    
    ## WHEN trying to load a delivery report in a non existing case
    with pytest.raises(IntegrityError):
        ## THEN assert an integrity error is raised
        updated_case = load_report(adapter, 'non existing case', delivery_path)
Exemple #3
0
def test_load_report(adapter):
    ## GIVEN a database with a case without case report
    case_id = 'test_case'
    case = {'_id':case_id}
    
    adapter._add_case(case)
    
    case_obj = adapter.case_collection.find_one()
    
    delivery_path = 'here'
    
    assert 'delivery_report' not in case_obj
    
    ## WHEN loading a delivery report
    updated_case = load_report(adapter, case_id, delivery_path)
    
    ## THEN assert the report is there
    
    assert updated_case['delivery_report'] == delivery_path
Exemple #4
0
def test_load_report_existing_report(adapter):
    ## GIVEN a database with a case with case report
    case_id = 'test_case'
    delivery_path = 'here'
    
    case = {
        '_id':case_id,
        'delivery_report': delivery_path
    }
    
    adapter._add_case(case)
    
    case_obj = adapter.case_collection.find_one()
    
    assert 'delivery_report' in case_obj

    other_report = 'there'
    
    ## WHEN trying to load a delivery report in a case that already have a report
    with pytest.raises(ValidationError):
        ## THEN assert an validation error is raised
        updated_case = load_report(adapter, case_id, other_report)