def test_codec_dumps_raises_exception_on_invalid_schema(): """ Verify that codec dumps() with invalid schema raise exception """ csp_config = csp_config_for_test() csp_config.interface = 'http://schema.skatelescope.org/ska-csp-configure/3.0' with pytest.raises(JsonValidationError): CODEC.dumps(csp_config)
def test_configure_request_raises_exception_on_invalid_csp_object(): """ Verify that codec dumps() with invalid schema raise exception """ configure_request = CODEC.loads(ConfigureRequest, VALID_CONFIGURE_REQUEST) configure_request.csp.interface = \ 'http://schema.skatelescope.org/ska-csp-configure/3.0' with pytest.raises(JsonValidationError): CODEC.dumps(configure_request, strictness=2)
def test_codec_loads_from_file_without_schema_validation_for_old_json(mock_fn): """ Verify that the schema validation does not apply when it is set to false for pre ADR-18 JSON schema """ cwd, _ = os.path.split(__file__) test_new_json_data = os.path.join(cwd, "testfile_sample_configure.json") CODEC.load_from_file(ConfigureRequest, test_new_json_data, False) assert mock_fn.call_count == 0 mock_fn.assert_not_called()
def test_loads_from_file_with_invalid_schema_and_validation_set_to_true(): """ Verify that the codec unmarshalls objects correctly with schema validation and Test it with loading a invalid ADR18-configure request from a JSON file """ cwd, _ = os.path.split(__file__) test_new_json_data = os.path.join( cwd, "testfile_invalid_configure_ADR_18.json") with pytest.raises(JsonValidationError): CODEC.load_from_file(ConfigureRequest, test_new_json_data)
def test_read_a_file_from_disk(): """ Test for loading a configure request from a JSON file """ cwd, _ = os.path.split(__file__) test_data = os.path.join(cwd, "testfile_sample_configure.json") result = CODEC.load_from_file(ConfigureRequest, test_data) dish_config = DishConfiguration(ReceiverBand.BAND_1) assert result.dish == dish_config test_new_json_data = os.path.join(cwd, "testfile_sample_configure_ADR_18.json") result_data = CODEC.load_from_file(ConfigureRequest, test_new_json_data) dish_config = DishConfiguration(ReceiverBand.BAND_1) assert result_data.dish == dish_config
def test_codec_loads_with_schema_validation_for_csp(): """ Verify that the codec unmarshalls objects correctly with schema validation. """ csp_config = csp_config_for_test() unmarshalled = CODEC.loads(CSPConfiguration, VALID_CSP_SCHEMA) assert csp_config == unmarshalled
def test_codec_dumps_with_schema_validation_for_csp(): """ Verify that the codec marshalls csp objects to JSON with schema validation. """ expected = VALID_CSP_SCHEMA csp_config = csp_config_for_test() marshalled = CODEC.dumps(csp_config) assert json_is_equal(marshalled, expected)
def oet_compose_sub(): cdm_file_path = 'resources/test_data/OET_integration/example_allocate.json' LOGGER.info("cdm_file_path :" + str(cdm_file_path)) update_resource_config_file(cdm_file_path) cdm_request_object = cdm_CODEC.load_from_file(AssignResourcesRequest, cdm_file_path) cdm_request_object.dish.receptor_ids = [str(x).zfill(4) for x in range(1, 5)] subarray = SubArray(1) LOGGER.info("Allocated Subarray is :" + str(subarray)) return subarray.allocate_from_cdm(cdm_request_object)
def assign(): sdp_block = update_resource_config_file(file) resource_request: AssignResourcesRequest = cdm_CODEC.load_from_file( AssignResourcesRequest, file) resource_request.dish.receptor_ids = [ str(x).zfill(4) for x in range(1, dishes + 1) ] self.SubArray.allocate_from_cdm(resource_request) return sdp_block
def test_codec_dumps(): """ Verify that the codec marshalls dish & sdp objects to JSON. """ sdp_config = VALID_SDP_OBJECT expected = VALID_MID_ASSIGNRESOURCESREQUEST_JSON obj = AssignResourcesRequest( subarray_id=1, dish_allocation=DishAllocation(receptor_ids=["0001", "0002"]), sdp_config=sdp_config) marshalled = CODEC.dumps(obj) assert json_is_equal(marshalled, expected)
def test_codec_loads(): """ Verify that the codec unmarshalls objects correctly. """ sdp_config = VALID_SDP_OBJECT unmarshalled = CODEC.loads(AssignResourcesRequest, VALID_MID_ASSIGNRESOURCESREQUEST_JSON) expected = AssignResourcesRequest.from_dish( 1, DishAllocation(receptor_ids=["0001", "0002"]), sdp_config=sdp_config, ) assert expected == unmarshalled
def test_codec_loads_from_file_with_schema_validation(mock_fn): """ Verify that the codec unmarshalls objects correctly with schema validation and Test it with loading a valid ADR18-configure request from a JSON file """ csp_config = csp_config_for_test() cwd, _ = os.path.split(__file__) test_new_json_data = os.path.join(cwd, "testfile_sample_configure_ADR_18.json") result_data = CODEC.load_from_file(ConfigureRequest, test_new_json_data) assert result_data.csp == csp_config assert mock_fn.call_count == 1 mock_fn.assert_called_once()
def test_loads_from_file_with_invalid_schema_and_validation_set_to_false( mock_fn): """ Verify that the codec unmarshalls objects correctly without schema validation and Test it with loading a invalid ADR18-configure request from a JSON file """ cwd, _ = os.path.split(__file__) test_new_json_data = os.path.join( cwd, "testfile_invalid_configure_ADR_18.json") result_data = CODEC.load_from_file(ConfigureRequest, test_new_json_data, False) assert result_data.csp.subarray_config is None assert mock_fn.call_count == 0 mock_fn.assert_not_called()
def test_configure_request_raises_exception_when_loads_invalid_csp_schema(): """ Verify that codec loads() with invalid schema raise exception """ with pytest.raises(JsonValidationError): CODEC.loads(ConfigureRequest, INVALID_CONFIGURE_REQUEST)
def test_codec_loads_raises_exception_on_invalid_schema(): """ Verify that codec loads() with invalid schema raise exception """ with pytest.raises(JsonValidationError): CODEC.loads(CSPConfiguration, INVALID_CSP_SCHEMA)