test_crud_v3.py 4.84 KB
Newer Older
Luc Yriarte's avatar
Luc Yriarte committed
1
2
3
4
5
6
7
8
9
10
11
12
13
# 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.
Victor Dosda's avatar
Victor Dosda committed
14
import json
Luc Yriarte's avatar
Luc Yriarte committed
15
16

import pytest
Victor Dosda's avatar
Victor Dosda committed
17
18

from wdms_client.request_builders.wdms.delete_records import build_request_delete_osdu_records
Luc Yriarte's avatar
Luc Yriarte committed
19
from .fixtures import with_wdms_env
20
from wdms_client.request_builders import build_request, diff_record_against_ref
Luc Yriarte's avatar
Luc Yriarte committed
21

22
kind_list = ['osdu_wellbore', 'osdu_well', 'osdu_welllog', 'osdu_wellboretrajectory', 'osdu_wellboremarkerset']
Luc Yriarte's avatar
Luc Yriarte committed
23
24
25
26
27
28

# parametrize of kind + dependency on the create_record
param_kind_depend_on_create = [
    pytest.param(k, marks=pytest.mark.dependency(depends=[f'test_create_record_{k}'])) for k in kind_list
]

29

Luc Yriarte's avatar
Luc Yriarte committed
30
31
32
@pytest.mark.tag('basic', 'crud', 'smoke')
@pytest.mark.parametrize(
    'kind', [pytest.param(k, marks=pytest.mark.dependency(name=f'test_create_record_{k}')) for k in kind_list])
33
def test_create_record(with_wdms_env, kind):
Luc Yriarte's avatar
Luc Yriarte committed
34
35
36
37
38
    result = build_request(f'crud.{kind}.create_{kind}').call(with_wdms_env)
    result.assert_ok()
    resobj = result.get_response_obj()
    assert resobj.recordCount == 1
    assert len(resobj.recordIds) == 1
39
    assert len(resobj.recordIdVersions) == 1
Luc Yriarte's avatar
Luc Yriarte committed
40
41
42
43
44
45
46
47
48
    with_wdms_env.set(f'{kind}_record_id', resobj.recordIds[0])  # stored the record id for the following tests


@pytest.mark.tag('basic', 'crud', 'smoke')
@pytest.mark.parametrize('kind', param_kind_depend_on_create)
def test_crud_get_record(with_wdms_env, kind):
    result = build_request(f'crud.{kind}.get_{kind}').call(with_wdms_env)
    result.assert_ok()
    res_dict = result.get_response_obj().toDict()
49
50
51
    diff = diff_record_against_ref(kind, res_dict)
    assert not diff

Luc Yriarte's avatar
Luc Yriarte committed
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68


@pytest.mark.tag('basic', 'crud', 'smoke')
@pytest.mark.parametrize('kind', param_kind_depend_on_create)
def test_crud_record_versions(with_wdms_env, kind):
    # get all version of the record
    result = build_request(f'crud.{kind}.get_versions_of_{kind}').call(with_wdms_env)
    result.assert_ok()
    resobj = result.get_response_obj()

    record_id = with_wdms_env.get(f'{kind}_record_id')
    assert resobj.recordId == record_id
    assert len(resobj.versions) >= 1

    # get specific version of the record
    result = build_request(f'crud.{kind}.get_{kind}_specific_version').call(
        with_wdms_env,
Victor Dosda's avatar
Victor Dosda committed
69
        **{f'{kind}_record_version': resobj.versions[len(resobj.versions) - 1]}  # set/pass version to fetch
Luc Yriarte's avatar
Luc Yriarte committed
70
71
72
73
74
75
76
77
78
79
    )

    result.assert_ok()


@pytest.mark.tag('basic', 'crud', 'smoke')
@pytest.mark.parametrize('kind', param_kind_depend_on_create)
def test_crud_delete_record(with_wdms_env, kind):
    result = build_request(f'crud.{kind}.delete_{kind}').call(with_wdms_env)
    result.assert_status_code(204)
fabian serin's avatar
fabian serin committed
80

fabian serin's avatar
fabian serin committed
81
82
83
84
85
86
87

GETAS_PARAMS = [
    'wellbore',
    'well'
]


fabian serin's avatar
fabian serin committed
88
@pytest.fixture()
fabian serin's avatar
fabian serin committed
89
90
91
def delfi_id(with_wdms_env, kind):
    # Create a delfi well
    result = build_request(f"crud.{kind}.create_{kind}").call(with_wdms_env)
fabian serin's avatar
fabian serin committed
92
93
94
95
96
    result.assert_ok()
    resobj = result.get_response_obj()
    assert resobj.recordCount == 1
    assert len(resobj.recordIds) == 1
    delfi_record_id = resobj.recordIds[0]
fabian serin's avatar
fabian serin committed
97
    with_wdms_env.set(f'{kind}_record_id', delfi_record_id)
fabian serin's avatar
fabian serin committed
98
99
100

    yield delfi_record_id

fabian serin's avatar
fabian serin committed
101
102
    # Cleanup
    result = build_request(f"crud.{kind}.delete_{kind}").call(with_wdms_env)
fabian serin's avatar
fabian serin committed
103
104
    result.assert_ok()

fabian serin's avatar
fabian serin committed
105

106
@pytest.mark.tag('crud', 'smoke')
fabian serin's avatar
fabian serin committed
107
108
109
110
@pytest.mark.parametrize('kind', GETAS_PARAMS)
def test_crud_get_as_record(delfi_id, kind, with_wdms_env):
    delfi_record_id = delfi_id
    with_wdms_env.set(f'osdu_{kind}_record_id', delfi_record_id)
fabian serin's avatar
fabian serin committed
111
112

    # Get it as osdu wellbore with delfi id
fabian serin's avatar
fabian serin committed
113
    result = build_request(f'crud.osdu_{kind}.get_osdu_{kind}').call(with_wdms_env)
114
    result.assert_status_code(422)
Victor Dosda's avatar
Victor Dosda committed
115
116
117
118
119
120
121
122


@pytest.mark.tag('basic', 'crud', 'smoke')
def test_crud_delete_records(with_wdms_env):
    record_ids = []
    for kind in kind_list:
        result = build_request(f'crud.{kind}.create_{kind}').call(with_wdms_env)
        resobj = result.get_response_obj()
Victor Dosda's avatar
Victor Dosda committed
123
        with_wdms_env.set(f'{kind}_record_id', resobj.recordIds[0])
Victor Dosda's avatar
Victor Dosda committed
124
        record_ids.append(resobj.recordIds[0])
Victor Dosda's avatar
Victor Dosda committed
125
126
127
        result = build_request(f'crud.{kind}.get_{kind}').call(with_wdms_env)
        result.assert_status_code(200)
    with_wdms_env.set(f'record_ids', json.dumps(record_ids))  # stored the record id for the following tests
Victor Dosda's avatar
Victor Dosda committed
128
    result = build_request_delete_osdu_records().call(with_wdms_env)
Victor Dosda's avatar
Victor Dosda committed
129
130
131
    result.assert_status_code(204)
    for kind in kind_list:
        result = build_request(f'crud.{kind}.get_{kind}').call(with_wdms_env)
132
        result.assert_status_code(404)