def test_validate_missing_file(self, mock_show_warning, mock_isfile): file_path = 'testtesttest' mock_isfile.return_value = False pfh = p_and_s.ParamsFileHandler(file_path) with self.assertRaises(p_and_s.rn_except.MissingParamsFilePopupError): pfh.validate_params_file()
def test_validate_missing_fields(self, mock_read_dictionary, mock_show_warning, mock_isfile): file_path = 'testtesttest' test_params = { "RNDataStorePath": '/home/tw-johns/Roadnet/database_files', "DbName": 'roadnet_demo.sqlite', "RNPolyEdit": 'true', "RNsrwr": 'true', "Blank": 'true', "UserName": '******', "RAMP_output_directory": '', "PreventOverlappingPolygons": 'true', "ShouldNotBeUsed": 'should not appear in output' } mock_isfile.return_value = True mock_read_dictionary.return_value = test_params pfh = p_and_s.ParamsFileHandler(file_path) with self.assertRaises(p_and_s.rn_except.InvalidParamsKeysPopupError): pfh.validate_params_file()
def test_read_to_dictionary(self, mock_update_tree): file_path = 'testtesttest' pfh = p_and_s.ParamsFileHandler(file_path) pfh.root = self.test_root params = pfh.read_to_dictionary() expected = { "RNDataStorePath": '/home/tw-johns/Roadnet/database_files', "DbName": 'roadnet_demo.sqlite', "RNPolyEdit": 'true', "RNsrwr": 'true', "Language": 'ENG', "UserName": '******' } mock_update_tree.assert_called_once_with() for key in expected: self.assertEqual( params[key], expected[key], "Wrong value read for params {}: {}, not {}".format( key, params[key], expected[key]))
def test_update_xml_file(self, mock_update_tree): file_path = 'testtesttest' pfh = p_and_s.ParamsFileHandler(file_path) pfh.root = self.test_root pfh.tree = MagicMock() test_params = { "RNDataStorePath": '/home/tw-johns/Roadnet/database_files', "DbName": 'roadnet_demo.sqlite', "RNPolyEdit": 'true', "Language": 'ENG', "RNsrwr": 'true', "Blank": 'true', "UserName": '******', "ShouldNotBeUsed": 'should not appear in output' } m = mock_open() with patch('Roadnet.params_and_settings.open', m, create=True): pfh.update_xml_file(test_params) # Check that the file is opened m.assert_called_once_with(file_path, 'w') mock_outfile = m() # Check data is written to correct file pfh.tree.assert_has_calls([call.write(mock_outfile)])
def test_init(self): file_path = 'testtesttest' pfh = p_and_s.ParamsFileHandler(file_path) self.assertEqual( pfh.xmlfile_path, file_path, "xmlfile_path was not {} ({})".format(file_path, pfh.xmlfile_path))