def testIrrelevantSO(self):
        """Should fix up bad sort orders and logic when parsing from xml"""
        model = self.service.model

        xml = '''<template name="bad_so"><query name="bad_so" model="testmodel" view="Employee.name Employee.age" sortOrder="Employee.fullTime ASC"/></template>'''
        t = Template.from_xml(xml, model)
        self.assertEqual(str(t.get_sort_order()), "Employee.name asc")

        xml = '''<template name="bad_so"><query name="bad_so" model="testmodel" view="Employee.name Employee.age" sortOrder="Employee.fullTime"/></template>'''
        t = Template.from_xml(xml, model)
        self.assertEqual(str(t.get_sort_order()), "Employee.name asc")
Пример #2
0
    def testIrrelevantSO(self):
        """Should fix up bad sort orders and logic when parsing from xml"""
        model = self.service.model

        xml = '''<template name="bad_so"><query name="bad_so" model="testmodel" view="Employee.name Employee.age" sortOrder="Employee.fullTime ASC"/></template>'''
        t = Template.from_xml(xml, model)
        self.assertEqual(str(t.get_sort_order()), "Employee.name asc")

        xml = '''<template name="bad_so"><query name="bad_so" model="testmodel" view="Employee.name Employee.age" sortOrder="Employee.fullTime"/></template>'''
        t = Template.from_xml(xml, model)
        self.assertEqual(str(t.get_sort_order()), "Employee.name asc")
    def get_template(self, name):
        """
        Returns a template of the given name
        ====================================

        Tries to retrieve a template of the given name
        from the webservice. If you are trying to fetch
        a private template (ie. one you made yourself
        and is not available to others) then you may need to authenticate

        @see: L{intermine.webservice.Service.__init__}

        @param name: the template's name
        @type name: string

        @raise ServiceError: if the template does not exist
        @raise QueryParseError: if the template cannot be parsed

        @return: L{intermine.query.Template}
        """
        try:
            t = self.templates[name]
        except KeyError:
            raise ServiceError("There is no template called '"
                + name + "' at this service")
        if not isinstance(t, Template):
            t = Template.from_xml(t, self.model, self)
            self.templates[name] = t
        return t
Пример #4
0
    def get_template(self, name):
        """
        Returns a template of the given name
        ====================================

        Tries to retrieve a template of the given name
        from the webservice. If you are trying to fetch
        a private template (ie. one you made yourself
        and is not available to others) then you may need to authenticate

        @see: L{intermine.webservice.Service.__init__}

        @param name: the template's name
        @type name: string

        @raise ServiceError: if the template does not exist
        @raise QueryParseError: if the template cannot be parsed

        @return: L{intermine.query.Template}
        """
        try:
            t = self.templates[name]
        except KeyError:
            raise ServiceError("There is no template called '" + name +
                               "' at this service")
        if not isinstance(t, Template):
            t = Template.from_xml(t, self.model, self)
            self.templates[name] = t
        return t
    def testIrrelevantConstraintLogic(self):
        """Should fix up bad logic"""
        model = self.service.model

        xml = '''<template name="bad_cl"><query name="bad_cl" model="testmodel" view="Employee.name Employee.age" constraintLogic="A and B and C"/></template>'''
        t = Template.from_xml(xml, model)
        self.assertEqual(str(t.get_logic()), "")

        xml = '''<template name="bad_cl"><query name="bad_cl" model="testmodel" view="Employee.name Employee.age" constraintLogic="A and B or (D and E) and C"/></template>'''
        t = Template.from_xml(xml, model)
        self.assertEqual(str(t.get_logic()), "")

        xml = '''<template name="bad_cl"><query name="bad_cl" model="testmodel" view="Employee.name Employee.age" constraintLogic="A or B or (D and E) and C">
                <constraint path="Employee.name" op="IS NULL"/><constraint path="Employee.age" op="IS NOT NULL"/>
                </query>
            </template>'''
        t = Template.from_xml(xml, model)
        self.assertEqual(str(t.get_logic()), "A or B")

        xml = '''<template name="bad_cl"><query name="bad_cl" model="testmodel" view="Employee.name Employee.age" constraintLogic="A or B or (D and E) and C">
                <constraint path="Employee.name" op="IS NULL"/><constraint path="Employee.age" op="IS NOT NULL"/><constraint path="Employee.fullTime" op="=" value="true"/>
                </query>
            </template>'''
        t = Template.from_xml(xml, model)
        self.assertEqual(str(t.get_logic()), "(A or B) and C")

        xml = '''<template name="bad_cl"><query name="bad_cl" model="testmodel" view="Employee.name Employee.age" constraintLogic="A or B or (D and E) or C">
                <constraint path="Employee.name" op="IS NULL"/><constraint path="Employee.age" op="IS NOT NULL"/><constraint path="Employee.fullTime" op="=" value="true"/>
                </query>
            </template>'''
        t = Template.from_xml(xml, model)
        self.assertEqual(str(t.get_logic()), "A or B or C")

        xml = '''<template name="bad_cl"><query name="bad_cl" model="testmodel" view="Employee.name Employee.age" constraintLogic="A or B and (D and E) or C">
                <constraint path="Employee.name" op="IS NULL"/>
                <constraint path="Employee.age" op="IS NOT NULL"/>
                <constraint path="Employee.fullTime" op="=" value="true"/>
                </query>
            </template>'''
        t = Template.from_xml(xml, model)
        self.assertEqual(str(t.get_logic()), "(A or B) and C")

        xml = '''<template name="bad_cl"><query name="bad_cl" model="testmodel" view="Employee.name Employee.age" constraintLogic="A or B or (D and E) and C">
                <constraint path="Employee.name" op="IS NULL"/>
                <constraint path="Employee.age" op="IS NOT NULL"/>
                <constraint path="Employee.fullTime" op="=" value="true"/>
                <constraint path="Employee.name" op="IS NULL"/>
                </query>
            </template>'''
        t = Template.from_xml(xml, model)
        self.assertEqual(str(t.get_logic()), "(A or B or D) and C")
    def testIrrelevantConstraintLogic(self):
        """Should fix up bad logic"""
        model = self.service.model

        xml = '''<template name="bad_cl"><query name="bad_cl" model="testmodel" view="Employee.name Employee.age" constraintLogic="A and B and C"/></template>'''
        t = Template.from_xml(xml, model)
        self.assertEqual(str(t.get_logic()), "")

        xml = '''<template name="bad_cl"><query name="bad_cl" model="testmodel" view="Employee.name Employee.age" constraintLogic="A and B or (D and E) and C"/></template>'''
        t = Template.from_xml(xml, model)
        self.assertEqual(str(t.get_logic()), "")

        xml = '''<template name="bad_cl"><query name="bad_cl" model="testmodel" view="Employee.name Employee.age" constraintLogic="A or B or (D and E) and C">
                <constraint path="Employee.name" op="IS NULL"/><constraint path="Employee.age" op="IS NOT NULL"/>
                </query>
            </template>'''
        t = Template.from_xml(xml, model)
        self.assertEqual(str(t.get_logic()), "A or B")

        xml = '''<template name="bad_cl"><query name="bad_cl" model="testmodel" view="Employee.name Employee.age" constraintLogic="A or B or (D and E) and C">
                <constraint path="Employee.name" op="IS NULL"/><constraint path="Employee.age" op="IS NOT NULL"/><constraint path="Employee.fullTime" op="=" value="true"/>
                </query>
            </template>'''
        t = Template.from_xml(xml, model)
        self.assertEqual(str(t.get_logic()), "(A or B) and C")

        xml = '''<template name="bad_cl"><query name="bad_cl" model="testmodel" view="Employee.name Employee.age" constraintLogic="A or B or (D and E) or C">
                <constraint path="Employee.name" op="IS NULL"/><constraint path="Employee.age" op="IS NOT NULL"/><constraint path="Employee.fullTime" op="=" value="true"/>
                </query>
            </template>'''
        t = Template.from_xml(xml, model)
        self.assertEqual(str(t.get_logic()), "A or B or C")

        xml = '''<template name="bad_cl"><query name="bad_cl" model="testmodel" view="Employee.name Employee.age" constraintLogic="A or B and (D and E) or C">
                <constraint path="Employee.name" op="IS NULL"/>
                <constraint path="Employee.age" op="IS NOT NULL"/>
                <constraint path="Employee.fullTime" op="=" value="true"/>
                </query>
            </template>'''
        t = Template.from_xml(xml, model)
        self.assertEqual(str(t.get_logic()), "(A or B) and C")

        xml = '''<template name="bad_cl"><query name="bad_cl" model="testmodel" view="Employee.name Employee.age" constraintLogic="A or B or (D and E) and C">
                <constraint path="Employee.name" op="IS NULL"/>
                <constraint path="Employee.age" op="IS NOT NULL"/>
                <constraint path="Employee.fullTime" op="=" value="true"/>
                <constraint path="Employee.name" op="IS NULL"/>
                </query>
            </template>'''
        t = Template.from_xml(xml, model)
        self.assertEqual(str(t.get_logic()), "(A or B or D) and C")
    def testCodesInOrder(self):
        """Should associate the right constraints with the right codes"""
        model = self.service.model

        xml = '''
          <template name="codesNotInOrder">
              <query nampe="codesNotInOrder" model="testmodel" view="Employee.name Employee.age">
                  <constraint path="Employee.name" op="=" value="foo" code="X"/>
                  <constraint path="Employee.name" op="=" value="bar" code="Y"/>
                  <constraint path="Employee.name" op="=" value="baz" code="Z"/>
              </query>
          </template>
          '''
        t = Template.from_xml(xml, model)
        v = None
        try:
            v = t.get_constraint("X").value
        except:
            pass

        self.assertIsNotNone(v, msg = "Query (%s) should have a constraint with the code 'X'" % t)
        self.assertEqual("foo", v, msg = "should be the correct constraint")
    def testCodesInOrder(self):
        """Should associate the right constraints with the right codes"""
        model = self.service.model

        xml = '''
          <template name="codesNotInOrder">
              <query nampe="codesNotInOrder" model="testmodel" view="Employee.name Employee.age">
                  <constraint path="Employee.name" op="=" value="foo" code="X"/>
                  <constraint path="Employee.name" op="=" value="bar" code="Y"/>
                  <constraint path="Employee.name" op="=" value="baz" code="Z"/>
              </query>
          </template>
          '''
        t = Template.from_xml(xml, model)
        v = None
        try:
            v = t.get_constraint("X").value
        except:
            pass

        self.assertIsNotNone(
            v, msg="Query (%s) should have a constraint with the code 'X'" % t)
        self.assertEqual("foo", v, msg="should be the correct constraint")