aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_sdc_vfc.py
blob: 7322e0a55d51e28bc36e2194524b6fe06c66734e (plain)
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#   Copyright 2022 Orange, Deutsche Telekom AG
#
#   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.
from unittest import mock

import pytest

import onapsdk.constants as const
from onapsdk.exceptions import ResourceNotFound
from onapsdk.sdc.vfc import Vfc


VFCS = [
    {
        "uuid":"18167a36-5f7d-4e10-809f-b73ce7268b00",
        "invariantUUID":"a5852d77-c364-4eec-97c6-8630b8f138ac",
        "name":"Allotted Resource",
        "version":"1.0",
        "toscaModelURL":"/sdc/v1/catalog/resources/18167a36-5f7d-4e10-809f-b73ce7268b00/toscaModel",
        "category":"Allotted Resource",
        "subCategory":"Allotted Resource",
        "resourceType":"VFC",
        "lifecycleState":"CERTIFIED",
        "lastUpdaterUserId":"jh0003"
    },
    {
        "uuid":"3b9f3a0d-f9d1-4d95-80ce-7f7812a2b7b5",
        "invariantUUID":"c4aa9ad7-1c68-4fde-884e-b9d693b5f725",
        "name":"Controller",
        "version":"1.0",
        "toscaModelURL":"/sdc/v1/catalog/resources/3b9f3a0d-f9d1-4d95-80ce-7f7812a2b7b5/toscaModel",
        "category":"Generic",
        "subCategory":"Infrastructure",
        "resourceType":"VFC",
        "lifecycleState":"CERTIFIED",
        "lastUpdaterUserId":"jh0003"
    }
]


@mock.patch.object(Vfc, 'send_message_json')
def test_get_all_no_vfc(mock_send):
    """Returns empty array if no vfcs."""
    mock_send.return_value = {}
    assert Vfc.get_all() == []
    mock_send.assert_called_once_with("GET", 'get Vfcs', 'https://sdc.api.be.simpledemo.onap.org:30204/sdc/v1/catalog/resources?resourceType=VFC')


@mock.patch.object(Vfc, 'send_message_json')
def test_get_all_vfc(mock_send):
    mock_send.return_value = VFCS
    vfcs = Vfc.get_all()
    assert len(vfcs) == 2
    vfc = vfcs[0]
    assert vfc.name == "Allotted Resource"
    assert vfc.identifier == "18167a36-5f7d-4e10-809f-b73ce7268b00"
    assert vfc.unique_uuid == "a5852d77-c364-4eec-97c6-8630b8f138ac"
    assert vfc.version == "1.0"
    assert vfc.status == const.CERTIFIED
    vfc = vfcs[1]
    assert vfc.name == "Controller"
    assert vfc.identifier == "3b9f3a0d-f9d1-4d95-80ce-7f7812a2b7b5"
    assert vfc.unique_uuid == "c4aa9ad7-1c68-4fde-884e-b9d693b5f725"
    assert vfc.version == "1.0"
    assert vfc.status == const.CERTIFIED


@mock.patch.object(Vfc, 'send_message_json')
def test_create_vfc_not_exists(mock_send):
    mock_send.return_value = VFCS
    with pytest.raises(ResourceNotFound):
        Vfc("not_exists")