Пример #1
0
 def test_host_subs_with_err(self):
     """Test the host subscriptons method with bad status code."""
     sub_url = 'https://{sat_host}:{port}/' \
         'api/v2/hosts/{host_id}/subscriptions'
     with requests_mock.Mocker() as mocker:
         url = construct_url(url=sub_url, sat_host='1.2.3.4', host_id=1)
         mocker.get(url, status_code=500)
         with self.assertRaises(SatelliteException):
             host_subscriptions(self.scan_task, sub_url, None, 1)
Пример #2
0
 def test_host_subs_err_nojson(self):
     """Test the host subscriptons method with bad code and not json."""
     sub_url = 'https://{sat_host}:{port}/' \
         'api/v2/hosts/{host_id}/subscriptions'
     with requests_mock.Mocker() as mocker:
         url = construct_url(url=sub_url, sat_host='1.2.3.4', host_id=1)
         mocker.get(url, status_code=404, text='error message')
         subs = host_subscriptions(self.scan_task, sub_url, None, 1)
         self.assertEqual(subs, {'entitlements': []})
Пример #3
0
 def test_host_not_subscribed(self):
     """Test the host subscriptons method for not subscribed error."""
     sub_url = 'https://{sat_host}:{port}/' \
         'api/v2/hosts/{host_id}/subscriptions'
     with requests_mock.Mocker() as mocker:
         url = construct_url(url=sub_url, sat_host='1.2.3.4',
                             host_id=1)
         err_msg = {
             'displayMessage': 'Host has not been registered '
                               'with subscription-manager',
             'errors': ['Host has not been registered'
                        ' with subscription-manager']
             }  # noqa
         mocker.get(url, status_code=400, json=err_msg)
         subs = host_subscriptions(self.scan_task, sub_url, None, 1)
         self.assertEqual(subs, {'entitlements': []})
Пример #4
0
 def test_host_subscriptons(self):
     """Test the host subscriptons method."""
     sub_url = 'https://{sat_host}:{port}/' \
         'api/v2/hosts/{host_id}/subscriptions'
     with requests_mock.Mocker() as mocker:
         url = construct_url(url=sub_url, sat_host='1.2.3.4', host_id=1)
         jsonresult = {
             'results': [{
                 'amount': 1,
                 'name': 'Satellite Tools 6.3',
                 'start_date': '2017-12-01 14:50:59 UTC',
                 'end_date': '2047-11-24 14:50:59 UTC',
                 'product_name': 'Satellite Tools 6.3',
             }, {
                 'quantity_consumed': 1,
                 'name': 'Employee SKU',
                 'start_date': '2016-03-24 04:00:00 UTC',
                 'end_date': '2022-01-01 04:59:59 UTC',
                 'account_number': 1212729,
                 'contract_number': 10913844,
                 'type': 'ENTITLEMENT_DERIVED',
                 'product_name': 'Employee SKU',
             }]
         }
         mocker.get(url, status_code=200, json=jsonresult)
         subs = host_subscriptions(jsonresult)
         expected = {
             'entitlements': [{
                 'derived_entitlement': False,
                 'name': 'Satellite Tools 6.3',
                 'amount': 1,
                 'account_number': None,
                 'contract_number': None,
                 'start_date': '2017-12-01 14:50:59 UTC',
                 'end_date': '2047-11-24 14:50:59 UTC'
             }, {
                 'derived_entitlement': True,
                 'name': 'Employee SKU',
                 'amount': 1,
                 'account_number': 1212729,
                 'contract_number': 10913844,
                 'start_date': '2016-03-24 04:00:00 UTC',
                 'end_date': '2022-01-01 04:59:59 UTC'
             }]
         }
         self.assertEqual(subs, expected)