Beispiel #1
0
 def subscription_json_parsing_test(self):
     """Test the subscription JSON parsing method of ParseAttachedSubscriptionsTask."""
     parse_method = ParseAttachedSubscriptionsTask._parse_subscription_json
     # the method should be able to survive the RHSM DBus API returning an empty string,
     # as empty list of subscriptions is a lesser issue than crashed installation
     self.assertEqual(parse_method(""), [])
     # try parsing a json file containing two subscriptions
     # - to make this look sane, we write it as a dict that we then convert to JSON
     subscription_dict = {
         "consumed": [{
             "subscription_name": "Foo Bar Beta",
             "service_level": "very good",
             "sku": "ABC1234",
             "contract": "12345678",
             "starts": "05/12/20",
             "ends": "05/12/21",
             "quantity_used": "1"
         }, {
             "subscription_name": "Foo Bar Beta NG",
             "service_level": "even better",
             "sku": "ABC4321",
             "contract": "87654321",
             "starts": "now",
             "ends": "never",
             "quantity_used": "1000"
         }]
     }
     subscription_json = json.dumps(subscription_dict)
     expected_structs = [{
         "name": "Foo Bar Beta",
         "service-level": "very good",
         "sku": "ABC1234",
         "contract": "12345678",
         "start-date": "May 12, 2020",
         "end-date": "May 12, 2021",
         "consumed-entitlement-count": 1
     }, {
         "name": "Foo Bar Beta NG",
         "service-level": "even better",
         "sku": "ABC4321",
         "contract": "87654321",
         "start-date": "now",
         "end-date": "never",
         "consumed-entitlement-count": 1000
     }]
     structs = get_native(
         AttachedSubscription.to_structure_list(
             parse_method(subscription_json)))
     # check the content of the AttachedSubscription corresponds to the input JSON,
     # including date formatting
     self.assertEqual(structs, expected_structs)
Beispiel #2
0
 def AttachedSubscriptions(self) -> List[Structure]:
     """Return a list of DBus structures holding data about attached subscriptions."""
     return AttachedSubscription.to_structure_list(
         self.implementation.attached_subscriptions)