aboutsummaryrefslogtreecommitdiffstats
path: root/integration_tests/test_11_ves.py
blob: 555317615a4b6423ce6e77928b622bf5c56651eb (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
#   Copyright 2022 Nokia
#
#   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
import logging
import os
import requests

from onapsdk.configuration import settings
from onapsdk.utils.jinja import jinja_env
from onapsdk.ves.ves import Ves
from onapsdk.dmaap.dmaap import Dmaap

logging.basicConfig(level=os.environ.get("LOGLEVEL", "DEBUG"))


def reset_dmaap_mock():
    requests.get("{}/reset".format(settings.DMAAP_URL))


@pytest.mark.integration
def test_should_send_event_to_ves():
    # given

    requests.post("{}/set_dmaap_address".format(settings.VES_URL), json={"DMAAP_MOCK": settings.DMAAP_URL})
    event: str = jinja_env().get_template("ves_stnd_event.json.j2").render()

    # when
    response = Ves.send_event(
        basic_auth={'username': 'sample1', 'password': 'sample1'},
        json_event=event,
        version="v7"
    )

    # then
    assert response.status_code == 202


@pytest.mark.integration
def test_should_send_batch_event_to_ves():
    # given

    requests.post("{}/set_dmaap_address".format(settings.VES_URL), json={"DMAAP_MOCK": settings.DMAAP_URL})
    event: str = jinja_env().get_template("ves7_batch_with_stndDefined_valid.json.j2").render()

    # when
    response = Ves.send_batch_event(
        basic_auth={'username': 'sample1', 'password': 'sample1'},
        json_event=event,
        version="v7"
    )

    # then
    assert response.status_code == 202


@pytest.mark.integration
def test_should_send_event_to_ves_and_dmaap():
    # given

    requests.post("{}/set_dmaap_address".format(settings.VES_URL), json={"DMAAP_MOCK": settings.DMAAP_URL})
    event: str = jinja_env().get_template("ves_stnd_event.json.j2").render()

    # when
    reset_dmaap_mock()
    response = Ves.send_event(
        basic_auth={'username': 'sample1', 'password': 'sample1'},
        json_event=event,

        version="v7"
    )

    # then
    assert response.status_code == 202
    events = Dmaap.get_events_for_topic("fault",
                                        basic_auth={'username': 'dcae@dcae.onap.org', 'password': 'demo123456!'})
    assert len(events) == 1


@pytest.mark.integration
def test_should_send_batch_event_to_ves_and_dmaap():
    # given

    requests.post("{}/set_dmaap_address".format(settings.VES_URL), json={"DMAAP_MOCK": settings.DMAAP_URL})
    event: str = jinja_env().get_template("ves7_batch_with_stndDefined_valid.json.j2").render()

    # when
    reset_dmaap_mock()
    response = Ves.send_batch_event(
        basic_auth={'username': 'sample1', 'password': 'sample1'},
        json_event=event,
        version="v7"
    )

    # then
    assert response.status_code == 202
    events = Dmaap.get_events_for_topic("fault",
                                        basic_auth={'username': 'dcae@dcae.onap.org', 'password': 'demo123456!'})
    assert len(events) == 2