コード例 #1
0
def test_get_all_filing_comments_only_one(session, client, jwt):
    """Assert that a list of comments with a single comment is returned correctly."""
    identifier = 'CP7654321'
    b = factory_business(identifier)
    f = factory_filing(b, ANNUAL_REPORT)
    factory_comment(b, f)

    rv = client.get(f'/api/v1/businesses/{identifier}/filings/{f.id}/comments',
                    headers=create_header(jwt, [STAFF_ROLE]))

    assert HTTPStatus.OK == rv.status_code
    assert 1 == len(rv.json.get('comments'))
コード例 #2
0
def test_get_all_business_filings_multiple(session, client, jwt):
    """Assert that multiple filings are returned correctly."""
    identifier = 'CP7654321'
    b = factory_business(identifier)
    f = factory_filing(b, ANNUAL_REPORT)
    factory_comment(b, f)
    factory_comment(b, f, 'other text')

    rv = client.get(f'/api/v1/businesses/{identifier}/filings/{f.id}/comments',
                    headers=create_header(jwt, [STAFF_ROLE]))

    assert HTTPStatus.OK == rv.status_code
    assert 2 == len(rv.json.get('comments'))
コード例 #3
0
def test_comments_in_filing_response(session, client, jwt):
    """Assert that the list of comments is the filing GET response."""
    b = factory_business('CP1111111')
    f = factory_filing(b, ANNUAL_REPORT)
    factory_comment(b, f, 'comment 1')
    factory_comment(b, f, 'comment 2')

    rv = client.get(f'/api/v1/businesses/{b.identifier}/filings/{f.id}',
                    headers=create_header(jwt, [STAFF_ROLE]))

    assert rv.status_code == HTTPStatus.OK
    assert None is not rv.json['filing']['header'].get('comments')
    assert 2 == len(rv.json['filing']['header'].get('comments'))
コード例 #4
0
def test_comment_json_output(session, client, jwt):
    """Assert the json output of a comment is correctly formatted."""
    identifier = 'CP7654321'
    b = factory_business(identifier)
    f = factory_filing(b, ANNUAL_REPORT)
    u = User(username='******',
             firstname='firstname',
             lastname='lastname',
             sub='sub',
             iss='iss')
    u.save()
    c = factory_comment(b, f, 'some specific text', u)

    system_timezone = datetime.datetime.now().astimezone().tzinfo
    expected_timestamp = \
        datetime.datetime(1970, 1, 1, 0, 0).replace(tzinfo=datetime.timezone.utc).astimezone(tz=system_timezone)

    rv = client.get(
        f'/api/v1/businesses/{identifier}/filings/{f.id}/comments/{c.id}',
        headers=create_header(jwt, [STAFF_ROLE]))

    assert HTTPStatus.OK == rv.status_code
    assert 'some specific text' == rv.json.get('comment').get('comment')
    assert 'firstname lastname' == rv.json.get('comment').get(
        'submitterDisplayName')
    assert expected_timestamp.isoformat() == rv.json.get('comment').get(
        'timestamp')
コード例 #5
0
def test_comment_delete_is_blocked(session):
    """Assert that an AR filing can be saved."""
    c = factory_comment()

    with pytest.raises(BusinessException) as excinfo:
        c.delete()

    assert excinfo.value.status_code == HTTPStatus.FORBIDDEN
    assert excinfo.value.error == 'Deletion not allowed.'
コード例 #6
0
def test_delete_comment_error(session, client, jwt):
    """Assert that the DELETE endpoint isn't allowed."""
    b = factory_business('CP1111111')
    f = factory_filing(b, ANNUAL_REPORT)
    c = factory_comment(b, f)

    rv = client.delete(f'/api/v2/businesses/{b.identifier}/filings/{f.id}/comments/{c.id}',
                       headers=create_header(jwt, [STAFF_ROLE]))

    assert HTTPStatus.METHOD_NOT_ALLOWED == rv.status_code
コード例 #7
0
def test_comment_block_orm_delete(session):
    """Assert that attempting to delete a filing will raise a BusinessException."""
    from legal_api.exceptions import BusinessException

    c = factory_comment()

    with pytest.raises(BusinessException) as excinfo:
        session.delete(c)
        session.commit()

    assert excinfo.value.status_code == HTTPStatus.FORBIDDEN
    assert excinfo.value.error == 'Deletion not allowed.'
コード例 #8
0
def test_get_one_filing_comment_by_id(session, client, jwt):
    """Assert that a single comment is returned correctly."""
    identifier = 'CP7654321'
    b = factory_business(identifier)
    f = factory_filing(b, ANNUAL_REPORT)
    c = factory_comment(b, f, 'some specific text')

    rv = client.get(f'/api/v2/businesses/{identifier}/filings/{f.id}/comments/{c.id}',
                    headers=create_header(jwt, [STAFF_ROLE]))

    assert HTTPStatus.OK == rv.status_code
    assert 'some specific text' == rv.json.get('comment').get('comment')
コード例 #9
0
def test_put_comment_error(session, client, jwt):
    """Assert that the PUT endpoint isn't allowed."""
    b = factory_business('CP1111111')
    f = factory_filing(b, ANNUAL_REPORT)
    c = factory_comment(b, f)

    json_data = copy.deepcopy(SAMPLE_JSON_DATA)
    json_data['comment']['id'] = c.id
    json_data['comment']['filingId'] = f.id

    rv = client.put(
        f'/api/v1/businesses/{b.identifier}/filings/{f.id}/comments/{c.id}',
        json=json_data,
        headers=create_header(jwt, [STAFF_ROLE]))

    assert HTTPStatus.METHOD_NOT_ALLOWED == rv.status_code
コード例 #10
0
def test_filing_comment_dump_json(session):
    """Assert the comment json serialization works correctly."""
    identifier = 'CP7654321'
    b = factory_business(identifier)
    f = factory_filing(b, ANNUAL_REPORT)
    c = factory_comment(b, f, 'a comment')

    now = datetime.datetime(1970, 1, 1, 0,
                            0).replace(tzinfo=datetime.timezone.utc)
    with freeze_time(now):
        assert c.json == {
            'comment': {
                'id': c.id,
                'submitterDisplayName': None,
                'comment': 'a comment',
                'filingId': f.id,
                'businessId': None,
                'timestamp': now.isoformat()
            }
        }