def test_narratives(database, job_constants, monkeypatch):
    """Verify that we can add, retrieve, and update submission narratives. Not
    quite a unit test as it covers a few functions in sequence"""
    monkeypatch.setattr(fileHandler, 'user_agency_matches',
                        Mock(return_value=True))
    sub1, sub2 = SubmissionFactory(), SubmissionFactory()
    database.session.add_all([sub1, sub2])
    database.session.commit()

    # Write some narratives
    result = fileHandler.update_narratives(sub1.submission_id, {
        'B': 'BBBBBB',
        'E': 'EEEEEE'
    })
    assert result.status_code == 200
    result = fileHandler.update_narratives(sub2.submission_id,
                                           {'A': 'Submission2'})
    assert result.status_code == 200

    # Check the narratives
    result = fileHandler.narratives_for_submission(sub1.submission_id)
    result = json.loads(result.get_data().decode('UTF-8'))
    assert result == {
        'A': '',
        'B': 'BBBBBB',
        'C': '',
        'D1': '',
        'D2': '',
        'E': 'EEEEEE',
        'F': ''
    }

    # Replace the narratives
    result = fileHandler.update_narratives(sub1.submission_id, {
        'A': 'AAAAAA',
        'E': 'E2E2E2'
    })
    assert result.status_code == 200

    # Verify the change worked
    result = fileHandler.narratives_for_submission(sub1.submission_id)
    result = json.loads(result.get_data().decode('UTF-8'))
    assert result == {
        'A': 'AAAAAA',
        'B': '',
        'C': '',
        'D1': '',
        'D2': '',
        'E': 'E2E2E2',
        'F': ''
    }
def test_narratives(database):
    """Verify that we can add, retrieve, and update submission narratives. Not
    quite a unit test as it covers a few functions in sequence"""
    sub1, sub2 = SubmissionFactory(), SubmissionFactory()
    database.session.add_all([sub1, sub2])
    database.session.commit()

    # Write some narratives
    result = fileHandler.update_narratives(sub1, {
        'B': 'BBBBBB',
        'E': 'EEEEEE'
    })
    assert result.status_code == 200
    result = fileHandler.update_narratives(sub2, {'A': 'Submission2'})
    assert result.status_code == 200

    # Check the narratives
    result = fileHandler.narratives_for_submission(sub1)
    result = json.loads(result.get_data().decode('UTF-8'))
    assert result == {
        'A': '',
        'B': 'BBBBBB',
        'C': '',
        'D1': '',
        'D2': '',
        'E': 'EEEEEE',
        'F': '',
        'FABS': ''
    }

    # Replace the narratives
    result = fileHandler.update_narratives(sub1, {
        'A': 'AAAAAA',
        'E': 'E2E2E2'
    })
    assert result.status_code == 200

    # Verify the change worked
    result = fileHandler.narratives_for_submission(sub1)
    result = json.loads(result.get_data().decode('UTF-8'))
    assert result == {
        'A': 'AAAAAA',
        'B': '',
        'C': '',
        'D1': '',
        'D2': '',
        'E': 'E2E2E2',
        'F': '',
        'FABS': ''
    }
Exemple #3
0
 def post_submission_narratives(submission_id):
     json = request.json or {}
     # clean input
     json = {
         key.upper(): value.strip()
         for key, value in json.items()
         if isinstance(value, str) and value.strip()
     }
     return update_narratives(int(submission_id), json)
def test_narratives(database, job_constants):
    """Verify that we can add, retrieve, and update submission narratives. Not
    quite a unit test as it covers a few functions in sequence"""
    sub1, sub2 = SubmissionFactory(), SubmissionFactory()
    database.session.add_all([sub1, sub2])
    database.session.commit()

    # Write some narratives
    result = fileHandler.update_narratives(sub1, {'B': 'BBBBBB', 'E': 'EEEEEE'})
    assert result.status_code == 200
    result = fileHandler.update_narratives(sub2, {'A': 'Submission2'})
    assert result.status_code == 200

    # Check the narratives
    result = fileHandler.narratives_for_submission(sub1)
    result = json.loads(result.get_data().decode('UTF-8'))
    assert result == {
        'A': '',
        'B': 'BBBBBB',
        'C': '',
        'D1': '',
        'D2': '',
        'E': 'EEEEEE',
        'F': '',
        'D2_detached': ''
    }

    # Replace the narratives
    result = fileHandler.update_narratives(sub1, {'A': 'AAAAAA', 'E': 'E2E2E2'})
    assert result.status_code == 200

    # Verify the change worked
    result = fileHandler.narratives_for_submission(sub1)
    result = json.loads(result.get_data().decode('UTF-8'))
    assert result == {
        'A': 'AAAAAA',
        'B': '',
        'C': '',
        'D1': '',
        'D2': '',
        'E': 'E2E2E2',
        'F': '',
        'D2_detached': ''
    }
Exemple #5
0
 def post_submission_narratives(submission):
     return update_narratives(submission, request.json)
 def post_submission_narratives(submission):
     json = request.json or {}
     # clean input
     json = {key.upper(): value.strip() for key, value in json.items()
             if isinstance(value, str) and value.strip()}
     return update_narratives(submission, json)
 def post_submission_narratives(submission):
     return update_narratives(submission, request.json)