aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_sdc_element.py
blob: 8cfb9074aa7c51cebcac0561ea4b8b3bf1c421f1 (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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
"""Test SdcElement module."""
#   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

from onapsdk.onap_service import OnapService
from onapsdk.sdc.sdc_element import SdcElement
from onapsdk.sdc.vendor import Vendor
from onapsdk.sdc.vsp import Vsp
from onapsdk.sdc import SDC
from onapsdk.utils.gui import GuiList

def test_init():
    """Test the initialization."""
    element = Vendor()
    assert isinstance(element, OnapService)

def test_class_variables():
    """Test the class variables."""
    assert SdcElement.server == "SDC"
    assert SdcElement.base_front_url == "https://sdc.api.fe.simpledemo.onap.org:30207"
    assert SdcElement.base_back_url == "https://sdc.api.be.simpledemo.onap.org:30204"
    assert SdcElement.headers == {
            "Content-Type": "application/json",
            "Accept": "application/json"
        }

@mock.patch.object(Vendor, 'created')
@mock.patch.object(Vendor, 'send_message_json')
def test__get_item_details_not_created(mock_send, mock_created):
    vendor = Vendor()
    mock_created.return_value = False
    assert vendor._get_item_details() == {}
    mock_send.assert_not_called()

@mock.patch.object(Vsp, 'send_message_json')
def test__get_item_details_created(mock_send):
    vsp = Vsp()
    vsp.identifier = "1234"
    mock_send.return_value = {'results': [{"creationTime": "2"}, {"creationTime": "3"}], "listCount": 2}
    assert vsp._get_item_details() == {"creationTime": "3"}
    mock_send.assert_called_once_with('GET', 'get item', "{}/items/1234/versions".format(vsp._base_url()))

@mock.patch.object(Vsp, 'created')
@mock.patch.object(Vsp, 'send_message_json')
def test__get_items_version_details_not_created(mock_send, mock_created):
    vsp = Vsp()
    mock_created.return_value = False
    assert vsp._get_item_version_details() == {}
    mock_send.assert_not_called()

@mock.patch.object(Vsp, 'load')
@mock.patch.object(Vsp, 'send_message_json')
def test__get_items_version_details_no_version(mock_send, mock_load):
    vsp = Vsp()
    vsp.identifier = "1234"
    assert vsp._get_item_version_details() == {}
    mock_send.assert_not_called()

@mock.patch.object(Vsp, 'send_message_json')
def test__get_items_version_details(mock_send):
    vsp = Vsp()
    vsp.identifier = "1234"
    vsp._version = "4567"
    mock_send.return_value = {'return': 'value'}
    assert vsp._get_item_version_details() == {'return': 'value'}
    mock_send.assert_called_once_with('GET', 'get item version', "{}/items/1234/versions/4567".format(vsp._base_url()))

@mock.patch.object(SDC, "send_message")
def test_get_guis(send_message_mock):
    send_message_mock.return_value.status_code = 200
    send_message_mock.return_value.url = "https://sdc.api.fe.simpledemo.onap.org:30207/sdc1/portal"
    gui_results = SDC.get_guis()
    assert type(gui_results) == GuiList
    assert gui_results.guilist[0].url == send_message_mock.return_value.url
    assert gui_results.guilist[0].status == send_message_mock.return_value.status_code

@mock.patch.object(SDC, "get_all")
@mock.patch.object(Vsp, "created")
def test_exists_versions(mock_vsp_created, mock_get_all):
    mock_vsp_created.return_value = True
    sdc_el1 = Vsp(name="test1")
    sdc_el1._version = "1.0"
    sdc_el1._identifier = "123"
    sdc_el2 = Vsp(name="test2")
    sdc_el2._version = "2.0"
    sdc_el2._identifier = "123"
    mock_get_all.return_value = [sdc_el1, sdc_el2]
    assert sdc_el1.exists()

    sdc_el1 = Vsp(name="test1")
    sdc_el1._version = "anything"
    sdc_el1._identifier = "123"
    sdc_el2 = Vsp(name="test2")
    sdc_el2._version = "what_is_not_a_float"
    sdc_el2._identifier = "123"
    mock_get_all.return_value = [sdc_el1, sdc_el2]
    assert sdc_el1.exists()

@mock.patch.object(SdcElement, "send_message")
def test_delete(mock_send_message):
    vsp = Vsp("test_vsp")
    vsp.identifier = "test_vsp"
    vsp.delete()
    mock_send_message.assert_called_once()

    mock_send_message.reset_mock()
    vendor = Vendor("test_vendor")
    vendor.identifier = "test_vendor"
    vendor.delete()
    mock_send_message.assert_called_once()
n class="s">'{{ .Values.restServer.policyPapUserName }}' password: '{{ .Values.restServer.policyPapUserPassword }}' passwordPolicy: required - uid: policy-api-user-creds name: &policyApiCredsSecret '{{ include "common.release" . }}-policy-api-user-creds' type: basicAuth externalSecret: '{{ tpl (default "" .Values.restServer.policyApiUserExternalSecret) . }}' login: '{{ .Values.restServer.policyApiUserName }}' password: '{{ .Values.restServer.policyApiUserPassword }}' passwordPolicy: required - uid: pg-root-pass name: &pgRootPassSecretName '{{ include "common.release" . }}-policy-pg-root-pass' type: password externalSecret: '{{ ternary "" (tpl (default "" .Values.postgres.config.pgRootPasswordExternalSecret) .) (hasSuffix "policy-pg-root-pass" .Values.postgres.config.pgRootPasswordExternalSecret) }}' password: '{{ .Values.postgres.config.pgRootpassword }}' policy: generate - uid: pg-user-creds name: &pgUserCredsSecretName '{{ include "common.release" . }}-policy-pg-user-creds' type: basicAuth externalSecret: '{{ ternary "" (tpl (default "" .Values.postgres.config.pgUserExternalSecret) .) (hasSuffix "policy-pg-user-creds" .Values.postgres.config.pgUserExternalSecret) }}' login: '{{ .Values.postgres.config.pgUserName }}' password: '{{ .Values.postgres.config.pgUserPassword }}' passwordPolicy: generate db: &dbSecretsHook credsExternalSecret: *dbSecretName policy-api: enabled: true db: *dbSecretsHook restServer: apiUserExternalSecret: *policyApiCredsSecret config: jaasConfExternalSecret: '{{ include "common.release" . }}-{{ .Values.global.policyKafkaUser }}' policy-pap: enabled: true db: *dbSecretsHook restServer: papUserExternalSecret: *policyPapCredsSecret apiUserExternalSecret: *policyApiCredsSecret config: jaasConfExternalSecret: '{{ include "common.release" . }}-{{ .Values.global.policyKafkaUser }}' policy-xacml-pdp: enabled: true db: *dbSecretsHook config: jaasConfExternalSecret: '{{ include "common.release" . }}-{{ .Values.global.policyKafkaUser }}' policy-apex-pdp: enabled: true db: *dbSecretsHook config: jaasConfExternalSecret: '{{ include "common.release" . }}-{{ .Values.global.policyKafkaUser }}' policy-drools-pdp: enabled: true db: *dbSecretsHook config: jaasConfExternalSecret: '{{ include "common.release" . }}-{{ .Values.global.policyKafkaUser }}' policy-distribution: enabled: true db: *dbSecretsHook config: jaasConfExternalSecret: '{{ include "common.release" . }}-{{ .Values.global.policyDistKafkaUser }}' policy-clamp-ac-k8s-ppnt: enabled: true config: jaasConfExternalSecret: '{{ include "common.release" . }}-{{ .Values.global.policyKafkaUser }}' policy-clamp-ac-pf-ppnt: enabled: true restServer: apiUserExternalSecret: *policyApiCredsSecret papUserExternalSecret: *policyPapCredsSecret config: jaasConfExternalSecret: '{{ include "common.release" . }}-{{ .Values.global.policyKafkaUser }}' policy-clamp-ac-http-ppnt: enabled: true config: jaasConfExternalSecret: '{{ include "common.release" . }}-{{ .Values.global.policyKafkaUser }}' policy-clamp-ac-a1pms-ppnt: enabled: true config: jaasConfExternalSecret: '{{ include "common.release" . }}-{{ .Values.global.policyKafkaUser }}' policy-nexus: enabled: false config: jaasConfExternalSecret: '{{ include "common.release" . }}-{{ .Values.global.policyKafkaUser }}' policy-clamp-runtime-acm: enabled: true db: *dbSecretsHook config: appUserExternalSecret: *policyAppCredsSecret jaasConfExternalSecret: '{{ include "common.release" . }}-{{ .Values.global.policyKafkaUser }}' policy-gui: enabled: false config: jaasConfExternalSecret: '{{ include "common.release" . }}-{{ .Values.global.policyKafkaUser }}' ################################################################# # DB configuration defaults. ################################################################# repository: nexus3.onap.org:10001 pullPolicy: Always mariadb: image: mariadb:10.5.8 dbmigrator: image: onap/policy-db-migrator:2.5.1 schema: policyadmin policy_home: "/opt/app/policy" subChartsOnly: enabled: true # flag to enable debugging - application support required debugEnabled: false # default number of instances replicaCount: 1 nodeSelector: {} affinity: {} # probe configuration parameters liveness: initialDelaySeconds: 10 periodSeconds: 10 # necessary to disable liveness probe when setting breakpoints # in debugger so K8s doesn't restart unresponsive container enabled: true readiness: initialDelaySeconds: 10 periodSeconds: 10 config: policyAppUserName: runtimeUser useStrimziKafka: true acRuntimeTopic: name: policy-acruntime-participant partitions: 10 retentionMs: 7200000 segmentBytes: 1073741824 consumer: groupId: policy-group policyPdpPapTopic: name: policy-pdp-pap partitions: 10 retentionMs: 7200000 segmentBytes: 1073741824 consumer: groupId: policy-group policyHeartbeatTopic: name: policy-heartbeat partitions: 10 retentionMs: 7200000 segmentBytes: 1073741824 consumer: groupId: policy-group policyNotificationTopic: name: policy-notification partitions: 10 retentionMs: 7200000 segmentBytes: 1073741824 consumer: groupId: policy-group someConfig: blah mariadb-galera: # mariadb-galera.config and global.mariadb.config must be equals db: user: policy_user # password: externalSecret: *dbSecretName name: &mysqlDbName policyadmin rootUser: externalSecret: *dbRootPassSecretName nameOverride: *policy-mariadb # mariadb-galera.service and global.mariadb.service must be equals service: *mariadbService replicaCount: 1 persistence: enabled: true mountSubPath: policy/maria/data serviceAccount: nameOverride: *policy-mariadb postgresImage: library/postgres:latest # application configuration override for postgres postgres: nameOverride: &postgresName policy-postgres service: name: *postgresName name2: policy-pg-primary name3: policy-pg-replica container: name: primary: policy-pg-primary replica: policy-pg-replica persistence: mountSubPath: policy/postgres/data mountInitPath: policy config: pgUserName: policy_user pgDatabase: policyadmin pgUserExternalSecret: *pgUserCredsSecretName pgRootPasswordExternalSecret: *pgRootPassSecretName readinessCheck: wait_for: - '{{ ternary .Values.postgres.service.name "postgres" .Values.global.postgres.localCluster }}' restServer: policyPapUserName: policyadmin policyPapUserPassword: zb!XztG34 policyApiUserName: policyadmin policyApiUserPassword: zb!XztG34 # Resource Limit flavor -By Default using small # Segregation for Different environment (small, large, or unlimited) flavor: small resources: small: limits: cpu: 1 memory: 4Gi requests: cpu: 100m memory: 1Gi large: limits: cpu: 2 memory: 8Gi requests: cpu: 200m memory: 2Gi unlimited: {} #Pods Service Account serviceAccount: nameOverride: policy roles: - read