test_crud.py 3.52 KB
Newer Older
ethiraj krishnamanaidu's avatar
ethiraj krishnamanaidu committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 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.

Luc Yriarte's avatar
Luc Yriarte committed
15
16
17
18
19
import pytest
from .fixtures import with_wdms_env
from ..request_builders import build_request

kind_list = ['well', 'wellbore', 'logset', 'marker', 'trajectory', 'log']
Victor Dosda's avatar
Victor Dosda committed
20
new_parameters_env = {'authorityKind': 'slb',
Victor Dosda's avatar
Victor Dosda committed
21
                      'prefix_data_entity_name': 'wdms_e2e_slb_authority'}
Luc Yriarte's avatar
Luc Yriarte committed
22
23
24
25
26

param_kind_depend_on_create = [
    pytest.param(k, marks=pytest.mark.dependency(depends=[f'test_create_record_{k}'])) for k in kind_list
]

27
28
#it will only be run once
@pytest.fixture(scope='module')
Victor Dosda's avatar
Victor Dosda committed
29
def get_env_variables_with_authority_in_kind(with_wdms_env):
30
31
32
33
34
    env_with_authority_in_kind = with_wdms_env.copy()
    for name, value in new_parameters_env.items():
        env_with_authority_in_kind.set(name, value)
    return env_with_authority_in_kind

35
@pytest.fixture(params=['data_partition', 'authority_slb'])
Victor Dosda's avatar
Victor Dosda committed
36
def get_env(with_wdms_env, get_env_variables_with_authority_in_kind, request):
37
    return with_wdms_env if request.param == "data_partition" else get_env_variables_with_authority_in_kind
38

Luc Yriarte's avatar
Luc Yriarte committed
39
40
41
42

@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])
43
44
def test_crud_create_record(get_env, kind):
    result = build_request(f'crud.{kind}.create_{kind}').call(get_env)
Luc Yriarte's avatar
Luc Yriarte committed
45
46
47
48
    result.assert_ok()
    resobj = result.get_response_obj()
    assert resobj.recordCount == 1
    assert len(resobj.recordIds) == 1
49
    assert len(resobj.recordIdVersions) == 1
50
    get_env.set(f'{kind}_record_id', resobj.recordIds[0])  # stored the record id for the following tests
Luc Yriarte's avatar
Luc Yriarte committed
51
52
53
54


@pytest.mark.tag('basic', 'crud', 'smoke')
@pytest.mark.parametrize('kind', param_kind_depend_on_create)
55
56
def test_crud_get_record(get_env, kind):
    result = build_request(f'crud.{kind}.get_{kind}').call(get_env)
Luc Yriarte's avatar
Luc Yriarte committed
57
58
    result.assert_ok()
    resobj = result.get_response_obj()
59
    assert resobj.data.name == f'{get_env.get("prefix_data_entity_name")}_{kind}'
Luc Yriarte's avatar
Luc Yriarte committed
60
61
62
63


@pytest.mark.tag('basic', 'crud', 'smoke')
@pytest.mark.parametrize('kind', param_kind_depend_on_create)
64
def test_crud_record_versions(get_env, kind):
Luc Yriarte's avatar
Luc Yriarte committed
65
    # get all version of the record
66
    result = build_request(f'crud.{kind}.get_versions_of_{kind}').call(get_env)
Luc Yriarte's avatar
Luc Yriarte committed
67
68
69
    result.assert_ok()
    resobj = result.get_response_obj()

70
    record_id = get_env.get(f'{kind}_record_id')
Luc Yriarte's avatar
Luc Yriarte committed
71
72
73
74
75
    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(
76
        get_env,
Luc Yriarte's avatar
Luc Yriarte committed
77
78
79
80
81
        **{f'{kind}_record_version': resobj.versions[0]}  # set/pass version to fetch
    )

    result.assert_ok()
    resobj = result.get_response_obj()
82
    assert resobj.data.name == f'{get_env.get("prefix_data_entity_name")}_{kind}'
Luc Yriarte's avatar
Luc Yriarte committed
83
84
85
86


@pytest.mark.tag('basic', 'crud', 'smoke')
@pytest.mark.parametrize('kind', param_kind_depend_on_create)
87
88
def test_crud_delete_record(get_env, kind):
    result = build_request(f'crud.{kind}.delete_{kind}').call(get_env)
Luc Yriarte's avatar
Luc Yriarte committed
89
    result.assert_status_code(204)