aboutsummaryrefslogtreecommitdiffstats
path: root/tests/apiTests/test_negative_requests.py
blob: 9efb69e0ea7530b792b9ebde0ab7eef5c77793bc (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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
# ============LICENSE_START==========================================
# org.onap.vvp/test-engine
# ===================================================================
# Copyright © 2017 AT&T Intellectual Property. All rights reserved.
# ===================================================================
#
# Unless otherwise specified, all software contained herein is licensed
# under the Apache License, Version 2.0 (the “License”);
# you may not use this software 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.
#
#
#
# Unless otherwise specified, all documentation contained herein is licensed
# under the Creative Commons License, Attribution 4.0 Intl. (the “License”);
# you may not use this documentation except in compliance with the License.
# You may obtain a copy of the License at
#
#             https://creativecommons.org/licenses/by/4.0/
#
# Unless required by applicable law or agreed to in writing, documentation
# 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.
#
# ============LICENSE_END============================================
#
# ECOMP is a trademark and service mark of AT&T Intellectual Property.
from django.conf import settings

from iceci.decorator.exception_decor import exception
from services.constants import Constants
from services.helper import Helper
from services.logging_service import LoggingServiceFactory
from services.types import API
from tests.apiTests.test_api_base import TestApiBase


logger = LoggingServiceFactory.get_logger()


class TestNegativeRequests(TestApiBase, Helper):

    @exception()
    def test_negative_invite_member(self):
        logger.debug(
            "This negative test will try to invite team " +
            "member to an engagement using other auth token.")
        user_a = API.VirtualFunction.create_engagement()
        user_b = API.VirtualFunction.create_engagement()
        user_a['session_token'] = user_b['session_token']
        try:
            logger.debug(
                "About to invite team member to the engagement of user " +
                user_a['full_name'])
            API.VirtualFunction.invite_team_member(user_a)
            raise Exception(
                user_a['full_name'] +
                " has invited user using other auth token.")
        except BaseException:
            logger.debug(
                "Success! Test failed to invite user using other auth token.")

    @exception()
    def test_negative_add_contact(self):
        logger.debug(
            "This negative test will try to add contact to " +
            "an engagement using other auth token.")
        user_a = API.VirtualFunction.create_engagement()
        user_b = API.VirtualFunction.create_engagement()
        user_a['session_token'] = user_b['session_token']
        try:
            logger.debug(
                "About to invite contact to the engagement of user " +
                user_a['full_name'])
            API.VirtualFunction.add_contact(user_a)
            raise Exception(
                user_a['full_name'] +
                " has invited contact user using other auth token.")
        except BaseException:
            logger.debug(
                "Success! Test failed to invite contact " +
                "user using other auth token.")

    @exception()
    def test_negative_add_next_step(self):
        logger.debug(
            "This negative test will try to add a next step to engagement " +
            "using PR / standard user / admin_ro auth token.")
        user_content = API.VirtualFunction.create_engagement()
        users = [user_content['email'], user_content[
            'pr_email'], Constants.Users.AdminRO.EMAIL]
        for user in users:
            token = "token " + API.User.login_user(user)
            user_content['session_token'] = token
            try:
                logger.debug(
                    "About to add a next step to VF " +
                    user_content['vfName'] +
                    " using " +
                    user +
                    " token.")
                API.VirtualFunction.add_next_step(user_content)
                raise Exception(
                    "Next step was added to VF " +
                    user_content['vfName'] +
                    " using " +
                    user +
                    " token.")
            except BaseException:
                logger.debug(
                    "Success! Test failed to add a new next step to the " +
                    "engagement using other auth token.")

    @exception()
    def test_negative_edit_next_step(self):
        logger.debug(
            "This negative test will try to edit a next step using PR / " +
            "standard user / admin_ro auth token.")
        user_content = API.VirtualFunction.create_engagement()
        token = "token " + API.User.login_user(user_content['el_email'])
        user_content['session_token'] = token
        ns_uuid = API.VirtualFunction.add_next_step(user_content)
        users = [user_content['email'], user_content[
            'pr_email'], Constants.Users.AdminRO.EMAIL]
        for user in users:
            token = "token " + API.User.login_user(user)
            user_content['session_token'] = token
            try:
                logger.debug(
                    "About to edit a next step (ns uuid: " +
                    ns_uuid +
                    ") using " +
                    user +
                    " token.")
                API.VirtualFunction.edit_next_step(user_content, ns_uuid)
                raise Exception(
                    "Next step was edited using " + user + " token.")
            except BaseException:
                logger.debug(
                    "Success! Test failed to edit a next step using " +
                    "other auth token.")

    @exception()
    def test_negative_create_checklist(self):
        user_content = API.VirtualFunction.create_engagement()
        logger.debug(
            "This negative test will try to create a checklist " +
            "using PR / standard user / admin_ro auth token.")
        users = [user_content['email'], user_content[
            'pr_email'], Constants.Users.AdminRO.EMAIL]
        for user in users:
            token = "token " + API.User.login_user(user)
            user_content['session_token'] = token
            try:
                logger.debug(
                    "About to create checklist for VF " +
                    user_content['vfName'])
                API.Checklist.create_checklist(user_content)
                raise Exception(
                    "Checklist was created using " + user + " token.")
            except BaseException:
                logger.debug(
                    "Success! Test failed to create checklist using other " +
                    "auth token.")

    @exception()
    def test_negative_update_checklist(self):
        user_content = API.VirtualFunction.create_engagement()
        API.GitLab.git_clone_push(user_content)
        logger.debug(
            "Create checklist with engagement lead (next: try to edit " +
            "checklist with PR and standard user)")
        token = "token " + API.User.login_user(user_content['el_email'])
        user_content['session_token'] = token
        cl_content = API.Checklist.create_checklist(user_content)
        logger.debug(
            "This negative test will try to create a checklist using PR / " +
            "standard user / admin_ro auth token.")
        users = [user_content['email'], user_content[
            'pr_email'], Constants.Users.AdminRO.EMAIL]
        for user in users:
            token = "token " + API.User.login_user(user)
            user_content['session_token'] = token
            try:
                logger.debug(
                    "About to update checklist for VF " +
                    user_content['vfName'])
                API.Checklist.update_checklist(
                    user_content, cl_content['uuid'])
                raise Exception(
                    "Checklist was created using " + user + " token.")
            except BaseException:
                logger.debug(
                    "Success! Test failed to create checklist using other " +
                    "auth token.")

    @exception()
    def test_negative_set_checklist_state(self):
        user_content = API.VirtualFunction.create_engagement()
        API.GitLab.git_clone_push(user_content)
        logger.debug(
            "Create checklist with engagement lead (next: try to change " +
            "checklist state with PR, standard user and admin_ro)")
        token = "token " + API.User.login_user(user_content['el_email'])
        user_content['session_token'] = token
        cl_content = API.Checklist.create_checklist(user_content)
        logger.debug(
            "This negative test will try to change checklist state using " +
            "PR / standard user / admin_ro auth token.")
        users = [user_content['email'], user_content[
            'pr_email'], Constants.Users.AdminRO.EMAIL]
        for user in users:
            try:
                logger.debug(
                    "About to change checklist state for VF " +
                    user_content['vfName'])
                API.Checklist.jump_state(cl_content['uuid'], user)
                raise Exception(
                    "Checklist state was changed using " + user + " token.")
            except BaseException:
                logger.debug(
                    "Success! Test failed to change checklist state using " +
                    "other auth token.")

    @exception()
    def test_add_checklist_audit_log(self):
        user_content = API.VirtualFunction.create_engagement()
        logger.debug(
            "Create checklist with engagement lead (next: try to add audit " +
            "log to checklist with standard user and admin_ro)")
        token = "token " + API.User.login_user(user_content['el_email'])
        user_content['session_token'] = token
        cl_content = API.Checklist.create_checklist(user_content, files=[])
        logger.debug(
            "This negative test will try to add audit log to checklist " +
            "using standard user / admin_ro auth token.")
        users = [user_content['email'], Constants.Users.AdminRO.EMAIL]
        for user in users:
            token = "token " + API.User.login_user(user)
            user_content['session_token'] = token
            try:
                logger.debug(
                    "About to add audit log to checklist uuid " +
                    cl_content['uuid'])
                API.Checklist.add_checklist_audit_log(
                    user_content, cl_content['uuid'])
                raise Exception(
                    "Audit log was added to checklist using " +
                    user +
                    " token.")
            except BaseException:
                logger.debug(
                    "Success! Test failed to add audit log to checklist " +
                    "using other auth token.")

    @exception()
    def test_add_checklist_next_step(self):
        user_content = API.VirtualFunction.create_engagement()
        API.GitLab.git_clone_push(user_content)
        logger.debug(
            "Create checklist with engagement lead (next: try to add " +
            "checklist next step with PR, standard user and admin_ro)")
        token = "token " + API.User.login_user(user_content['el_email'])
        user_content['session_token'] = token
        cl_content = API.Checklist.create_checklist(user_content)
        logger.debug(
            "This negative test will try to add checklist next step using " +
            "PR / standard user / admin_ro auth token.")
        users = [user_content['email'], user_content[
            'pr_email'], Constants.Users.AdminRO.EMAIL]
        for user in users:
            token = "token " + API.User.login_user(user)
            user_content['session_token'] = token
            try:
                logger.debug(
                    "About to add next step to checklist uuid " +
                    cl_content['uuid'])
                API.Checklist.add_checklist_next_step(
                    user_content, cl_content['uuid'])
                raise Exception(
                    "Next step was added to checklist using " +
                    user +
                    " token.")
            except BaseException:
                logger.debug(
                    "Success! Test failed to add next steps to checklist " +
                    "using other auth token.")

    @exception()
    def test_negative_checklist_files(self):
        # Can't run this test locally since locally we have files by default.
        if settings.DATABASE_TYPE == 'local':
            logger.debug("Local environment, skipping test...")
        else:  # Test starts here #
            user_content = API.VirtualFunction.create_engagement()
            logger.debug(
                "Trying to create checklist with associated files when " +
                "git repo is empty")
            token = "token " + API.User.login_user(user_content['el_email'])
            user_content['session_token'] = token
            try:
                API.Checklist.create_checklist(user_content)
                raise Exception(
                    "Checklist was created with associated files while " +
                    "git repo is empty.")
            except BaseException:
                logger.debug(
                    "Success! Test failed to create checklist with " +
                    "associated files while git repo is empty.")