def test_add_column_readonly(self): from xml.etree.ElementTree import TreeBuilder, tostring from sqlalchemy.orm.util import class_mapper from c2cgeoportal_geoportal.lib.xsd import XSDGenerator gen = XSDGenerator(include_foreign_keys=True) mapper = class_mapper(self.cls) tb = TreeBuilder() p = mapper.attrs["readonly"] gen.add_column_property_xsd(tb, p) e = tb.close() self.assertEqual( '<xsd:element name="readonly" minOccurs="0" nillable="true" type="xsd:string">' "<xsd:annotation>" "<xsd:appinfo>" '<readonly value="true" />' "</xsd:appinfo>" "</xsd:annotation>" "</xsd:element>", tostring(e).decode("utf-8"), )
def test_add_class_properties_xsd_column_order(self, column_mock): from c2cgeoportal_geoportal.lib.xsd import XSDGenerator tb = Mock() self.cls.__attributes_order__ = ["child1_id", "other"] gen = XSDGenerator(include_foreign_keys=True) gen.add_class_properties_xsd(tb, self.cls) called_properties = [kall[0][1].class_attribute.name for kall in column_mock.call_args_list] assert len(called_properties) == 5 assert self.cls.__attributes_order__ == called_properties[: len(self.cls.__attributes_order__)]
def test_add_column_property_xsd(self, column_mock, proxy_mock): from c2cgeoportal_geoportal.lib.xsd import XSDGenerator from sqlalchemy.orm.util import class_mapper gen = XSDGenerator(include_foreign_keys=True) tb = Mock() mapper = class_mapper(self.cls) p = mapper.attrs["child1_id"] gen.add_column_property_xsd(tb, p) proxy_mock.assert_called_once_with(tb, p) p = mapper.attrs["other"] gen.add_column_property_xsd(tb, p) column_mock.assert_called_once_with(tb, p)
def test_add_association_proxy_xsd(self): from xml.etree.ElementTree import TreeBuilder, tostring from sqlalchemy.orm.util import class_mapper from c2cgeoportal_geoportal.lib.xsd import XSDGenerator gen = XSDGenerator(include_foreign_keys=True) mapper = class_mapper(self.cls) tb = TreeBuilder() gen.add_association_proxy_xsd(tb, mapper.attrs["child1_id"]) e = tb.close() self.assertEqual( '<xsd:element minOccurs="0" nillable="true" name="child1">' "<xsd:simpleType>" '<xsd:restriction base="xsd:string">' '<xsd:enumeration value="foo" />' '<xsd:enumeration value="zad" />' '<xsd:enumeration value="bar" />' "</xsd:restriction>" "</xsd:simpleType>" "</xsd:element>", tostring(e).decode("utf-8"), ) # Test child2 enumeration is ordered by Child.custom_order tb = TreeBuilder() gen.add_association_proxy_xsd(tb, mapper.attrs["child2_id"]) e = tb.close() self.assertEqual( '<xsd:element name="child2">' "<xsd:simpleType>" '<xsd:restriction base="xsd:string">' '<xsd:enumeration value="zad" />' '<xsd:enumeration value="foo" />' '<xsd:enumeration value="bar" />' "</xsd:restriction>" "</xsd:simpleType>" "</xsd:element>", tostring(e).decode("utf-8"), )