def test_documents_returns_200_for_some_type(client, jwt, session):  # pylint:disable=unused-argument
    """Assert authorizations for affiliated users returns 200."""
    html_content = '<HTML></HTML>'
    version_id = 10
    factory_document_model(version_id, 'sometype', html_content)

    rv = client.get(f'/api/v1/documents/sometype', content_type='application/json')

    assert rv.status_code == http_status.HTTP_200_OK
    assert rv.json.get('content') == html_content
    assert rv.json.get('version_id') == version_id
Exemplo n.º 2
0
def test_documents_returns_200_for_some_type(client, jwt, session):  # pylint:disable=unused-argument
    """Assert get documents endpoint with different type returns 200."""
    html_content = '<HTML></HTML>'
    version_id = '10'
    factory_document_model(version_id, 'sometype', html_content)

    headers = factory_auth_header(jwt=jwt, claims=TestJwtClaims.public_user_role)
    rv = client.get('/api/v1/documents/sometype', headers=headers, content_type='application/json')

    assert rv.status_code == http_status.HTTP_200_OK
    assert schema_utils.validate(rv.json, 'document')[0]
    assert rv.json.get('content') == html_content
    assert rv.json.get('versionId') == version_id
Exemplo n.º 3
0
def test_documents_returns_latest_always(client, jwt, session):  # pylint:disable=unused-argument
    """Assert get documents endpoint returns latest version of document."""
    html_content_1 = '<HTML>1</HTML>'
    version_id_1 = '20'  # putting higher numbers so that version number doesnt collide with existing in db
    factory_document_model(version_id_1, 'termsofuse', html_content_1)

    html_content_2 = '<HTML>3</HTML>'
    version_id_2 = '41'  # putting higher numbers so that version number doesnt collide with existing in db
    factory_document_model(version_id_2, 'termsofuse', html_content_2)

    headers = factory_auth_header(jwt=jwt, claims=TestJwtClaims.public_user_role)
    rv = client.get('/api/v1/documents/termsofuse', headers=headers, content_type='application/json')

    assert rv.status_code == http_status.HTTP_200_OK
    assert schema_utils.validate(rv.json, 'document')[0]
    assert rv.json.get('content') == html_content_2
    assert rv.json.get('versionId') == version_id_2

    version_id_3 = 'd30'  # putting higher numbers so that version number doesnt collide with existing in db
    factory_document_model(version_id_3, 'termsofuse_directorsearch', html_content_1)

    version_id_4 = 'd31'  # putting higher numbers so that version number doesnt collide with existing in db
    factory_document_model(version_id_4, 'termsofuse_directorsearch', html_content_2)

    headers = factory_auth_header(jwt=jwt, claims=TestJwtClaims.anonymous_bcros_role)
    rv = client.get('/api/v1/documents/termsofuse', headers=headers, content_type='application/json')

    assert rv.status_code == http_status.HTTP_200_OK
    assert schema_utils.validate(rv.json, 'document')[0]
    assert rv.json.get('content') == html_content_2
    assert rv.json.get('versionId') == version_id_4
def test_documents_returns_latest_always(client, jwt, session):  # pylint:disable=unused-argument
    """Assert authorizations for affiliated users returns 200."""
    html_content_1 = '<HTML>1</HTML>'
    version_id_1 = 2
    factory_document_model(version_id_1, 'termsofuse', html_content_1)

    html_content_2 = '<HTML>2</HTML>'
    version_id_2 = 3
    factory_document_model(version_id_2, 'termsofuse', html_content_2)

    rv = client.get(f'/api/v1/documents/termsofuse', content_type='application/json')

    assert rv.status_code == http_status.HTTP_200_OK
    assert rv.json.get('content') == html_content_2
    assert rv.json.get('version_id') == version_id_2