本文整理汇总了Python中mgi.tests.DataHandler.get_json方法的典型用法代码示例。如果您正苦于以下问题:Python DataHandler.get_json方法的具体用法?Python DataHandler.get_json怎么用?Python DataHandler.get_json使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mgi.tests.DataHandler
的用法示例。
在下文中一共展示了DataHandler.get_json方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ParserReloadSimpleContentTestSuite
# 需要导入模块: from mgi.tests import DataHandler [as 别名]
# 或者: from mgi.tests.DataHandler import get_json [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)
示例2: ParserCreateComplexContentTestSuite
# 需要导入模块: from mgi.tests import DataHandler [as 别名]
# 或者: from mgi.tests.DataHandler import get_json [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)
示例3: ParserCreateSimpleTypeTestSuite
# 需要导入模块: from mgi.tests import DataHandler [as 别名]
# 或者: from mgi.tests.DataHandler import get_json [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)
示例4: ParserCreateRestrictionTestSuite
# 需要导入模块: from mgi.tests import DataHandler [as 别名]
# 或者: from mgi.tests.DataHandler import get_json [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)
示例5: ParserCreateSimpleContentTestSuite
# 需要导入模块: from mgi.tests import DataHandler [as 别名]
# 或者: from mgi.tests.DataHandler import get_json [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)
示例6: ParserReloadElementTestSuite
# 需要导入模块: from mgi.tests import DataHandler [as 别名]
# 或者: from mgi.tests.DataHandler import get_json [as 别名]
class ParserReloadElementTestSuite(TestCase):
"""
"""
def setUp(self):
element_data = join('utils', 'XSDParser', 'tests', 'data', 'parser', 'element')
self.element_data_handler = DataHandler(element_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
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_reload_simple_type_basic(self):
xsd_files = join('simple_type', 'basic')
xsd_tree = self.element_data_handler.get_xsd(xsd_files)
xsd_element = xsd_tree.xpath('/xs:schema/xs:element', namespaces=self.request.session['namespaces'])[0]
self.request.session['curate_edit'] = True
xml_tree = self.element_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_element(self.request, xsd_element, xsd_tree, full_path='',
edit_data_tree=edit_data_tree)
expected_element = self.element_data_handler.get_json(xsd_files + '.reload')
self.assertDictEqual(result_string[1], expected_element)
# result_html = etree.fromstring(result_string[0])
# expected_html = self.element_data_handler.get_html(xsd_files + '.reload')
#
# self.assertTrue(are_equals(result_html, expected_html))
def test_reload_simple_type_unbounded(self):
xsd_files = join('simple_type', 'unbounded')
xsd_tree = self.element_data_handler.get_xsd(xsd_files)
xsd_element = xsd_tree.xpath('/xs:schema/xs:complexType/xs:sequence/xs:element',
namespaces=self.request.session['namespaces'])[0]
self.request.session['curate_edit'] = True
xml_tree = self.element_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)
edit_data_tree = etree.XML(str(xml_data.encode('utf-8')))
result_string = generate_element(self.request, xsd_element, xsd_tree, full_path='/root',
edit_data_tree=edit_data_tree)
expected_element = self.element_data_handler.get_json(xsd_files + '.reload')
self.assertDictEqual(result_string[1], expected_element)
# result_html = etree.fromstring(result_string[0])
# expected_html = self.element_data_handler.get_html(xsd_files + '.reload')
#
# self.assertTrue(are_equals(result_html, expected_html))
def test_reload_complex_type_basic(self):
xsd_files = join('complex_type', 'basic')
xsd_tree = self.element_data_handler.get_xsd(xsd_files)
xsd_element = xsd_tree.xpath('/xs:schema/xs:element', namespaces=self.request.session['namespaces'])[0]
self.request.session['curate_edit'] = True
xml_tree = self.element_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_element(self.request, xsd_element, xsd_tree, full_path='',
#.........这里部分代码省略.........
示例7: ParserReloadSimpleTypeTestSuite
# 需要导入模块: from mgi.tests import DataHandler [as 别名]
# 或者: from mgi.tests.DataHandler import get_json [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)
示例8: ParserReloadSequenceTestSuite
# 需要导入模块: from mgi.tests import DataHandler [as 别名]
# 或者: from mgi.tests.DataHandler import get_json [as 别名]
class ParserReloadSequenceTestSuite(TestCase):
"""
"""
def setUp(self):
sequence_data = join('curate', 'tests', 'data', 'parser', 'sequence')
self.sequence_data_handler = DataHandler(sequence_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_reload_element_basic(self):
xsd_files = join('element', 'basic')
xsd_tree = self.sequence_data_handler.get_xsd(xsd_files)
xsd_element = xsd_tree.xpath('/xs:schema/xs:complexType/xs:sequence',
namespaces=self.request.session['namespaces'])[0]
self.request.session['curate_edit'] = True
xml_tree = self.sequence_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_sequence(self.request, xsd_element, xsd_tree, full_path='/root',
edit_data_tree=edit_data_tree)
# print result_string
expected_element = self.sequence_data_handler.get_json(xsd_files + '.reload')
self.assertDictEqual(result_string[1], expected_element)
# result_html = etree.fromstring(result_string[0])
# expected_html = self.sequence_data_handler.get_html(xsd_files + '.reload')
#
# self.assertTrue(are_equals(result_html, expected_html))
def test_reload_element_unbounded(self):
# fixme correct bug
xsd_files = join('element', 'unbounded')
xsd_tree = self.sequence_data_handler.get_xsd(xsd_files)
xsd_element = xsd_tree.xpath('/xs:schema/xs:complexType/xs:sequence',
namespaces=self.request.session['namespaces'])[0]
self.request.session['curate_edit'] = True
xml_tree = self.sequence_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_sequence(self.request, xsd_element, xsd_tree, full_path='/root',
edit_data_tree=edit_data_tree)
# print result_string
expected_element = self.sequence_data_handler.get_json(xsd_files + '.reload')
self.assertDictEqual(result_string[1], expected_element)
# result_html = etree.fromstring(result_string[0])
# expected_html = self.sequence_data_handler.get_html(xsd_files + '.reload')
#
# self.assertTrue(are_equals(result_html, expected_html))
# fixme implement groups
# def test_reload_group_basic(self):
# xsd_files = join('element', 'basic')
# xsd_tree = self.sequence_data_handler.get_xsd(xsd_files)
# xsd_element = xsd_tree.xpath('/schema/complexType/sequence')[0]
#
# self.request.session['curate_edit'] = True
#
# xml_tree = self.sequence_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_sequence(self.request, xsd_element, xsd_tree, '', full_path='/root',
# edit_data_tree=edit_data_tree)
# print result_string
#.........这里部分代码省略.........
示例9: ParserCreateSequenceTestSuite
# 需要导入模块: from mgi.tests import DataHandler [as 别名]
# 或者: from mgi.tests.DataHandler import get_json [as 别名]
class ParserCreateSequenceTestSuite(TestCase):
"""
"""
def setUp(self):
sequence_data = join('curate', 'tests', 'data', 'parser', 'sequence')
self.sequence_data_handler = DataHandler(sequence_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_element_basic(self):
xsd_files = join('element', 'basic')
xsd_xpath = '/xs:schema/xs:complexType/xs:sequence'
# self.parser_test_datastructures(xsd_files, self.sequence_data_handler, xsd_xpath,
# self.request.session['namespaces'],
# generate_sequence, self.request)
xsd_tree = self.sequence_data_handler.get_xsd(xsd_files)
xsd_element = xsd_tree.xpath(xsd_xpath,
namespaces=self.request.session['namespaces'])[0]
result_string = generate_sequence(self.request, xsd_element, xsd_tree, full_path='')
expected_element = self.sequence_data_handler.get_json(xsd_files)
self.assertDictEqual(result_string[1], expected_element)
# result_html = etree.fromstring(result_string[0])
# expected_html = self.sequence_data_handler.get_html(join('element', 'basic'))
#
# self.assertTrue(are_equals(result_html, expected_html))
def test_create_element_unbounded(self):
xsd_files = join('element', 'unbounded')
xsd_tree = self.sequence_data_handler.get_xsd(xsd_files)
xsd_element = xsd_tree.xpath('/xs:schema/xs:complexType/xs:sequence',
namespaces=self.request.session['namespaces'])[0]
result_string = generate_sequence(self.request, xsd_element, xsd_tree, full_path='')
expected_element = self.sequence_data_handler.get_json(xsd_files)
self.assertDictEqual(result_string[1], expected_element)
# result_html = etree.fromstring(result_string[0])
# expected_html = self.sequence_data_handler.get_html(join('element', 'unbounded'))
#
# self.assertTrue(are_equals(result_html, expected_html))
# def test_create_group_basic(self):
# # FIXME change test and implement group support on the parser
# xsd_tree = self.sequence_data_handler.get_xsd(join('group', 'basic'))
# xsd_element = xsd_tree.xpath('/schema/complexType/sequence')[0]
#
# result_string = generate_sequence(self.request, xsd_element, xsd_tree, '', full_path='')
# self.assertEqual(result_string, "")
#
# # result_html = etree.fromstring(result_string)
# # expected_html = self.sequence_data_handler.get_html(join('element', 'element'))
# #
# # self.assertTrue(are_equals(result_html, expected_html))
#
# def test_create_group_unbounded(self):
# xsd_tree = self.sequence_data_handler.get_xsd(join('group', 'unbounded'))
# xsd_element = xsd_tree.xpath('/schema/complexType/sequence')[0]
#
# result_string = generate_sequence(self.request, xsd_element, xsd_tree, '', full_path='')
#
# result_html = etree.fromstring(result_string)
# expected_html = self.sequence_data_handler.get_html(join('group', 'unbounded'))
#
# self.assertTrue(are_equals(result_html, expected_html))
def test_create_choice_basic(self):
xsd_files = join('choice', 'basic')
xsd_tree = self.sequence_data_handler.get_xsd(xsd_files)
xsd_element = xsd_tree.xpath('/xs:schema/xs:complexType/xs:sequence',
namespaces=self.request.session['namespaces'])[0]
result_string = generate_sequence(self.request, xsd_element, xsd_tree, full_path='')
# print result_string
expected_element = self.sequence_data_handler.get_json(xsd_files)
#.........这里部分代码省略.........
示例10: ParserReloadRestrictionTestSuite
# 需要导入模块: from mgi.tests import DataHandler [as 别名]
# 或者: from mgi.tests.DataHandler import get_json [as 别名]
class ParserReloadRestrictionTestSuite(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'] = True # 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
self.xml_xpath = '/root'
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]
xml_tree = self.restriction_data_handler.get_xml(xsd_files)
# xml_data = etree.tostring(xml_tree)
xml_data_value = xml_tree.xpath(self.xml_xpath)[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_restriction(self.request, xsd_element, xsd_tree, full_path=self.xml_xpath,
edit_data_tree=xml_tree, default_value=xml_data_value)
expected_element = self.restriction_data_handler.get_json(join('enumeration', 'reload'))
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]
xml_tree = self.restriction_data_handler.get_xml(xsd_files)
xml_data_value = xml_tree.xpath(self.xml_xpath)[0].text
result_string = generate_restriction(self.request, xsd_element, xsd_tree, full_path=self.xml_xpath,
edit_data_tree=xml_tree, default_value=xml_data_value)
expected_element = self.restriction_data_handler.get_json(join('simple_type', 'reload'))
self.assertDictEqual(result_string[1], expected_element)
示例11: ParserReloadComplexTypeTestSuite
# 需要导入模块: from mgi.tests import DataHandler [as 别名]
# 或者: from mgi.tests.DataHandler import get_json [as 别名]
class ParserReloadComplexTypeTestSuite(TestCase):
"""
"""
def setUp(self):
complex_type_data = join('utils', 'XSDParser', 'tests', 'data', 'parser', 'complex_type')
self.complex_type_data_handler = DataHandler(complex_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
self.request.session['keys'] = {}
self.request.session['keyrefs'] = {}
# 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_reload_simple_content(self):
xsd_files = join('simple_content', 'basic')
xsd_tree = self.complex_type_data_handler.get_xsd(xsd_files)
xsd_element = xsd_tree.xpath('/xs:schema/xs:complexType', namespaces=self.request.session['namespaces'])[0]
self.request.session['curate_edit'] = True
xml_tree = self.complex_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_complex_type(self.request, xsd_element, xsd_tree, full_path='/root',
default_value=xml_value, edit_data_tree=edit_data_tree)
# print result_string
expected_element = self.complex_type_data_handler.get_json(xsd_files + '.reload')
self.assertDictEqual(result_string[1], expected_element)
# result_html = etree.fromstring(result_string[0])
# expected_html = self.complex_type_data_handler.get_html(xsd_files + '.reload')
#
# self.assertTrue(are_equals(result_html, expected_html))
def test_reload_complex_content(self):
xsd_files = join('complex_content', 'basic')
xsd_tree = self.complex_type_data_handler.get_xsd(xsd_files)
xsd_element = xsd_tree.xpath('/xs:schema/xs:complexType', namespaces=self.request.session['namespaces'])[0]
self.request.session['curate_edit'] = True
xml_tree = self.complex_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_complex_type(self.request, xsd_element, xsd_tree, full_path='/root',
edit_data_tree=edit_data_tree)
expected_element = self.complex_type_data_handler.get_json(xsd_files + '.reload')
self.assertDictEqual(result_string[1], expected_element)
# print result_string
# result_html = etree.fromstring(result_string)
# expected_html = self.complex_type_data_handler.get_html(xsd_files + '.reload')
#
# self.assertTrue(are_equals(result_html, expected_html))
#
# FIXME group not implemented
# def test_reload_group(self):
# xsd_files = join('simple_content', 'basic')
# xsd_tree = self.complex_type_data_handler.get_xsd(xsd_files)
# xsd_element = xsd_tree.xpath('/schema/complexType')[0]
#
# self.request.session['curate_edit'] = True
#
# xml_tree = self.complex_type_data_handler.get_xml(xsd_files)
# xml_data = etree.tostring(xml_tree)
#
#.........这里部分代码省略.........
示例12: ParserCreateComplexTypeTestSuite
# 需要导入模块: from mgi.tests import DataHandler [as 别名]
# 或者: from mgi.tests.DataHandler import get_json [as 别名]
class ParserCreateComplexTypeTestSuite(TestCase):
"""
"""
def setUp(self):
complex_type_data = join('utils', 'XSDParser', 'tests', 'data', 'parser', 'complex_type')
self.complex_type_data_handler = DataHandler(complex_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
self.request.session['keys'] = {}
self.request.session['keyrefs'] = {}
# 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_simple_content(self):
xsd_files = join('simple_content', 'basic')
xsd_tree = self.complex_type_data_handler.get_xsd(xsd_files)
xsd_element = xsd_tree.xpath('/xs:schema/xs:complexType', namespaces=self.request.session['namespaces'])[0]
result_string = generate_complex_type(self.request, xsd_element, xsd_tree, full_path='')
# print result_string
expected_element = self.complex_type_data_handler.get_json(xsd_files)
self.assertDictEqual(result_string[1], expected_element)
# result_html = etree.fromstring(result_string[0])
# expected_html = self.complex_type_data_handler.get_html(xsd_files)
#
# self.assertTrue(are_equals(result_html, expected_html))
def test_create_complex_content(self):
xsd_files = join('complex_content', 'basic')
xsd_tree = self.complex_type_data_handler.get_xsd(xsd_files)
xsd_element = xsd_tree.xpath('/xs:schema/xs:complexType[1]', namespaces=self.request.session['namespaces'])[0]
result_string = generate_complex_type(self.request, xsd_element, xsd_tree, full_path='')
# print result_string
expected_element = self.complex_type_data_handler.get_json(xsd_files)
self.assertDictEqual(result_string[1], expected_element)
# self.assertEqual(result_string[0], '')
# result_string = '<div>' + result_string[0] + '</div>'
# result_html = etree.fromstring(result_string)
# expected_html = self.complex_type_data_handler.get_html(xsd_files)
#
# self.assertTrue(are_equals(result_html, expected_html))
# FIXME group not supported
# def test_create_group(self):
# xsd_files = join('group', 'basic')
# xsd_tree = self.complex_type_data_handler.get_xsd(xsd_files)
# xsd_element = xsd_tree.xpath('/xs:schema/xs:complexType', namespaces=self.request.session['namespaces'])[0]
#
# result_string = generate_complex_type(self.request, xsd_element, xsd_tree, self.namespace, full_path='')
# # print result_string
# self.assertEqual(result_string[0], '')
#
# expected_element = {
# 'tag': 'complex_type',
# 'occurs': (1, 1, 1),
# 'module': None,
# 'value': None,
# 'children': []
# }
#
# self.assertDictEqual(result_string[1], expected_element)
#
# # result_html = etree.fromstring(result_string)
# # expected_html = self.complex_type_data_handler.get_html(xsd_files)
# #
# # self.assertTrue(are_equals(result_html, expected_html))
# FIXME all is not suported
# def test_create_all(self):
# xsd_files = join('all', 'basic')
# xsd_tree = self.complex_type_data_handler.get_xsd(xsd_files)
# xsd_element = xsd_tree.xpath('/xs:schema/xs:complexType', namespaces=self.request.session['namespaces'])[0]
#
#.........这里部分代码省略.........
示例13: ParserReloadExtensionTestSuite
# 需要导入模块: from mgi.tests import DataHandler [as 别名]
# 或者: from mgi.tests.DataHandler import get_json [as 别名]
#.........这里部分代码省略.........
# # print result_string
# # result_string = '<div>' + result_string + '</div>'
#
# expected_dict = {}
#
# self.assertDictEqual(result_string[1], expected_dict)
#
# result_string = '<div>' + result_string[0] + '</div>'
# result_html = etree.fromstring(result_string)
# expected_html = self.extension_data_handler.get_html(xsd_files + '.reload')
#
# self.assertTrue(are_equals(result_html, expected_html))
def test_choice(self):
xsd_files = join('choice', 'basic')
xsd_tree = self.extension_data_handler.get_xsd(xsd_files)
xsd_element = xsd_tree.xpath('/xs:schema/xs:element/xs:complexType/xs:complexContent/xs:extension',
namespaces=self.session['namespaces'])[0]
xml_tree = self.extension_data_handler.get_xml(xsd_files)
xml_data = etree.tostring(xml_tree)
xml_value = xml_tree.xpath('/test2', namespaces=self.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_extension(self.request, xsd_element, xsd_tree, full_path='/test2',
default_value=xml_value, edit_data_tree=edit_data_tree)
expected_dict = self.extension_data_handler.get_json(xsd_files+'.reload')
self.assertDictEqual(result_string[1], expected_dict)
def test_sequence(self):
xsd_files = join('sequence', 'basic')
xsd_tree = self.extension_data_handler.get_xsd(xsd_files)
xsd_element = xsd_tree.xpath('/xs:schema/xs:element/xs:complexType/xs:complexContent/xs:extension',
namespaces=self.session['namespaces'])[0]
xml_tree = self.extension_data_handler.get_xml(xsd_files)
xml_data = etree.tostring(xml_tree)
xml_value = ''
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_extension(self.request, xsd_element, xsd_tree, full_path='/root[1]',
default_value=xml_value, edit_data_tree=edit_data_tree)
# print result_string
# result_string = '<div>' + result_string + '</div>'
expected_dict = self.extension_data_handler.get_json(xsd_files+'.reload')
self.assertDictEqual(result_string[1], expected_dict)
def test_attribute(self):
xsd_files = join('attribute', 'basic')
xsd_tree = self.extension_data_handler.get_xsd(xsd_files)
xsd_element = xsd_tree.xpath('/xs:schema/xs:element/xs:complexType/xs:simpleContent/xs:extension',
namespaces=self.session['namespaces'])[0]
示例14: ParserCreateExtensionTestSuite
# 需要导入模块: from mgi.tests import DataHandler [as 别名]
# 或者: from mgi.tests.DataHandler import get_json [as 别名]
class ParserCreateExtensionTestSuite(TestCase):
"""
"""
def setUp(self):
extension_data = join('curate', 'tests', 'data', 'parser', 'extension')
self.extension_data_handler = DataHandler(extension_data)
self.maxDiff = None
engine = import_module(settings.SESSION_ENGINE)
store = engine.SessionStore()
store['curate_edit'] = False # Data edition
store['nb_html_tags'] = 0
store['mapTagID'] = {}
store['nbChoicesID'] = 0
store['keys'] = {}
store['keyrefs'] = {}
# set default namespace
self.namespace = "{" + SCHEMA_NAMESPACE + "}"
store['defaultPrefix'] = 'xs'
store['namespaces'] = {'xs': SCHEMA_NAMESPACE}
store.save()
self.session = store
self.client.cookies[settings.SESSION_COOKIE_NAME] = store.session_key
self.request = HttpRequest()
self.request.session = self.session
# def test_create_group(self):
# xsd_files = join('group', 'basic')
# xsd_tree = self.extension_data_handler.get_xsd(xsd_files))
# xsd_element = xsd_tree.xpath('/xs:schema/xs:element/xs:complexType/xs:complexContent/xs:extension',
# namespaces=self.request.session['namespaces'])[0]
#
# result_string = generate_extension(self.request, xsd_element, xsd_tree, self.namespace, full_path='')
# # print result_string
#
# expected_dict = {
# }
#
# self.assertDictEqual(result_string[1], expected_dict)
#
# result_string = '<div>' + result_string[0] + '</div>'
# result_html = etree.fromstring(result_string)
# expected_html = self.extension_data_handler.get_html(xsd_files)
#
# self.assertTrue(are_equals(result_html, expected_html))
# def test_create_all(self):
# xsd_files = join('all', 'basic')
# xsd_tree = self.extension_data_handler.get_xsd(xsd_files))
# xsd_element = xsd_tree.xpath('/xs:schema/xs:element/xs:complexType/xs:complexContent/xs:extension',
# namespaces=self.request.session['namespaces'])[0]
#
# result_string = generate_extension(self.request, xsd_element, xsd_tree, self.namespace, 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)
# expected_html = self.extension_data_handler.get_html(xsd_files)
#
# self.assertTrue(are_equals(result_html, expected_html))
def test_choice(self):
xsd_files = join('choice', 'basic')
xsd_tree = self.extension_data_handler.get_xsd(xsd_files)
xsd_element = xsd_tree.xpath('/xs:schema/xs:element/xs:complexType/xs:complexContent/xs:extension',
namespaces=self.session['namespaces'])[0]
result_string = generate_extension(self.request, xsd_element, xsd_tree, full_path='')
expected_dict = self.extension_data_handler.get_json(xsd_files)
self.assertDictEqual(result_string[1], expected_dict)
def test_sequence(self):
xsd_files = join('sequence', 'basic')
xsd_tree = self.extension_data_handler.get_xsd(xsd_files)
xsd_element = xsd_tree.xpath('/xs:schema/xs:element/xs:complexType/xs:complexContent/xs:extension',
namespaces=self.session['namespaces'])[0]
self.session['keys'] = {}
self.session.save()
self.request.session = self.session
result_string = generate_extension(self.request, xsd_element, xsd_tree, full_path='')
# print result_string
expected_dict = self.extension_data_handler.get_json(xsd_files)
#.........这里部分代码省略.........
示例15: ParserCreateChoiceTestSuite
# 需要导入模块: from mgi.tests import DataHandler [as 别名]
# 或者: from mgi.tests.DataHandler import get_json [as 别名]
class ParserCreateChoiceTestSuite(TestCase):
"""
"""
def setUp(self):
choice_data = join("utils", "XSDParser", "tests", "data", "parser", "choice")
self.choice_data_handler = DataHandler(choice_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}
from utils.XSDParser import parser
from curate.ajax import load_config
parser.load_config(self.request, load_config())
def test_create_element_basic(self):
xsd_files = join("element", "basic")
xsd_tree = self.choice_data_handler.get_xsd(xsd_files)
xsd_element = xsd_tree.xpath(
"/xs:schema/xs:complexType/xs:choice", namespaces=self.request.session["namespaces"]
)[0]
result_string = generate_choice(self.request, xsd_element, xsd_tree, full_path="")
# print result_string
expected_element = self.choice_data_handler.get_json(xsd_files)
self.assertDictEqual(result_string[1], expected_element)
# result_html = etree.fromstring(result_string[0])
# expected_html = self.choice_data_handler.get_html(xsd_files)
#
# self.assertTrue(are_equals(result_html, expected_html))
def test_create_element_unbounded(self):
xsd_files = join("element", "unbounded")
xsd_tree = self.choice_data_handler.get_xsd(xsd_files)
xsd_element = xsd_tree.xpath(
"/xs:schema/xs:complexType/xs:choice", namespaces=self.request.session["namespaces"]
)[0]
result_string = generate_choice(self.request, xsd_element, xsd_tree, full_path="")
# print result_string
expected_element = self.choice_data_handler.get_json(xsd_files)
self.assertDictEqual(result_string[1], expected_element)
# result_html = etree.fromstring(result_string[0])
# expected_html = self.choice_data_handler.get_html(xsd_files)
#
# self.assertTrue(are_equals(result_html, expected_html))
# FIXME group test are not good since it is not supported by the parser
# def test_create_group_basic(self):
# xsd_files = join('group', 'basic')
# xsd_tree = self.choice_data_handler.get_xsd(xsd_files)
# xsd_element = xsd_tree.xpath('/schema/complexType/choice')[0]
#
# result_string = generate_choice(self.request, xsd_element, xsd_tree, '', full_path='')
# # print result_string
#
# result_html = etree.fromstring(result_string)
# expected_html = self.choice_data_handler.get_html(xsd_files)
#
# self.assertTrue(are_equals(result_html, expected_html))
#
# def test_create_group_unbounded(self):
# xsd_files = join('group', 'unbounded')
# xsd_tree = self.choice_data_handler.get_xsd(xsd_files)
# xsd_element = xsd_tree.xpath('/schema/complexType/choice')[0]
#
# result_string = generate_choice(self.request, xsd_element, xsd_tree, '', full_path='')
# # print result_string
#
# result_html = etree.fromstring(result_string)
# expected_html = self.choice_data_handler.get_html(xsd_files)
#
# self.assertTrue(are_equals(result_html, expected_html))
# FIXME choice test are not good since it is not supported by the parser
# def test_create_choice_basic(self):
# xsd_files = join('choice', 'basic')
# xsd_tree = self.choice_data_handler.get_xsd(xsd_files)
#.........这里部分代码省略.........