Example #1
0
    def test_load_from_dict_seq4(self):
        """
        Nominal test of load_from_dict()
        """

        my_custom_ws = CustomizedAlgoWs(self.my_custom_algo_in_DB)
        normal_dict = my_custom_ws.to_dict(level=LevelInfo.NORMAL)

        self.info(
            "- Evaluating my_custom_algo_in_DB => CustomizedAlgoWs.load_from_dict(...)"
        )
        loaded_ws_resource = CustomizedAlgoWs.load_from_dict(normal_dict)

        my_business_custo = loaded_ws_resource.get_customized_algo()
        self.info(" - uploaded custom_algo={}".format(my_business_custo))

        self.assertTrue(my_business_custo == self.my_custom_algo_in_DB)
Example #2
0
    def test_custo_read_200(self):
        """
        Tests the nominal reading of resource initialized in test DB: self.my_custom_algo_in_DB
        """

        my_id = self.my_custom_algo_in_DB.db_id

        http_response = get_custom_algo(http_request=HttpRequest(),
                                        customized_algo_id=my_id,
                                        query_dict=None)

        self.assertTrue(
            http_response.status_code == HttpResponseFactory.OK_HTTP_STATUS)

        # Check result content: ... self.my_custom_algo_in_DB == biz_result
        dict_result = json_io.decode_json_from_http_response(http_response)

        ws_result = CustomizedAlgoWs.load_from_dict(dict_result)

        biz_result = ws_result.get_customized_algo()

        self.assertTrue(self.my_custom_algo_in_DB == biz_result)
Example #3
0
    def convert_to_business_custo_algo(cls, custom_algo_from_json):
        """
        Returns the business CustomizedAlgo resource from the equivalent json string.
        the customized algorithm

        :param custom_algo_from_json: json input encoding the resource
        :type custom_algo_from_json: str or equivalent json-friendly dict
        :return: the business resource CustomizedAlgo
        :rtype: CustomizedAlgo
        """
        if type(custom_algo_from_json) is str:
            my_dict = json.loads(custom_algo_from_json)
        elif type(custom_algo_from_json) is dict:
            my_dict = custom_algo_from_json
        else:
            msg = "Unexpected type={} for arg custom_algo_from_json in convert_to_business_custo_algo()"
            raise IkatsException(
                msg.format(type(custom_algo_from_json).__name__))

        my_ws_custo_algo = CustomizedAlgoWs.load_from_dict(my_dict)

        return my_ws_custo_algo.get_customized_algo()