forked from SatelliteQE/robottelo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_subscription.py
More file actions
396 lines (330 loc) · 15 KB
/
Copy pathtest_subscription.py
File metadata and controls
396 lines (330 loc) · 15 KB
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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
"""Test module for Subscriptions/Manifests UI
:Requirement: Subscription
:CaseAutomation: Automated
:CaseComponent: SubscriptionManagement
:team: Proton
:CaseImportance: High
"""
from datetime import datetime, timedelta
from tempfile import mkstemp
import time
from zoneinfo import ZoneInfo
from fauxfactory import gen_string
import pytest
from tzlocal import get_localzone_name
from robottelo.constants import (
DEFAULT_SUBSCRIPTION_NAME,
EXPIRED_MANIFEST,
EXPIRED_MANIFEST_DATE,
DataFile,
)
from robottelo.utils.issue_handlers import is_open
pytestmark = [pytest.mark.run_in_one_thread]
@pytest.mark.e2e
@pytest.mark.upgrade
def test_positive_end_to_end(session, function_sca_manifest, target_sat):
"""Upload a manifest with minimal input parameters, attempt to
delete it with checking the warning message and hit 'Cancel' button after than delete it.
:id: 580fc072-01e0-4f83-8cbb-2a8522d76243
:expectedresults:
1. The manifest was uploaded successfully.
2. Manifest import is reflected at the dashboard
3. When attempting to delete the manifest the confirmation dialog contains informative
message which warns user about downsides and consequences of manifest deletion.
4. When hitting cancel the manifest was not deleted.
5. When deleting and confirming deletion, the manifest was deleted successfully.
6. When reimporting manifest, the manifest is reimported successfully and the candlepin log
shows no error.
:BZ: 1266827, 2066899, 2076684
:SubComponent: Candlepin
:customerscenario: true
:CaseImportance: Critical
"""
expected_message_lines = [
'Are you sure you want to delete the manifest?',
'Note: Deleting a subscription manifest is STRONGLY discouraged.',
'This action should only be taken for debugging purposes.',
]
org = target_sat.api.Organization().create()
_, temporary_local_manifest_path = mkstemp(prefix='manifest-', suffix='.zip')
with (
function_sca_manifest as manifest,
open(temporary_local_manifest_path, 'wb') as file_handler,
):
file_handler.write(manifest.content)
with session:
session.organization.select(org.name)
# Ignore "Danger alert: Katello::Errors::UpstreamConsumerNotFound'" as server will connect
# to upstream subscription service to verify
# the consumer uuid, that will be displayed in flash error messages
# Note: this happen only when using clone manifest.
session.subscription.add_manifest(
temporary_local_manifest_path,
ignore_error_messages=['Danger alert: Katello::Errors::UpstreamConsumerNotFound'],
)
assert session.subscription.has_manifest
subscriptions = session.subscription.read_subscriptions()
assert len(subscriptions) >= 1
assert any('Red Hat' in subscription['Name'] for subscription in subscriptions)
assert int(subscriptions[0]['Entitlements']) > 0
assert int(subscriptions[0]['Consumed']) >= 0
# manifest delete testing
delete_message = session.subscription.read_delete_manifest_message()
assert ' '.join(expected_message_lines) == delete_message
assert session.subscription.has_manifest
session.subscription.delete_manifest(
ignore_error_messages=['Danger alert: Katello::Errors::UpstreamConsumerNotFound']
)
assert not session.subscription.has_manifest
# reimport manifest
session.subscription.add_manifest(
temporary_local_manifest_path,
ignore_error_messages=['Danger alert: Katello::Errors::UpstreamConsumerNotFound'],
)
assert session.subscription.has_manifest
results = target_sat.execute(
'grep -E "NullPointerException|CandlepinError" /var/log/candlepin/candlepin.log'
)
assert results.stdout == ''
def test_positive_access_with_non_admin_user_without_manifest(test_name, target_sat):
"""Access subscription page with non admin user that has the necessary
permissions to check that there is no manifest uploaded.
:id: dab9dc15-39a8-4105-b7ff-ecef909dc6e6
:expectedresults: Subscription page is rendered properly without errors
:BZ: 1417082
:CaseImportance: Critical
"""
org = target_sat.api.Organization().create()
role = target_sat.api.Role(organization=[org]).create()
target_sat.api_factory.create_role_permissions(
role,
{
'Katello::Subscription': [
'view_subscriptions',
'manage_subscription_allocations',
'import_manifest',
'delete_manifest',
],
'Organization': ['view_organizations', 'edit_organizations'],
},
)
user_password = gen_string('alphanumeric')
user = target_sat.api.User(
admin=False,
role=[role],
password=user_password,
organization=[org],
default_organization=org,
).create()
with target_sat.ui_session(test_name, user=user.login, password=user_password) as session:
assert not session.subscription.has_manifest
@pytest.mark.upgrade
def test_positive_access_with_non_admin_user_with_manifest(
test_name, function_sca_manifest_org, target_sat
):
"""Access subscription page with user that has only view_subscriptions and view organizations
permission and organization that has a manifest uploaded.
:id: 9184fcf6-36be-42c8-984c-3c5d7834b3b4
:expectedresults: Subscription page is rendered properly without errors
and the default subscription is visible
:BZ: 1417082, 1651981
:customerscenario: true
:CaseImportance: Critical
"""
org = function_sca_manifest_org
role = target_sat.api.Role(organization=[org]).create()
target_sat.api_factory.create_role_permissions(
role,
{'Katello::Subscription': ['view_subscriptions'], 'Organization': ['view_organizations']},
)
user_password = gen_string('alphanumeric')
user = target_sat.api.User(
admin=False,
role=[role],
password=user_password,
organization=[org],
default_organization=org,
).create()
with target_sat.ui_session(test_name, user=user.login, password=user_password) as session:
assert (
session.subscription.search(f'name = "{DEFAULT_SUBSCRIPTION_NAME}"')[0]['Name']
== DEFAULT_SUBSCRIPTION_NAME
)
def test_positive_access_manifest_as_another_admin_user(
test_name, target_sat, function_sca_manifest
):
"""Other admin users should be able to access and manage a manifest
uploaded by a different admin.
:id: 02e319da-3b7a-4694-9164-475c2c71b9a8
:expectedresults: Other admin user should see/manage the manifest
:BZ: 1669241
:customerscenario: true
:CaseImportance: High
"""
org = target_sat.api.Organization().create()
user1_password = gen_string('alphanumeric')
user1 = target_sat.api.User(
admin=True, password=user1_password, organization=[org], default_organization=org
).create()
user2_password = gen_string('alphanumeric')
user2 = target_sat.api.User(
admin=True, password=user2_password, organization=[org], default_organization=org
).create()
# use the first admin to upload a manifest
with target_sat.ui_session(test_name, user=user1.login, password=user1_password) as session:
target_sat.upload_manifest(org.id, function_sca_manifest.content)
assert session.subscription.has_manifest
# store subscriptions that have "Red Hat" in the name for later
rh_subs = session.subscription.search("Red Hat")
# try to view and delete the manifest with another admin
with target_sat.ui_session(test_name, user=user2.login, password=user2_password) as session:
assert session.subscription.has_manifest
assert rh_subs == session.subscription.search("Red Hat")
session.subscription.delete_manifest(
ignore_error_messages=['Danger alert: Katello::Errors::UpstreamConsumerNotFound']
)
assert not session.subscription.has_manifest
def test_select_customizable_columns_uncheck_and_checks_all_checkboxes(
session, function_org, function_sca_manifest
):
"""Ensures that no column headers from checkboxes show up in the table after
unticking everything from selectable customizable column
:id: 88e140c7-ab4b-4d85-85bd-d3eff12162d7
:steps:
1. Login and go to Content -> Subscription
2. Click selectable customizable column icon next to search button
3. Iterate through list of checkboxes
4. Unchecks all ticked checkboxes
5. Verify that the table header column is empty after filter
6. Check all ticked checkboxes
7. Verify that the table header column is the same as the Checkbox_dict
Note: Table header will always contain 'Select all rows' header in html,
but will not be displayed in UI
:expectedresults:
1. No column headers show up
:CaseImportance: Medium
"""
checkbox_dict = {
'Name': False,
'SKU': False,
'Contract': False,
'Start Date': False,
'End Date': False,
'Requires Virt-Who': False,
'Type': False,
'Consumed': False,
'Entitlements': False,
'Product Host Count': False,
}
org = function_org
with session:
session.organization.select(org.name)
session.subscription.add_manifest(
function_sca_manifest.path,
ignore_error_messages=['Danger alert: Katello::Errors::UpstreamConsumerNotFound'],
)
headers = session.subscription.filter_columns(checkbox_dict)
assert headers == ('Select all rows',)
time.sleep(3)
checkbox_dict.update((k, True) for k in checkbox_dict)
col = session.subscription.filter_columns(checkbox_dict)
checkbox_dict.update({'Select all rows': ''})
assert set(col) == set(checkbox_dict)
@pytest.mark.parametrize('setting_update', ['expire_soon_days'], indirect=True)
def test_positive_check_manifest_validity_notification(
target_sat, setting_update, function_org, function_sca_manifest
):
"""Check notification when manifest is going to expire.
:id: 29ab0e80-25eb-44f0-9294-3a26922c33c5
:setup:
1. create new organization
:steps:
1. Upload expired manifest in newly created org
2. Go to Content > Subscriptions page, click on 'Manage Manifest' button.
3. Search for message string 'Manifest expired', or 'Your manifest expired'
4. Delete expired manifest from this org (cleanup part)
5. Upload non-expired manifest
6. Go to Content > Subscription page, click on 'Manage Manifest' button.
7. Search for message string 'Manifest expiring soon', or 'Your manifest will expire'
8. Delete non-expired manifest from this org (cleanup part)
:expectedresults:
1. 'Manifest expired', 'Manifest expiring soon' messages appear on Manage Manifest modal box
:Verifies: SAT-11630
:customerscenario: true
"""
remote_path = f'/tmp/{EXPIRED_MANIFEST}'
target_sat.put(DataFile.EXPIRED_MANIFEST_FILE, remote_path)
# upload expired manifest
target_sat.cli.Subscription.upload({'organization-id': function_org.id, 'file': remote_path})
with target_sat.ui_session() as session:
# Message - Manifest expired
session.organization.select(function_org.name)
# read expire manifest message
expired_manifest = session.subscription.read_subscription_manifest_header_message_and_date()
assert 'Manifest expired' in expired_manifest['header'], 'Manifest expire alert not found'
if not is_open('SAT-25052'):
assert (
f'Your manifest expired on {EXPIRED_MANIFEST_DATE}. To continue using '
f'Red Hat content, import a new manifest.' in expired_manifest['message']
)
# Cleanup - delete expired manifest
session.subscription.delete_manifest(
ignore_error_messages=['Danger alert: Katello::Errors::UpstreamConsumerNotFound']
)
# Message - Manifest expiring soon
# Upload non-expire manifest
target_sat.upload_manifest(function_org.id, function_sca_manifest.content)
# Initially 'Manifest expiring soon' message not found
assert not session.subscription.is_subscription_manifest_header_message_display()
# then update the 'Expire soon days' value from settings > Content
# value should be greater than 365 to get expected output message
setting_update.value = 366
setting_update = setting_update.update({'value'})
session.browser.refresh()
# Predict expire date using below formula
date = datetime.now() + timedelta(days=365)
formatted_date = date.strftime('%a %b %d %Y')
# read expire manifest message
expiring_soon = session.subscription.read_subscription_manifest_header_message_and_date()
assert 'Manifest expiring soon' in expiring_soon['header'], (
'Manifest expire alert not found'
)
assert formatted_date in expiring_soon['date']
session.subscription.refresh_manifest()
expires_date = session.subscription.read_subscription_manifest_expiration_date_only()
assert formatted_date in expires_date
# Cleanup - delete non-expired manifest
session.subscription.delete_manifest(
ignore_error_messages=['Danger alert: Katello::Errors::UpstreamConsumerNotFound']
)
def test_positive_populate_future_date_subcription(
target_sat,
function_org,
func_future_dated_subscription_manifest,
):
"""Upload manifest which has future date subscription and verify future date subscription populated
:id: 87683cfc-8e65-4392-a437-ad5d88f5f618
:expectedresults:
1. Future date subscription should populate in Subscription table
:Verifies: SAT-29203
:customerscenario: true
"""
target_sat.upload_manifest(function_org.id, func_future_dated_subscription_manifest.content)
with target_sat.ui_session() as session:
session.organization.select(function_org.name)
assert session.subscription.has_manifest, 'Manifest not uploaded'
# Get current date time and convert into date
current_datetime = datetime.now(ZoneInfo(get_localzone_name()))
current_date = current_datetime.date()
# Get subscription Start Date and compare with current date
subscriptions = session.subscription.read_subscriptions()
if not any(
datetime.strptime(sub['Start Date'], '%Y-%m-%d %H:%M:%S %Z').date() > current_date
for sub in subscriptions
):
raise AssertionError('Subscription start date is not in the future')
# Delete the manifest from Organization
session.subscription.delete_manifest(
ignore_error_messages=['Danger alert: Katello::Errors::UpstreamConsumerNotFound']
)
assert not session.subscription.has_manifest, 'Manifest was not deleted'