Beispiel #1
0
class SpotinstEMRTestCase(unittest.TestCase):
    def setUp(self):
        self.client = SpotinstClient(auth_token='dummy-token',
                                     account_id='act-1234567')
        self.mock_emr_json = self.load_emr_json()

    def create_formatted_emr_request(self, emr):
        emr_request = EMRCreationRequest(emr)

        excluded_emr_dict = self.client.exclude_missing(
            json.loads(emr_request.toJSON()))

        formatted_emr_dict = self.client.convert_json(
            excluded_emr_dict, self.client.underscore_to_camel)

        return formatted_emr_dict

    @staticmethod
    def load_emr_json():
        with open(
                os.path.join(os.path.dirname(os.path.realpath(__file__)),
                             'test_lib/input/emr.json')) as emr_json:
            return json.load(emr_json)
class SpotinstEMRTestCase(unittest.TestCase):
    def setUp(self):
        self.client = SpotinstClient(auth_token='dummy-token',
                                     account_id='act-1234567')
        self.mock_stateful_json = self.load_stateful_json()

    def create_formatted_import_stateful(self, stateful_instance):
        stateful_instance = StatefulImportRequest(stateful_instance)

        excluded_stateful_dict = self.client.exclude_missing(
            json.loads(stateful_instance.toJSON()))

        formatted_stateful_dict = self.client.convert_json(
            excluded_stateful_dict, self.client.underscore_to_camel)

        return formatted_stateful_dict

    @staticmethod
    def load_stateful_json():
        with open(
                os.path.join(os.path.dirname(os.path.realpath(__file__)),
                             'test_lib/stateful/import_stateful.json')
        ) as stateful_json:
            return json.load(stateful_json)
Beispiel #3
0
class SpotinstSubscriptionTestCase(unittest.TestCase):
    def setUp(self):
        self.client = SpotinstClient(auth_token='dummy-token',
                                     account_id='act-1234567')
        self.mock_event_subscription_json = self.load_json(
            path='test_lib/input/event/subscription.json')

    def create_formatted_event_subscription_request(self, subscription):
        subscription_request = SubscriptionRequest(subscription)

        excluded_subscription_dict = self.client.exclude_missing(
            json.loads(subscription_request.toJSON()))

        formatted_subscription_dict = self.client.convert_json(
            excluded_subscription_dict, self.client.underscore_to_camel)

        return formatted_subscription_dict

    @staticmethod
    def load_json(path):
        with open(
                os.path.join(os.path.dirname(os.path.realpath(__file__)),
                             path)) as subscription_json:
            return json.load(subscription_json)
Beispiel #4
0
class SpotinstEMRTestCase(unittest.TestCase):
    def setUp(self):
        self.client = SpotinstClient(auth_token='dummy-token',
                                     account_id='act-1234567')
        self.mock_balancer_json = self.load_json(
            "test_lib/input/mlb/balancer.json")
        self.mock_target_set_json = self.load_json(
            "test_lib/input/mlb/target_set.json")
        self.mock_target_json = self.load_json(
            "test_lib/input/mlb/target.json")
        self.mock_targets_json = self.load_json(
            "test_lib/input/mlb/targets.json")
        self.mock_listener_json = self.load_json(
            "test_lib/input/mlb/listener.json")
        self.mock_middleware_json = self.load_json(
            "test_lib/input/mlb/middleware.json")
        self.mock_routing_rule_json = self.load_json(
            "test_lib/input/mlb/routing_rule.json")

    def create_formatted_balancer_request(self, balancer):
        balancer = BalancerRequest(balancer)

        excluded_balancer_dict = self.client.exclude_missing(
            json.loads(balancer.toJSON()))

        formatted_balancer_dict = self.client.convert_json(
            excluded_balancer_dict, self.client.underscore_to_camel)

        return formatted_balancer_dict

    def create_formatted_target_set_request(self, target_set):
        target_set = TargetSetRequest(target_set)

        excluded_target_set_dict = self.client.exclude_missing(
            json.loads(target_set.toJSON()))

        formatted_target_set_dict = self.client.convert_json(
            excluded_target_set_dict, self.client.underscore_to_camel)

        return formatted_target_set_dict

    def create_formatted_target_request(self, target):
        target = TargetRequest(target)

        excluded_target_dict = self.client.exclude_missing(
            json.loads(target.toJSON()))

        formatted_target_dict = self.client.convert_json(
            excluded_target_dict, self.client.underscore_to_camel)

        return formatted_target_dict

    def create_formatted_targets_request(self, targets):
        targets = TargetsRequest(targets)

        excluded_targets_dict = self.client.exclude_missing(
            json.loads(targets.toJSON()))

        formatted_targets_dict = self.client.convert_json(
            excluded_targets_dict, self.client.underscore_to_camel)

        return formatted_targets_dict

    def create_formatted_middleware_request(self, middleware):
        middleware = MiddlewareRequest(middleware)

        excluded_middleware_dict = self.client.exclude_missing(
            json.loads(middleware.toJSON()))

        formatted_middleware_dict = self.client.convert_json(
            excluded_middleware_dict, self.client.underscore_to_camel)

        return formatted_middleware_dict

    def create_formatted_routing_rule_request(self, routing_rule):
        routing_rule = RoutingRuleRequest(routing_rule)

        excluded_routing_rule_dict = self.client.exclude_missing(
            json.loads(routing_rule.toJSON()))

        formatted_routing_rule_dict = self.client.convert_json(
            excluded_routing_rule_dict, self.client.underscore_to_camel)

        return formatted_routing_rule_dict

    def create_formatted_listener_request(self, listener):
        listener = ListenerRequest(listener)

        excluded_listener_dict = self.client.exclude_missing(
            json.loads(listener.toJSON()))

        formatted_listener_dict = self.client.convert_json(
            excluded_listener_dict, self.client.underscore_to_camel)

        return formatted_listener_dict

    @staticmethod
    def load_json(input_file):
        with open(
                os.path.join(os.path.dirname(os.path.realpath(__file__)),
                             input_file)) as output_json:
            return json.load(output_json)