test_search_v3.py 5.53 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# Copyright 2021 Schlumberger
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import pytest
from .fixtures import with_wdms_env
from ..request_builders.wdms.search_apis.setup import *
from ..request_builders.wdms.search_apis.search import *
from time import sleep

@pytest.fixture(params=['query', 'fastquery'])
def set_search_query_type(with_wdms_env, request):
    env = with_wdms_env
    env.set('search_query_type', request.param)

def query_for_record_set_available(env):
    result = build_request_osdu_seach_tests_setup_start().call(env)
    result.assert_ok()
    return result.get_response_obj()

@pytest.mark.tag('search')
@pytest.mark.dependency()
def test_setup_for_search(with_wdms_env):
    # TODO this must be revisited to have independent setup for each needed record
    wait_attempt = 10

    # set here the version the data set of record needed for the tests
    env = with_wdms_env
    env.set('search_record_version', '0001')
    # this value is use in the query to fetch the record

    env.set('search_query_type', 'fastquery')

    query_result = query_for_record_set_available(env)
    nb_record = len(query_result.results)
    if nb_record > 0:
        #Retrieve wellboreID
        env.set("setup_search_osdu_wellbore_id", query_result.results[0].data.WellboreID)

    if nb_record == 0:
        # create one wellbore
fabian serin's avatar
fabian serin committed
52
        record_id = build_request_search_tests_setup_create_osdu_wellbore().call(
53
54
55
56
            env, assert_status=200).get_response_obj().recordIds[0]
        env.set("setup_search_osdu_wellbore_id", record_id)

        for _ in range(2):  # create 2 logset
fabian serin's avatar
fabian serin committed
57
            record_id = build_request_search_tests_setup_create_osdu_welllogs().call(
58
59
60
61
                env, assert_status=200).get_response_obj().recordIds[0]
        env.set("setup_search_osdu_welllog_id", record_id)  # it doesn't matter which logset id is set

        for _ in range(2):  # create 2 marker
fabian serin's avatar
fabian serin committed
62
63
64
65
            build_request_search_tests_setup_create_osdu_markersets().call(env, assert_status=200)

        for _ in range(2):  # create 2 trajectories
            build_request_search_tests_setup_create_osdu_trajectories().call(env, assert_status=200)
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98

        # wait for the record to be searchable
        while nb_record <= 0 and wait_attempt >= 0:
            print('not enough record indexed => Wait 1 minute ... attempt countdown=' + str(wait_attempt))
            sleep(60)
            query_result = query_for_record_set_available(env)
            nb_record = len(query_result.results)
            wait_attempt -= 1

    assert nb_record > 0, 'search setup failure, get the record set'

@pytest.mark.tag('search')
@pytest.mark.dependency(depends=["test_setup_for_search"])
def test_search_welllogs_by_wellbore_id(with_wdms_env, set_search_query_type):
    resobj = build_request_search_welllogs_by_wellbore_id().call(with_wdms_env, assert_status=200).get_response_obj()
    assert resobj.totalCount >= 2


@pytest.mark.tag('search')
@pytest.mark.dependency(depends=["test_setup_for_search"])
def test_search_markersets_by_wellbore_id(with_wdms_env, set_search_query_type):
    resobj = build_request_search_markersets_by_wellbore_id().call(with_wdms_env, assert_status=200).get_response_obj()
    assert resobj.totalCount >= 2


@pytest.mark.tag('search')
@pytest.mark.dependency(depends=["test_setup_for_search"])
def test_search_logset_by_wellbore_attribute(with_wdms_env, set_search_query_type):
    resobj = build_request_search_welllogs_by_wellbores_attribute().call(
        with_wdms_env, assert_status=200).get_response_obj()
    assert resobj.totalCount >= 2


fabian serin's avatar
fabian serin committed
99
100
101
102
103
104
105
106
@pytest.mark.tag('search')
@pytest.mark.dependency(depends=["test_setup_for_search"])
def test_search_wellbore_by_name(with_wdms_env):
    #Only search and no fast search
    env = with_wdms_env
    env.set('search_query_type', 'query')
    resobj = build_request_search_wellbore_by_name().call(with_wdms_env, assert_status=200).get_response_obj()
    assert resobj.totalCount >= 1
fabian serin's avatar
fabian serin committed
107
108
109
110
111
112
113
114
115
116


@pytest.mark.tag('search')
@pytest.mark.dependency(depends=["test_setup_for_search"])
def test_search_trajectory_by_wellbore_id(with_wdms_env):
    #Only search and no fast search
    env = with_wdms_env
    env.set('search_query_type', 'query')
    resobj = build_request_search_trajectory_by_wellbore_id().call(with_wdms_env, assert_status=200).get_response_obj()
    assert resobj.totalCount >= 1
fabian serin's avatar
fabian serin committed
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136


@pytest.mark.tag('search')
@pytest.mark.dependency(depends=["test_setup_for_search"])
def test_search_wellLog_by_name(with_wdms_env):
    #Only search and no fast search
    env = with_wdms_env
    env.set('search_query_type', 'query')
    resobj = build_request_search_welllog_by_name().call(with_wdms_env, assert_status=200).get_response_obj()
    assert resobj.totalCount >= 1


@pytest.mark.tag('search')
@pytest.mark.dependency(depends=["test_setup_for_search"])
def test_search_wellLog_by_name_and_wellbore(with_wdms_env):
    #Only search and no fast search
    env = with_wdms_env
    env.set('search_query_type', 'query')
    resobj = build_request_search_welllog_by_name_and_wellbore().call(with_wdms_env, assert_status=200).get_response_obj()
    assert resobj.totalCount >= 1