本文整理汇总了Python中mgi.tests.DataHandler.get_xsd方法的典型用法代码示例。如果您正苦于以下问题:Python DataHandler.get_xsd方法的具体用法?Python DataHandler.get_xsd怎么用?Python DataHandler.get_xsd使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mgi.tests.DataHandler
的用法示例。
在下文中一共展示了DataHandler.get_xsd方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ParserRemoveAnnotationTestSuite
# 需要导入模块: from mgi.tests import DataHandler [as 别名]
# 或者: from mgi.tests.DataHandler import get_xsd [as 别名]
class ParserRemoveAnnotationTestSuite(TestCase):
"""
"""
def setUp(self):
annotation_data = join('curate', 'tests', 'data', 'parser', 'utils', 'annotation')
self.annotation_data_handler = DataHandler(annotation_data)
self.namespaces = {
'xs': SCHEMA_NAMESPACE
}
xsd_etree = self.annotation_data_handler.get_xsd('not_annot')
self.xsd_xpath = '/xs:schema/xs:complexType/xs:sequence'
self.expected_xsd = xsd_etree.xpath(self.xsd_xpath, namespaces=self.namespaces)[0]
def test_annotation_is_removed(self):
annotated_etree = self.annotation_data_handler.get_xsd('annot')
# annotated_etree = etree.ElementTree(annotated_schema)
annotated_element = annotated_etree.xpath(self.xsd_xpath, namespaces=self.namespaces)[0]
remove_annotations(annotated_element)
self.assertTrue(are_equals(annotated_element, self.expected_xsd))
def test_no_annotation_no_change(self):
not_annotated_etree = self.annotation_data_handler.get_xsd('not_annot')
not_annotated_element = not_annotated_etree.xpath(self.xsd_xpath, namespaces=self.namespaces)[0]
remove_annotations(not_annotated_element)
self.assertTrue(are_equals(not_annotated_element, self.expected_xsd))
示例2: ParserHasModuleTestSuite
# 需要导入模块: from mgi.tests import DataHandler [as 别名]
# 或者: from mgi.tests.DataHandler import get_xsd [as 别名]
class ParserHasModuleTestSuite(TestCase):
"""
"""
def _save_module_to_db(self):
# FIXME module is not saved in the right database
module = Module()
module.name = "registered_module"
module.url = "registered_module"
module.view = "registered_module"
module.save()
def setUp(self):
# connect to test database
# self.db_name = "mgi_test"
# disconnect()
# connect(self.db_name, port=27018)
module_data = join("utils", "XSDParser", "tests", "data", "parser", "utils", "modules")
self.module_data_handler = DataHandler(module_data)
self.request = HttpRequest()
engine = import_module("django.contrib.sessions.backends.db")
session_key = None
self.request.session = engine.SessionStore(session_key)
from utils.XSDParser import parser
from curate.ajax import load_config
parser.load_config(self.request, load_config())
def test_element_is_module_registered(self):
# expect true
self._save_module_to_db()
xsd_tree = self.module_data_handler.get_xsd("registered_module")
xsd_element = xsd_tree.getroot()
has_module_result = has_module(self.request, xsd_element)
self.assertTrue(has_module_result)
def test_element_is_module_not_registered(self):
# expect false
xsd_tree = self.module_data_handler.get_xsd("unregistered_module")
xsd_element = xsd_tree.getroot()
has_module_result = has_module(self.request, xsd_element)
self.assertFalse(has_module_result)
def test_element_is_not_module(self):
# expect false
xsd_tree = self.module_data_handler.get_xsd("no_module")
xsd_element = xsd_tree.getroot()
has_module_result = has_module(self.request, xsd_element)
self.assertFalse(has_module_result)
示例3: ParserManageOccurencesTestSuite
# 需要导入模块: from mgi.tests import DataHandler [as 别名]
# 或者: from mgi.tests.DataHandler import get_xsd [as 别名]
class ParserManageOccurencesTestSuite(TestCase):
"""
"""
def setUp(self):
occurs_data = join('curate', 'tests', 'data', 'parser', 'utils', 'manage_occurs')
self.occurs_data_handler = DataHandler(occurs_data)
def test_element_with_min_occurs_parsable(self):
xsd_tree = self.occurs_data_handler.get_xsd('min_occurs_parsable')
xsd_element = xsd_tree.getroot()
(min_occ, max_occ) = manage_occurences(xsd_element)
self.assertEqual(min_occ, 1)
def test_element_with_max_occurs_unbounded(self):
xsd_tree = self.occurs_data_handler.get_xsd('max_occurs_unbounded')
xsd_element = xsd_tree.getroot()
(min_occ, max_occ) = manage_occurences(xsd_element)
self.assertEqual(max_occ, -1)
def test_element_with_max_occurs_parsable(self):
xsd_tree = self.occurs_data_handler.get_xsd('max_occurs_parsable')
xsd_element = xsd_tree.getroot()
(min_occ, max_occ) = manage_occurences(xsd_element)
self.assertEqual(max_occ, 5)
示例4: ParserRemoveAnnotationTestSuite
# 需要导入模块: from mgi.tests import DataHandler [as 别名]
# 或者: from mgi.tests.DataHandler import get_xsd [as 别名]
class ParserRemoveAnnotationTestSuite(TestCase):
"""
"""
def setUp(self):
annotation_data = join("utils", "XSDParser", "tests", "data", "parser", "utils", "annotation")
self.annotation_data_handler = DataHandler(annotation_data)
self.namespaces = {"xs": SCHEMA_NAMESPACE}
xsd_etree = self.annotation_data_handler.get_xsd("not_annot")
self.xsd_xpath = "/xs:schema/xs:complexType/xs:sequence"
self.expected_xsd = xsd_etree.xpath(self.xsd_xpath, namespaces=self.namespaces)[0]
def test_annotation_is_removed(self):
annotated_etree = self.annotation_data_handler.get_xsd("annot")
# annotated_etree = etree.ElementTree(annotated_schema)
annotated_element = annotated_etree.xpath(self.xsd_xpath, namespaces=self.namespaces)[0]
remove_annotations(annotated_element)
self.assertTrue(are_equals(annotated_element, self.expected_xsd))
def test_no_annotation_no_change(self):
not_annotated_etree = self.annotation_data_handler.get_xsd("not_annot")
not_annotated_element = not_annotated_etree.xpath(self.xsd_xpath, namespaces=self.namespaces)[0]
remove_annotations(not_annotated_element)
self.assertTrue(are_equals(not_annotated_element, self.expected_xsd))
示例5: ParserReloadSimpleContentTestSuite
# 需要导入模块: from mgi.tests import DataHandler [as 别名]
# 或者: from mgi.tests.DataHandler import get_xsd [as 别名]
class ParserReloadSimpleContentTestSuite(TestCase):
"""
"""
def setUp(self):
simple_content_data = join('utils', 'XSDParser', 'tests', 'data', 'parser', 'simple_content')
self.simple_content_data_handler = DataHandler(simple_content_data)
self.maxDiff = None
self.request = HttpRequest()
engine = import_module('django.contrib.sessions.backends.db')
session_key = None
self.request.session = engine.SessionStore(session_key)
self.request.session['curate_edit'] = True # Data edition
self.request.session['nb_html_tags'] = 0
self.request.session['mapTagID'] = {}
self.request.session['nbChoicesID'] = 0
self.request.session['keys'] = {}
self.request.session['keyrefs'] = {}
# set default namespace
self.namespace = {
'xs': SCHEMA_NAMESPACE
}
self.request.session['defaultPrefix'] = 'xs'
self.request.session['namespaces'] = self.namespace
from utils.XSDParser import parser
from curate.ajax import load_config
parser.load_config(self.request, load_config())
def test_restriction(self):
xsd_files = join('restriction', 'basic')
xsd_tree = self.simple_content_data_handler.get_xsd(xsd_files)
xsd_element = xsd_tree.xpath('/xs:schema/xs:complexType/xs:simpleContent', namespaces=self.namespace)[0]
xml_tree = self.simple_content_data_handler.get_xml(xsd_files)
result_string = generate_simple_content(self.request, xsd_element, xsd_tree, full_path='/root',
default_value='child0', edit_data_tree=xml_tree)
expected_element = self.simple_content_data_handler.get_json(xsd_files + '.reload')
self.assertDictEqual(result_string[1], expected_element)
def test_extension(self):
xsd_files = join('extension', 'basic')
xsd_tree = self.simple_content_data_handler.get_xsd(xsd_files)
xsd_element = xsd_tree.xpath('/xs:schema/xs:complexType/xs:simpleContent', namespaces=self.namespace)[0]
xml_tree = self.simple_content_data_handler.get_xml(xsd_files)
xml_value = xml_tree.xpath("/root", namespaces=self.namespace)[0].text
result_string = generate_simple_content(self.request, xsd_element, xsd_tree, full_path='/root',
default_value=xml_value, edit_data_tree=xml_tree)
expected_element = self.simple_content_data_handler.get_json(xsd_files + '.reload')
self.assertDictEqual(result_string[1], expected_element)
示例6: ParserManageOccurencesTestSuite
# 需要导入模块: from mgi.tests import DataHandler [as 别名]
# 或者: from mgi.tests.DataHandler import get_xsd [as 别名]
class ParserManageOccurencesTestSuite(TestCase):
"""
"""
def setUp(self):
occurs_data = join("utils", "XSDParser", "tests", "data", "parser", "utils", "manage_occurs")
self.occurs_data_handler = DataHandler(occurs_data)
def test_element_with_min_occurs_parsable(self):
xsd_tree = self.occurs_data_handler.get_xsd("min_occurs_parsable")
xsd_element = xsd_tree.getroot()
(min_occ, max_occ) = manage_occurences(xsd_element)
self.assertEqual(min_occ, 1)
def test_element_with_max_occurs_unbounded(self):
xsd_tree = self.occurs_data_handler.get_xsd("max_occurs_unbounded")
xsd_element = xsd_tree.getroot()
(min_occ, max_occ) = manage_occurences(xsd_element)
self.assertEqual(max_occ, -1)
def test_element_with_max_occurs_parsable(self):
xsd_tree = self.occurs_data_handler.get_xsd("max_occurs_parsable")
xsd_element = xsd_tree.getroot()
(min_occ, max_occ) = manage_occurences(xsd_element)
self.assertEqual(max_occ, 5)
示例7: ParserCreateComplexContentTestSuite
# 需要导入模块: from mgi.tests import DataHandler [as 别名]
# 或者: from mgi.tests.DataHandler import get_xsd [as 别名]
class ParserCreateComplexContentTestSuite(TestCase):
"""
"""
# FIXME restriction for complexContent are not working
def setUp(self):
extension_data = join('curate', 'tests', 'data', 'parser', 'complex_content')
self.extension_data_handler = DataHandler(extension_data)
self.maxDiff = None
self.request = HttpRequest()
engine = import_module('django.contrib.sessions.backends.db')
session_key = None
self.request.session = engine.SessionStore(session_key)
self.request.session['curate_edit'] = False # Data edition
self.request.session['nb_html_tags'] = 0
self.request.session['mapTagID'] = {}
self.request.session['nbChoicesID'] = 0
# set default namespace
namespace = "http://www.w3.org/2001/XMLSchema"
self.namespace = "{" + namespace + "}"
self.request.session['defaultPrefix'] = 'xs'
self.request.session['namespaces'] = {'xs': namespace}
def test_create_restriction(self):
xsd_files = join('restriction', 'basic')
xsd_tree = self.extension_data_handler.get_xsd(xsd_files)
xsd_element = xsd_tree.xpath('/xs:schema/xs:element/xs:complexType/xs:complexContent',
namespaces=self.request.session['namespaces'])[0]
result_string = generate_complex_content(self.request, xsd_element, xsd_tree, full_path='')
# print result_string
expected_dict = self.extension_data_handler.get_json(xsd_files)
self.assertDictEqual(result_string[1], expected_dict)
# result_string = '<div>' + result_string[0] + '</div>'
# result_html = etree.fromstring(result_string[0])
# expected_html = self.extension_data_handler.get_html(xsd_files)
#
# self.assertTrue(are_equals(result_html, expected_html))
def test_create_extension(self):
xsd_files = join('extension', 'basic')
xsd_tree = self.extension_data_handler.get_xsd(xsd_files)
xsd_element = xsd_tree.xpath('/xs:schema/xs:element/xs:complexType/xs:complexContent',
namespaces=self.request.session['namespaces'])[0]
result_string = generate_complex_content(self.request, xsd_element, xsd_tree, full_path='')
# print result_string
expected_dict = self.extension_data_handler.get_json(xsd_files)
self.assertDictEqual(result_string[1], expected_dict)
示例8: ParserCreateSimpleTypeTestSuite
# 需要导入模块: from mgi.tests import DataHandler [as 别名]
# 或者: from mgi.tests.DataHandler import get_xsd [as 别名]
class ParserCreateSimpleTypeTestSuite(TestCase):
"""
"""
def setUp(self):
simple_type_data = join('utils', 'XSDParser', 'tests', 'data', 'parser', 'simple_type')
self.simple_type_data_handler = DataHandler(simple_type_data)
self.maxDiff = None
self.request = HttpRequest()
engine = import_module('django.contrib.sessions.backends.db')
session_key = None
self.request.session = engine.SessionStore(session_key)
self.request.session['curate_edit'] = False # Data edition
self.request.session['nb_html_tags'] = 0
self.request.session['mapTagID'] = {}
self.request.session['nbChoicesID'] = 0
self.request.session['implicit_extension'] = True
# set default namespace
namespace = "http://www.w3.org/2001/XMLSchema"
self.namespace = "{" + namespace + "}"
self.request.session['defaultPrefix'] = 'xs'
self.request.session['namespaces'] = {'xs': namespace}
from utils.XSDParser import parser
from curate.ajax import load_config
parser.load_config(self.request, load_config())
def test_create_restriction(self):
xsd_files = join('restriction', 'basic')
xsd_tree = self.simple_type_data_handler.get_xsd(xsd_files)
xsd_element = xsd_tree.xpath('/xs:schema/xs:simpleType', namespaces=self.request.session['namespaces'])[0]
result_string = generate_simple_type(self.request, xsd_element, xsd_tree, full_path='')
# print result_string
expected_dict = self.simple_type_data_handler.get_json(xsd_files)
self.assertDictEqual(result_string[1], expected_dict)
# result_html = etree.fromstring(result_string[0])
# expected_html = self.simple_type_data_handler.get_html(xsd_files)
#
# self.assertTrue(are_equals(result_html, expected_html))
def test_create_list(self):
xsd_files = join('list', 'basic')
xsd_tree = self.simple_type_data_handler.get_xsd(xsd_files)
xsd_element = xsd_tree.xpath('/xs:schema/xs:simpleType', namespaces=self.request.session['namespaces'])[0]
result_string = generate_simple_type(self.request, xsd_element, xsd_tree, full_path='')
expected_dict = self.simple_type_data_handler.get_json(xsd_files)
self.assertDictEqual(result_string[1], expected_dict)
示例9: ParserCreateRestrictionTestSuite
# 需要导入模块: from mgi.tests import DataHandler [as 别名]
# 或者: from mgi.tests.DataHandler import get_xsd [as 别名]
class ParserCreateRestrictionTestSuite(TestCase):
"""
"""
def setUp(self):
restriction_data = join('utils', 'XSDParser', 'tests', 'data', 'parser', 'restriction')
self.restriction_data_handler = DataHandler(restriction_data)
self.request = HttpRequest()
engine = import_module('django.contrib.sessions.backends.db')
session_key = None
self.request.session = engine.SessionStore(session_key)
self.maxDiff = None
self.request.session['curate_edit'] = False # Data edition
self.request.session['nb_html_tags'] = 0
self.request.session['mapTagID'] = {}
self.request.session['nbChoicesID'] = 0
# set default namespace
self.namespace = {
'xs': SCHEMA_NAMESPACE
}
self.request.session['defaultPrefix'] = 'xs'
self.request.session['namespaces'] = self.namespace
from utils.XSDParser import parser
from curate.ajax import load_config
parser.load_config(self.request, load_config())
def test_enumeration(self):
xsd_files = join('enumeration', 'basic')
xsd_tree = self.restriction_data_handler.get_xsd(xsd_files)
xsd_element = xsd_tree.xpath('/xs:schema/xs:simpleType/xs:restriction',
namespaces=self.namespace)[0]
result_string = generate_restriction(self.request, xsd_element, xsd_tree)
# print result_string
expected_element = self.restriction_data_handler.get_json(xsd_files)
self.assertDictEqual(result_string[1], expected_element)
def test_simple_type(self):
xsd_files = join('simple_type', 'basic')
xsd_tree = self.restriction_data_handler.get_xsd(xsd_files)
xsd_element = xsd_tree.xpath('/xs:schema/xs:simpleType/xs:restriction',
namespaces=self.namespace)[0]
result_string = generate_restriction(self.request, xsd_element, xsd_tree)
# print result_string
expected_element = self.restriction_data_handler.get_json(xsd_files)
self.assertDictEqual(result_string[1], expected_element)
示例10: ParserHasModuleTestSuite
# 需要导入模块: from mgi.tests import DataHandler [as 别名]
# 或者: from mgi.tests.DataHandler import get_xsd [as 别名]
class ParserHasModuleTestSuite(TestCase):
"""
"""
def _save_module_to_db(self):
# FIXME module is not saved in the right database
module = Module()
module.name = 'registered_module'
module.url = 'registered_module'
module.view = 'registered_module'
module.save()
def setUp(self):
# connect to test database
# self.db_name = "mgi_test"
# disconnect()
# connect(self.db_name, port=27018)
module_data = join('curate', 'tests', 'data', 'parser', 'utils', 'modules')
self.module_data_handler = DataHandler(module_data)
def test_element_is_module_registered(self):
# expect true
self._save_module_to_db()
xsd_tree = self.module_data_handler.get_xsd('registered_module')
xsd_element = xsd_tree.getroot()
has_module_result = has_module(xsd_element)
self.assertTrue(has_module_result)
def test_element_is_module_not_registered(self):
# expect false
xsd_tree = self.module_data_handler.get_xsd('unregistered_module')
xsd_element = xsd_tree.getroot()
has_module_result = has_module(xsd_element)
self.assertFalse(has_module_result)
def test_element_is_not_module(self):
# expect false
xsd_tree = self.module_data_handler.get_xsd('no_module')
xsd_element = xsd_tree.getroot()
has_module_result = has_module(xsd_element)
self.assertFalse(has_module_result)
示例11: ParserCreateSimpleContentTestSuite
# 需要导入模块: from mgi.tests import DataHandler [as 别名]
# 或者: from mgi.tests.DataHandler import get_xsd [as 别名]
class ParserCreateSimpleContentTestSuite(TestCase):
"""
"""
def setUp(self):
simple_content_data = join('curate', 'tests', 'data', 'parser', 'simple_content')
self.simple_content_data_handler = DataHandler(simple_content_data)
self.maxDiff = None
self.request = HttpRequest()
engine = import_module('django.contrib.sessions.backends.db')
session_key = None
self.request.session = engine.SessionStore(session_key)
self.request.session['curate_edit'] = False # Data edition
self.request.session['nb_html_tags'] = 0
self.request.session['mapTagID'] = {}
self.request.session['nbChoicesID'] = 0
self.request.session['keys'] = {}
self.request.session['keyrefs'] = {}
# set default namespace
self.namespace = {
'xs': SCHEMA_NAMESPACE
}
self.request.session['defaultPrefix'] = 'xs'
self.request.session['namespaces'] = self.namespace
def test_restriction(self):
xsd_files = join('restriction', 'basic')
xsd_tree = self.simple_content_data_handler.get_xsd(xsd_files)
xsd_element = xsd_tree.xpath('/xs:schema/xs:complexType/xs:simpleContent', namespaces=self.namespace)[0]
result_string = generate_simple_content(self.request, xsd_element, xsd_tree)
expected_element = self.simple_content_data_handler.get_json(xsd_files)
self.assertDictEqual(result_string[1], expected_element)
def test_extension(self):
xsd_files = join('extension', 'basic')
xsd_tree = self.simple_content_data_handler.get_xsd(xsd_files)
xsd_element = xsd_tree.xpath('/xs:schema/xs:complexType/xs:simpleContent', namespaces=self.namespace)[0]
result_string = generate_simple_content(self.request, xsd_element, xsd_tree)
expected_element = self.simple_content_data_handler.get_json(xsd_files)
self.assertDictEqual(result_string[1], expected_element)
示例12: ParserManageAttrOccurencesTestSuite
# 需要导入模块: from mgi.tests import DataHandler [as 别名]
# 或者: from mgi.tests.DataHandler import get_xsd [as 别名]
class ParserManageAttrOccurencesTestSuite(TestCase):
"""
"""
def setUp(self):
occurs_data = join('curate', 'tests', 'data', 'parser', 'utils', 'manage_occurs')
self.occurs_data_handler = DataHandler(occurs_data)
def test_use_optional(self):
xsd_tree = self.occurs_data_handler.get_xsd('attr_use_optional')
xsd_element = xsd_tree.getroot()
(min_occ, max_occ) = manage_attr_occurrences(xsd_element)
self.assertEqual(min_occ, 0)
self.assertEqual(max_occ, 1)
def test_use_prohibited(self):
xsd_tree = self.occurs_data_handler.get_xsd('attr_use_prohibited')
xsd_element = xsd_tree.getroot()
(min_occ, max_occ) = manage_attr_occurrences(xsd_element)
self.assertEqual(min_occ, 0)
self.assertEqual(max_occ, 0)
def test_use_required(self):
xsd_tree = self.occurs_data_handler.get_xsd('attr_use_required')
xsd_element = xsd_tree.getroot()
(min_occ, max_occ) = manage_attr_occurrences(xsd_element)
self.assertEqual(min_occ, 1)
self.assertEqual(max_occ, 1)
def test_use_not_present(self):
xsd_tree = self.occurs_data_handler.get_xsd('attr_use_undefined')
xsd_element = xsd_tree.getroot()
(min_occ, max_occ) = manage_attr_occurrences(xsd_element)
# FIXME test broken with current parser
# self.assertEqual(min_occ, 0)
self.assertEqual(max_occ, 1)
示例13: ParserManageAttrOccurencesTestSuite
# 需要导入模块: from mgi.tests import DataHandler [as 别名]
# 或者: from mgi.tests.DataHandler import get_xsd [as 别名]
class ParserManageAttrOccurencesTestSuite(TestCase):
"""
"""
def setUp(self):
occurs_data = join("utils", "XSDParser", "tests", "data", "parser", "utils", "manage_occurs")
self.occurs_data_handler = DataHandler(occurs_data)
def test_use_optional(self):
xsd_tree = self.occurs_data_handler.get_xsd("attr_use_optional")
xsd_element = xsd_tree.getroot()
(min_occ, max_occ) = manage_attr_occurrences(xsd_element)
self.assertEqual(min_occ, 0)
self.assertEqual(max_occ, 1)
def test_use_prohibited(self):
xsd_tree = self.occurs_data_handler.get_xsd("attr_use_prohibited")
xsd_element = xsd_tree.getroot()
(min_occ, max_occ) = manage_attr_occurrences(xsd_element)
self.assertEqual(min_occ, 0)
self.assertEqual(max_occ, 0)
def test_use_required(self):
xsd_tree = self.occurs_data_handler.get_xsd("attr_use_required")
xsd_element = xsd_tree.getroot()
(min_occ, max_occ) = manage_attr_occurrences(xsd_element)
self.assertEqual(min_occ, 1)
self.assertEqual(max_occ, 1)
def test_use_not_present(self):
xsd_tree = self.occurs_data_handler.get_xsd("attr_use_undefined")
xsd_element = xsd_tree.getroot()
(min_occ, max_occ) = manage_attr_occurrences(xsd_element)
# FIXME test broken with current parser
# self.assertEqual(min_occ, 0)
self.assertEqual(max_occ, 1)
示例14: ChoiceCreateSchemaTestSuite
# 需要导入模块: from mgi.tests import DataHandler [as 别名]
# 或者: from mgi.tests.DataHandler import get_xsd [as 别名]
class ChoiceCreateSchemaTestSuite(SimpleTestCase):
"""
"""
def setUp(self):
xsd_files_path = join(XSD_FILES_PATH, 'choice')
self.xsd_handler = DataHandler(xsd_files_path)
html_files_path = join(HTML_FILES_PATH, 'choice')
self.html_handler = DataHandler(html_files_path)
engine = import_module('django.contrib.sessions.backends.db')
session = engine.SessionStore()
session.save()
self.client.cookies['sessionid'] = session.session_key
session['curate_edit'] = False
form_data = FormData()
form_data.name = ''
form_data.user = ''
form_data.template = ''
form_data.save()
session['curateFormData'] = str(form_data.pk)
session['nb_html_tags'] = 0
session['implicit_extension'] = True
session['mapTagID'] = {}
session['nbChoicesID'] = 0
session.save()
# def test_any_basic(self):
# pass
#
# def test_any_unbounded(self):
# pass
def test_choice_basic(self):
file_path = join('choice', 'basic')
xsd_data = self.xsd_handler.get_xsd(file_path)
session = self.client.session
session['xmlDocTree'] = etree.tostring(xsd_data)
session.save()
result = retrieve_rendered_form(self.client)
expected_result = self.html_handler.get_html(file_path)
self.assertTrue(are_equals(result[1], expected_result))
示例15: ParserReloadSimpleTypeTestSuite
# 需要导入模块: from mgi.tests import DataHandler [as 别名]
# 或者: from mgi.tests.DataHandler import get_xsd [as 别名]
class ParserReloadSimpleTypeTestSuite(TestCase):
"""
"""
def setUp(self):
simple_type_data = join('curate', 'tests', 'data', 'parser', 'simple_type')
self.simple_type_data_handler = DataHandler(simple_type_data)
self.maxDiff = None
self.request = HttpRequest()
engine = import_module('django.contrib.sessions.backends.db')
session_key = None
self.request.session = engine.SessionStore(session_key)
self.request.session['curate_edit'] = False # Data edition
self.request.session['nb_html_tags'] = 0
self.request.session['mapTagID'] = {}
self.request.session['nbChoicesID'] = 0
self.request.session['implicit_extension'] = True
# set default namespace
namespace = "http://www.w3.org/2001/XMLSchema"
self.namespace = "{" + namespace + "}"
self.request.session['defaultPrefix'] = 'xs'
self.request.session['namespaces'] = {'xs': namespace}
def test_reload_restriction(self):
# FIXME relaod restriction doesn't work
xsd_files = join('restriction', 'basic')
xsd_tree = self.simple_type_data_handler.get_xsd(xsd_files)
xsd_element = xsd_tree.xpath('/xs:schema/xs:simpleType', namespaces=self.request.session['namespaces'])[0]
self.request.session['curate_edit'] = True
xml_tree = self.simple_type_data_handler.get_xml(xsd_files)
xml_data = etree.tostring(xml_tree)
xml_value = xml_tree.xpath("/root", namespaces=self.request.session['namespaces'])[0].text
clean_parser = etree.XMLParser(remove_blank_text=True, remove_comments=True, remove_pis=True)
etree.set_default_parser(parser=clean_parser)
# load the XML tree from the text
edit_data_tree = etree.XML(str(xml_data.encode('utf-8')))
result_string = generate_simple_type(self.request, xsd_element, xsd_tree, full_path='/root',
default_value=xml_value, edit_data_tree=edit_data_tree)
# print result_string
expected_dict = self.simple_type_data_handler.get_json(xsd_files + '.reload')
self.assertDictEqual(result_string[1], expected_dict)
def test_reload_list(self):
# FIXME list reload is not working
xsd_files = join('list', 'basic')
xsd_tree = self.simple_type_data_handler.get_xsd(xsd_files)
xsd_element = xsd_tree.xpath('/xs:schema/xs:simpleType', namespaces=self.request.session['namespaces'])[0]
self.request.session['curate_edit'] = True
xml_tree = self.simple_type_data_handler.get_xml(xsd_files)
xml_data = etree.tostring(xml_tree)
clean_parser = etree.XMLParser(remove_blank_text=True, remove_comments=True, remove_pis=True)
etree.set_default_parser(parser=clean_parser)
# load the XML tree from the text
edit_data_tree = etree.XML(str(xml_data.encode('utf-8')))
result_string = generate_simple_type(self.request, xsd_element, xsd_tree, full_path='/root',
edit_data_tree=edit_data_tree)
# print result_string
expected_dict = self.simple_type_data_handler.get_json(xsd_files + '.reload')
self.assertDictEqual(result_string[1], expected_dict)