示例#1
0
    def test_check_err_create_bad_dom(self):
        """
        Tests that CheckEngine produces expected CheckStatus, when checking domain error exists
        with the CustomizedAlgo creation Rest service.
        """

        # Re-activate checking rules
        CheckEngine.set_checking_rules(
            FactoryCatalogue.TYPE_CHECKING_FUNCTIONS)

        my_custom_outside_domain = self.init_rsrc_outside_domain()

        http_req = self.request_factory.post(
            path=reverse('pattern_custom_algos_dummy'),
            data=CustomizedAlgoWs(my_custom_outside_domain).to_json(),
            content_type="application/json_util")

        http_response = create_custom_algo(http_req)

        # Display the check result
        result = json_io.decode_json_from_http_response(http_response)

        self.info("response loaded={}".format(result))
        self.info("response status={}".format(http_response.status_code))

        self.assertTrue(http_response.status_code ==
                        HttpResponseFactory.BAD_REQUEST_HTTP_STATUS)
示例#2
0
    def test_find_custom_of_implem_404(self):
        """
        Tests the not found case, finding the CustomizedAlgo collection child of an implementation
          - returned status is 404 : test case when the implementation is not found
        """

        client = Client()
        m_id = 99999
        http_response = client.get(
            '/ikats/algo/implementations/{}/custom_algos'.format(m_id))

        json_io.decode_json_from_http_response(http_response)

        self.assertEqual(http_response.status_code,
                         HttpResponseFactory.NOT_FOUND_HTTP_STATUS,
                         "code != 400 (bad request)")
示例#3
0
    def test_custo_create_200(self):
        """
        Tests the nominal Creation of CustomizedAlgo: we prepare the data and then submit creation
        """

        # Preparing the data ...
        my_new_custom_algo = self.init_resource_named(
            name="custom algo for create seq3", save_in_db=False)

        data = CustomizedAlgoWs(my_new_custom_algo).to_json()

        # ... testing the service
        http_req = self.request_factory.post(
            path=reverse('pattern_custom_algos_dummy'),
            data=data,
            content_type="application/json_util")

        http_response = create_custom_algo(http_req)

        result = json_io.decode_json_from_http_response(http_response)

        self.info("!!! response loaded={} !!!".format(result))
        self.info("!!! response status={} !!!".format(
            http_response.status_code))

        self.assertTrue(http_response.status_code ==
                        HttpResponseFactory.CREATED_HTTP_STATUS)
示例#4
0
    def test_check_errors_create(self):
        """
        Tests that CheckEngine produces expected CheckStatus, when checking type error exists
        with the CustomizedAlgo creation Rest service.
        """

        client = Client()
        m_id = self.my_pseudo_impl_from_db.db_id
        http_response = client.get(
            '/ikats/algo/implementations/{}/custom_algos/?info_level=5'.format(
                m_id))

        json_io.decode_json_from_http_response(http_response)

        self.assertEqual(http_response.status_code,
                         HttpResponseFactory.BAD_REQUEST_HTTP_STATUS,
                         "code != 400 (bad request)")
示例#5
0
    def test_find_custom_of_implem_400(self):
        """
        Tests the bad request, finding the CustomizedAlgo collection child of an implementation
          - returned status is 400 when the query param 'level' is incorrect
        """

        client = Client()
        m_id = self.my_pseudo_impl_from_db.db_id
        http_response = client.get(
            '/ikats/algo/implementations/{}/custom_algos/?info_level=5'.format(
                m_id))

        json_io.decode_json_from_http_response(http_response)

        self.assertEqual(http_response.status_code,
                         HttpResponseFactory.BAD_REQUEST_HTTP_STATUS,
                         "code != 400 (bad request)")
    def test_checked_exec_errors_seq2(self):
        """
        Test run with
        - customized algo inconsistent with its implementation: 2 wrong specified values
        - run args: angle (no value overriding)
        => CheckEngine detects errors
        Note: this unit test is testing the expected error code.
        """
        angle = 1.58

        # Wrong type : string for factor
        #
        # Wrong value for phase: 5.0 is outside of the domain defined in
        # my_pseudo_impl_with_domain_from_db: [0, 1.1, 2 ]
        #
        # ... checking rule are not activated here:
        my_custom = self.init_resource_named("Custom for created at {}".format(time.time()),
                                             save_in_db=True,
                                             implem=self.my_pseudo_impl_with_domain_from_db,
                                             factor="3",
                                             phase=5.0)

        my_id = my_custom.name

        my_async = False
        my_opts = {'async': my_async, 'custo_algo': True, 'debug': True}

        # case where
        # => no parameter value is redefined
        # => only argument angle is specified
        my_args = {'angle': angle}

        my_data = {'opts': my_opts, 'args': my_args}

        # self.info("- Implem ={}".format( my_custom.implementation ) )
        self.info("- Custom ={}".format(CustomizedAlgoWs(my_custom).to_json(indent=2, level=LevelInfo.DETAIL)))
        self.info("- data ={}".format(json.dumps(obj=my_data, indent=2)))

        http_req = self.request_factory.post(path=reverse(viewname='algo_run', args=[my_id]),
                                             data=json.dumps(my_data),
                                             content_type="application/json")

        self.info("- data ={}".format(json.dumps(obj=my_data, indent=2)))
        http_response = views_algo_run(http_req, my_id)

        # Display the check result
        result = json_io.decode_json_from_http_response(http_response)

        self.info("response loaded={}".format(result))
        self.info("response status={}".format(http_response.status_code))

        self.assertTrue(http_response.status_code == HttpResponseFactory.BAD_REQUEST_HTTP_STATUS)
示例#7
0
    def test_read_custom_collec_200(self):
        """
        Tests the CustomizedAlgo collection reading Rest service: basic case without filtering criterion
        """

        client = Client()
        http_response = client.get('/ikats/algo/custom/custom_algos/')

        result = json_io.decode_json_from_http_response(http_response)
        self.info(
            "test_read_custom_collection_nominal result={}".format(result))

        self.assertTrue(
            http_response.status_code == HttpResponseFactory.OK_HTTP_STATUS)
        self.assertTrue(len(result) == CustomizedAlgoDao.objects.count())
    def test_checked_exec_errors_seq3(self):
        """
        Test run with
        - implementation: see my_pseudo_impl_with_domain_from_db
        - run args: angle + inconsistent phase + inconsistent factor

        => CheckEngine detects errors
        Note: this unit test is testing the expected error code.
        """

        angle = 1.58

        # Outside of domain
        phase = 0.9
        # Wrong type
        factor = "1.4"

        # running case with Implementation:
        #
        my_id = self.my_pseudo_impl_with_domain_from_db.db_id

        my_async = False
        my_opts = {'async': my_async, 'custo_algo': False, 'debug': True}

        # run args: angle + inconsistent phase + inconsistent factor
        #
        my_args = {'angle': angle, 'phase': phase, 'factor': factor}

        my_data = {'opts': my_opts, 'args': my_args}

        self.info("- implem ={}".format(self.my_pseudo_impl_with_domain_from_db))
        self.info("- data ={}".format(json.dumps(obj=my_data, indent=2)))

        http_req = self.request_factory.post(path=reverse(viewname='algo_run', args=[my_id]),
                                             data=json.dumps(my_data),
                                             content_type="application/json")

        self.info("- data ={}".format(json.dumps(obj=my_data, indent=2)))
        http_response = views_algo_run(http_req, my_id)

        # Display the check result
        result = json_io.decode_json_from_http_response(http_response)

        self.info("response loaded={}".format(result))
        self.info("response status={}".format(http_response.status_code))

        self.assertEquals(http_response.status_code, HttpResponseFactory.BAD_REQUEST_HTTP_STATUS)
示例#9
0
    def test_read_custom_collec_400(self):
        """
        Tests the bad request case, reading a collection of  CustomizedAlgo
          - returned status is 400

        One tested case: with query parameter info_level=5
        """

        client = Client()
        http_response = client.get(
            '/ikats/algo/custom/custom_algos/?info_level=5')

        result = json_io.decode_json_from_http_response(http_response)

        self.assertEqual(http_response.status_code,
                         HttpResponseFactory.BAD_REQUEST_HTTP_STATUS,
                         "code != 400 (bad request)")
示例#10
0
    def test_read_custom_collec_404(self):
        """
        Tests the resource not found case, reading a collection of  CustomizedAlgo
          - returned status is 404
        """

        client = Client()
        http_response = client.get(
            '/ikats/algo/custom/custom_algos/?desc="nosuchexpression"')

        result = json_io.decode_json_from_http_response(http_response)
        self.info(
            "test_read_custom_collection_nominal result={}".format(result))

        self.assertEqual(http_response.status_code,
                         HttpResponseFactory.NOT_FOUND_HTTP_STATUS,
                         "code != 404 (not found)")
示例#11
0
    def test_custo_read_400(self):
        """
        Tests the bad request case, reading one CustomizedAlgo resource
          - returned status is 400 when a query param has unexpected value:
        """

        client = Client()
        my_id = self.my_custom_algo_2_in_DB.db_id
        http_response = client.get(
            '/ikats/algo/custom/custom_algos/{}?info_level=4'.format(my_id))

        result = json_io.decode_json_from_http_response(http_response)
        self.info(
            "test_read_custom_collection_nominal result={}".format(result))

        self.assertEqual(HttpResponseFactory.BAD_REQUEST_HTTP_STATUS,
                         http_response.status_code)
示例#12
0
    def test_find_custom_of_implem_200(self):
        """
        Tests the finding of CustomizedAlgo instances having a specified parent Implementation
        """

        id_implem = self.my_pseudo_impl_from_db.db_id

        client = Client()
        http_response = client.get(
            '/ikats/algo/implementations/{}/custom_algos'.format(id_implem))

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

        result = json_io.decode_json_from_http_response(http_response)
        self.assertTrue(len(result) == 3)
        self.info("test_find_custom_of_implem_nominal result={}".format(
            json.dumps(result, indent=2)))
示例#13
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)
示例#14
0
    def test_checked_exec_nominal_seq1(self):
        """
        Tests that the nominal execution on one CustomizedAlgo consistent with its Implementation:
          - is executed in nominal mode (no tests about Python execution: tested by another Test unit)
        Note: this unit test is testing the expected error code.
        TODO: complete this test: evaluate that response body is empty
        """
        angle = 1.58

        my_custom = self.init_resource_named("Custom for created at {}".format(time.time()),
                                             save_in_db=True)

        my_name = my_custom.name

        my_async = False
        my_opts = {'async': my_async, 'custo_algo': my_name, 'debug': True}

        my_args = {'angle': angle}

        my_data = {'opts': my_opts, 'args': my_args}

        # self.info("- Implem ={}".format( my_custom.implementation ) )
        self.info("- Custom ={}".format(CustomizedAlgoWs(my_custom).to_json(indent=2, level=LevelInfo.DETAIL)))
        self.info("- data ={}".format(json.dumps(obj=my_data, indent=2)))

        http_req = self.request_factory.post(path=reverse(viewname='algo_run', args=[my_name]),
                                             data=json.dumps(my_data),
                                             content_type="application/json")

        self.info("- data ={}".format(json.dumps(obj=my_data, indent=2)))
        http_response = views_algo_run(http_req, my_name)

        # Display the check result
        result = json_io.decode_json_from_http_response(http_response)

        self.info("response loaded={}".format(result))
        self.info("response status={}".format(http_response.status_code))

        self.assertTrue(http_response.status_code == HttpResponseFactory.OK_HTTP_STATUS)
示例#15
0
    def test_checked_exec_nominal_seq4(self):
        """
        Test run with
          - implementation: see my_pseudo_impl_with_domain_from_db
          - run args: angle + consistent phase + consistent factor

        Note: this unit test is testing the expected error code.
        TODO: complete this test: evaluate that response body is empty
        """
        angle = 1.58
        phase = 1.1
        factor = 1.4

        my_id = self.my_pseudo_impl_with_domain_from_db.db_id

        my_async = False
        my_opts = {'async': my_async, 'custo_algo': False, 'debug': True}

        my_args = {'angle': angle, 'phase': phase, 'factor': factor}

        my_data = {'opts': my_opts, 'args': my_args}

        self.info("- implem ={}".format(self.my_pseudo_impl_with_domain_from_db))
        self.info("- data ={}".format(json.dumps(obj=my_data, indent=2)))

        http_req = self.request_factory.post(path=reverse(viewname='algo_run', args=[my_id]),
                                             data=json.dumps(my_data),
                                             content_type="application/json")

        self.info("- data ={}".format(json.dumps(obj=my_data, indent=2)))
        http_response = views_algo_run(http_req, my_id)

        # Display the check result
        result = json_io.decode_json_from_http_response(http_response)

        self.info("response loaded={}".format(result))
        self.info("response status={}".format(http_response.status_code))

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