def test_serialize(self):
        # Tests the serialize function result against known result

        try:
            subscription_collection = SubscriptionCollection({})
        except Exception as e:
            self.fail("Failed to instantiate SubscriptionCollection class."
                      " Error: {}".format(e))

        try:
            result = json.loads(subscription_collection.serialize())
        except Exception as e:
            self.fail("Failed to serialize. Error: ".format(e))

        self.assertEqual(self.subscription_collection_mockup, result)
    def test_class_instantiation(self):
        # Tests if class is correctly instantiated and validated

        try:
            subscription = SubscriptionCollection({})
        except Exception as e:
            self.fail("Failed to instantiate SubscriptionCollection class."
                      " Error: {}".format(e))
        self.assertIsInstance(subscription, SubscriptionCollection)
def get_subscription_collection():
    """Get the Redfish Subscription Collection.

        Get method to return SubscriptionCollection JSON when
        /redfish/v1/EventService/EventSubscriptions is requested.
        Returns:
                JSON: JSON with EventSubscriptions.
    """

    # Build Subscription Collection object and validates it
    sc = SubscriptionCollection(util.get_all_subscriptions())

    return ResponseBuilder.success(sc)
def get_subscription_collection():
    """Get the Redfish Subscription Collection.

        Get method to return SubscriptionCollection JSON when
        /redfish/v1/EventService/EventSubscriptions is requested.
        Returns:
                JSON: JSON with EventSubscriptions.
    """
    try:
        # Build Subscription Collection object and validates it
        sc = SubscriptionCollection(util.all_subscriptions)

        # Build redfish json
        json_str = sc.serialize()

        # Build response and returns
        return Response(response=json_str,
                        status=status.HTTP_200_OK,
                        mimetype="application/json")
    except Exception as e:
        # In case of error print exception and abort
        logging.exception(e)
        return abort(status.HTTP_500_INTERNAL_SERVER_ERROR)