Пример #1
0
def test_record_created_through_api_is_indexed(
    app,
    celery_app_with_context,
    celery_session_worker,
    retry_until_matched,
    clear_environment,
):
    data = faker.record("lit")
    token = AccessTokenFactory()
    db.session.commit()
    headers = {"Authorization": f"Bearer {token.access_token}"}
    content_type = "application/json"
    response = app.test_client().post(f"literature",
                                      json=data,
                                      headers=headers,
                                      content_type=content_type)
    assert response.status_code == 201

    es.indices.refresh("records-hep")
    steps = [
        {
            "step": es.indices.refresh,
            "args": ["records-hep"]
        },
        {
            "step": es.search,
            "args": ["records-hep"],
            "expected_result": {
                "expected_key": "hits.total",
                "expected_result": 1
            },
        },
    ]
    retry_until_matched(steps)
Пример #2
0
def test_record_created_through_api_is_indexed(inspire_app,
                                               celery_app_with_context,
                                               celery_session_worker):
    data = faker.record("aut")
    token = AccessTokenFactory()
    db.session.commit()
    headers = {"Authorization": f"Bearer {token.access_token}"}
    content_type = "application/json"
    response = inspire_app.test_client().post("/api/authors",
                                              json=data,
                                              headers=headers,
                                              content_type=content_type)
    assert response.status_code == 201

    current_search.flush_and_refresh("records-authors")
    steps = [
        {
            "step": current_search.flush_and_refresh,
            "args": ["records-authors"]
        },
        {
            "step": es_search,
            "args": ["records-authors"],
            "expected_result": {
                "expected_key": "hits.total.value",
                "expected_result": 1,
            },
        },
    ]
    retry_until_matched(steps)
Пример #3
0
def test_record_created_through_api_is_indexed(inspire_app, clean_celery_session):
    data = faker.record("lit", with_control_number=True)
    token = AccessTokenFactory()
    db.session.commit()
    headers = {"Authorization": f"Bearer {token.access_token}"}
    content_type = "application/json"
    response = inspire_app.test_client().post(
        "/api/literature", json=data, headers=headers, content_type=content_type
    )
    assert response.status_code == 201

    assert_record_in_es(data["control_number"])
Пример #4
0
def test_record_created_through_api_is_indexed(inspire_app,
                                               celery_app_with_context,
                                               celery_session_worker):
    data = faker.record("lit")
    token = AccessTokenFactory()
    db.session.commit()
    headers = {"Authorization": f"Bearer {token.access_token}"}
    content_type = "application/json"
    response = inspire_app.test_client().post("/api/literature",
                                              json=data,
                                              headers=headers,
                                              content_type=content_type)
    assert response.status_code == 201
    assert_es_hits_count(1)
Пример #5
0
def test_record_created_through_api_is_indexed(inspire_app, clean_celery_session):
    data = faker.record("aut")
    token = AccessTokenFactory()
    db.session.commit()
    headers = {"Authorization": f"Bearer {token.access_token}"}
    content_type = "application/json"
    response = inspire_app.test_client().post(
        "/api/authors", json=data, headers=headers, content_type=content_type
    )
    assert response.status_code == 201

    def assert_record():
        current_search.flush_and_refresh("records-authors")
        result = es_search("records-authors")
        result_total = get_value(result, "hits.total.value")
        expected_total = 1
        assert expected_total == result_total

    retry_until_pass(assert_record)
Пример #6
0
def create_user_and_token(user_role="superuser"):
    """Test helper function to create user and authentication token."""
    return AccessTokenFactory(**{"role": user_role})
Пример #7
0
 def _create_user_and_token():
     return AccessTokenFactory()