Beispiel #1
0
    def test_search_by_query22_underscore(self):
        """can use fields starting with an underscore"""

        import datetime
        Family = self.Family
        Genus = self.Genus
        from bauble.plugins.plants.species_model import Species
        from bauble.plugins.garden.accession import Accession
        from bauble.plugins.garden.location import Location
        from bauble.plugins.garden.plant import Plant
        family2 = Family(family=u'family2')
        g2 = Genus(family=family2, genus=u'genus2')
        f3 = Family(family=u'fam3', qualifier=u's. lat.')
        g3 = Genus(family=f3, genus=u'Ixora')
        sp = Species(sp=u"coccinea", genus=g3)
        ac = Accession(species=sp, code=u'1979.0001')
        lc = Location(name=u'loc1', code=u'loc1')
        pp = Plant(accession=ac, code=u'01', location=lc, quantity=1)
        pp._last_updated = datetime.datetime(2009, 2, 13)
        self.session.add_all([family2, g2, f3, g3, sp, ac, lc, pp])
        self.session.commit()

        mapper_search = search.get_strategy('MapperSearch')
        self.assertTrue(isinstance(mapper_search, search.MapperSearch))

        s = 'plant where _last_updated < |datetime|2000,1,1|'
        results = mapper_search.search(s, self.session)
        self.assertEqual(results, set())

        s = 'plant where _last_updated > |datetime|2000,1,1|'
        results = mapper_search.search(s, self.session)
        self.assertEqual(results, set([pp]))
Beispiel #2
0
    def test_search_by_query22Symbolic(self):
        "query with &&, ||, !"

        # test does not depend on plugin functionality
        Family = self.Family
        Genus = self.Genus
        family2 = Family(family=u'family2')
        g2 = Genus(family=family2, genus=u'genus2')
        f3 = Family(family=u'fam3', qualifier=u's. lat.')
        g3 = Genus(family=f3, genus=u'genus3')
        self.session.add_all([family2, g2, f3, g3])
        self.session.commit()

        mapper_search = search.get_strategy('MapperSearch')
        self.assertTrue(isinstance(mapper_search, search.MapperSearch))

        s = 'genus where genus=genus2 && family.family=fam3'
        results = mapper_search.search(s, self.session)
        self.assertEqual(len(results), 0)

        s = 'family where family=family1 || family=fam3'
        results = mapper_search.search(s, self.session)
        self.assertEqual(len(results), 2)

        s = 'family where ! family=family1'
        results = mapper_search.search(s, self.session)
        self.assertEqual(len(results), 2)
Beispiel #3
0
    def test_search_by_query22like(self):
        "query with MapperSearch, joined tables, LIKE"

        # test does not depend on plugin functionality
        Family = self.Family
        Genus = self.Genus
        family2 = Family(family=u'family2')
        family3 = Family(family=u'afamily3')
        genus21 = Genus(family=family2, genus=u'genus21')
        genus31 = Genus(family=family3, genus=u'genus31')
        genus32 = Genus(family=family3, genus=u'genus32')
        genus33 = Genus(family=family3, genus=u'genus33')
        f3 = Family(family=u'fam3')
        g3 = Genus(family=f3, genus=u'genus31')
        self.session.add_all(
            [family3, family2, genus21, genus31, genus32, genus33, f3, g3])
        self.session.commit()

        mapper_search = search.get_strategy('MapperSearch')
        self.assertTrue(isinstance(mapper_search, search.MapperSearch))

        # test partial string matches on a query
        s = 'genus where family.family like family%'
        results = mapper_search.search(s, self.session)
        self.assertEquals(set(results), set([self.genus, genus21]))
Beispiel #4
0
    def test_search_by_query13(self):
        "query with MapperSearch, single table, p1 AND p2"

        # test does not depend on plugin functionality
        Family = self.Family
        Genus = self.Genus
        family2 = Family(family=u'family2')
        genus2 = Genus(family=family2, genus=u'genus2')
        f3 = Family(family=u'fam3')
        g3 = Genus(family=f3, genus=u'genus2')
        g4 = Genus(family=f3, genus=u'genus4')
        self.session.add_all([family2, genus2, f3, g3, g4])
        self.session.commit()

        mapper_search = search.get_strategy('MapperSearch')
        self.assertTrue(isinstance(mapper_search, search.MapperSearch))

        s = 'genus where id>1 AND id<3'
        results = mapper_search.search(s, self.session)
        self.assertEqual(len(results), 1)
        result = results.pop()
        self.assertEqual(result.id, 2)

        s = 'genus where id>0 AND id<3'
        results = list(mapper_search.search(s, self.session))
        self.assertEqual(len(results), 2)
        self.assertEqual(set(i.id for i in results), set([1, 2]))
Beispiel #5
0
    def test_search_by_expression_genus_like_contains_eq(self):
        mapper_search = search.get_strategy('MapperSearch')
        self.assertTrue(isinstance(mapper_search, search.MapperSearch))
        Family = self.Family
        f2 = Family(family=u'family2')
        f3 = Family(family=u'afamily3')
        f4 = Family(family=u'fam4')
        self.session.add_all([f3, f2, f4])
        self.session.commit()

        # search for family by domain
        results = mapper_search.search('family contains fam', self.session)
        self.assertEquals(len(results), 4)  # all do
        results = mapper_search.search('family like f%', self.session)
        self.assertEquals(len(results), 3)  # three start by f
        results = mapper_search.search('family like af%', self.session)
        self.assertEquals(len(results), 1)  # one starts by af
        results = mapper_search.search('family like fam', self.session)
        self.assertEquals(len(results), 0)
        results = mapper_search.search('family = fam', self.session)
        self.assertEquals(len(results), 0)
        results = mapper_search.search('family = fam4', self.session)
        self.assertEquals(len(results), 1)  # exact name match
        results = mapper_search.search('family = Fam4', self.session)
        self.assertEquals(len(results), 0)  # = is case sensitive
        results = mapper_search.search('family like Fam4', self.session)
        self.assertEquals(len(results), 1)  # like is case insensitive
        results = mapper_search.search('family contains FAM', self.session)
        self.assertEquals(len(results), 4)  # they case insensitively do
Beispiel #6
0
    def test_between_evaluate(self):
        'use BETWEEN value and value'
        Family = self.Family
        Genus = self.Genus
        from bauble.plugins.plants.species_model import Species
        from bauble.plugins.garden.accession import Accession
        #from bauble.plugins.garden.location import Location
        #from bauble.plugins.garden.plant import Plant
        family2 = Family(family=u'family2')
        g2 = Genus(family=family2, genus=u'genus2')
        f3 = Family(family=u'fam3', qualifier=u's. lat.')
        g3 = Genus(family=f3, genus=u'Ixora')
        sp = Species(sp=u"coccinea", genus=g3)
        ac = Accession(species=sp, code=u'1979.0001')
        self.session.add_all([family2, g2, f3, g3, sp, ac])
        self.session.commit()

        mapper_search = search.get_strategy('MapperSearch')
        self.assertTrue(isinstance(mapper_search, search.MapperSearch))

        s = 'accession where code between "1978" and "1980"'
        results = mapper_search.search(s, self.session)
        self.assertEqual(results, set([ac]))
        s = 'accession where code between "1980" and "1980"'
        results = mapper_search.search(s, self.session)
        self.assertEqual(results, set())
Beispiel #7
0
 def test_can_grab_existing_families(self):
     all_families = self.session.query(Family).all()
     orc = Family.retrieve_or_create(self.session, {"rank": "family", "epithet": "Orchidaceae"})
     leg = Family.retrieve_or_create(self.session, {"rank": "family", "epithet": "Leguminosae"})
     pol = Family.retrieve_or_create(self.session, {"rank": "family", "epithet": "Polypodiaceae"})
     sol = Family.retrieve_or_create(self.session, {"rank": "family", "epithet": "Solanaceae"})
     self.assertEquals(set(all_families), set([orc, pol, leg, sol]))
Beispiel #8
0
    def setUp(self):
        super(AggregatingFunctions, self).setUp()
        db.engine.execute('delete from genus')
        db.engine.execute('delete from family')
        db.engine.execute('delete from species')
        db.engine.execute('delete from accession')
        from bauble.plugins.plants import Family, Genus, Species
        f1 = Family(family=u'Rutaceae', qualifier=u'')
        g1 = Genus(family=f1, genus=u'Citrus')
        sp1 = Species(sp=u"medica", genus=g1)
        sp2 = Species(sp=u"maxima", genus=g1)
        sp3 = Species(sp=u"aurantium", genus=g1)

        f2 = Family(family=u'Sapotaceae')
        g2 = Genus(family=f2, genus=u'Manilkara')
        sp4 = Species(sp=u'zapota', genus=g2)
        sp5 = Species(sp=u'zapotilla', genus=g2)
        g3 = Genus(family=f2, genus=u'Pouteria')
        sp6 = Species(sp=u'stipitata', genus=g3)

        f3 = Family(family=u'Musaceae')
        g4 = Genus(family=f3, genus=u'Musa')
        self.session.add_all(
            [f1, f2, f3, g1, g2, g3, g4, sp1, sp2, sp3, sp4, sp5, sp6])
        self.session.commit()
Beispiel #9
0
 def test_where_can_object_be_found_before_commit(self):  # disabled
     raise SkipTest("Not Implemented")
     fab = Family.retrieve_or_create(self.session, {"rank": "family", "epithet": "Fabaceae"})
     # created in a session, it's not in other sessions
     other_session = db.Session()
     db_families = other_session.query(Family).all()
     fab = Family.retrieve_or_create(other_session, {"rank": "family", "epithet": "Fabaceae"})
     self.assertFalse(fab in db_families)  # fails, why?
Beispiel #10
0
 def test_where_can_object_be_found_after_commit(self):
     fab = Family.retrieve_or_create(self.session, {"rank": "family", "epithet": "Fabaceae"})
     ## after commit it's in database.
     self.session.commit()
     other_session = db.Session()
     all_families = other_session.query(Family).all()
     fab = Family.retrieve_or_create(other_session, {"rank": "family", "epithet": "Fabaceae"})
     self.assertTrue(fab in all_families)
Beispiel #11
0
 def test_str(self):
     """
     Test that the family str function works as expected
     """
     f = Family()
     self.assert_(str(f) == repr(f))
     f = Family(family=u"fam")
     self.assert_(str(f) == "fam")
     f.qualifier = "s. lat."
     self.assert_(str(f) == "fam s. lat.")
    def test_search_by_query22(self):
        "query with MapperSearch, joined tables, multiple predicates"

        # test does not depend on plugin functionality
        Family = self.Family
        Genus = self.Genus
        family2 = Family(epithet=u'family2')
        g2 = Genus(family=family2, epithet=u'genus2')
        f3 = Family(epithet=u'fam3', aggregate=u'agg.')
        g3 = Genus(family=f3, epithet=u'genus3')
        self.session.add_all([family2, g2, f3, g3])
        self.session.commit()

        mapper_search = search.get_strategy('MapperSearch')
        self.assertTrue(isinstance(mapper_search, search.MapperSearch))

        s = 'genus where epithet=genus2 AND family.epithet=fam3'
        results = mapper_search.search(s, self.session)
        self.assertEqual(len(results), 0)

        s = 'genus where epithet=genus3 AND family.epithet=fam3'
        results = mapper_search.search(s, self.session)
        self.assertEqual(len(results), 1)
        g0 = list(results)[0]
        self.assertTrue(isinstance(g0, Genus))
        self.assertEqual(g0.id, g3.id)

        s = 'genus where family.epithet="Orchidaceae" AND family.aggregate=""'
        results = mapper_search.search(s, self.session)
        r = list(results)
        self.assertEqual(r, [])

        s = 'genus where family.epithet=fam3 AND family.aggregate=""'
        results = mapper_search.search(s, self.session)
        self.assertEqual(results, set([]))

        # sqlite3 stores None as the empty string.
        s = 'genus where family.aggregate=""'
        results = mapper_search.search(s, self.session)
        self.assertEqual(results, set([g2]))

        # test where the column is ambiguous so make sure we choose
        # the right one, in this case we want to make sure we get the
        # aggregate on the family and not the genus
        s = 'plant where accession.species.genus.family.epithet="Orchidaceae" '\
            'AND accession.species.genus.family.aggregate=""'
        results = mapper_search.search(s, self.session)
        self.assertEqual(results, set([]))
Beispiel #13
0
 def test_family_nocreate_noupdateeq_existing(self):
     ## retrieve same object, we only give the keys
     obj = Family.retrieve_or_create(
         self.session, {"object": "taxon", "rank": "familia", "epithet": "Leguminosae"}, create=False, update=False
     )
     self.assertTrue(obj is not None)
     self.assertEquals(obj.qualifier, "s. str.")
 def genus_completion_cell_data_func(column, renderer, model, treeiter,
                                     data=None):
     '''
     '''
     v = model[treeiter][0]
     renderer.set_property('text', '%s (%s)' % (Genus.str(v),
                                                Family.str(v.family)))
 def genus_completion_cell_data_func(column, renderer, model, treeiter,
                                     data=None):
     '''
     '''
     v = model[treeiter][0]
     renderer.set_property('text', '%s (%s)' % (Genus.str(v),
                                                Family.str(v.family)))
    def test_search_by_query21(self):
        "query with MapperSearch, joined tables, one predicate"

        # test does not depend on plugin functionality
        Family = self.Family
        Genus = self.Genus
        family2 = Family(epithet=u'family2')
        genus2 = Genus(family=family2, epithet=u'genus2')
        self.session.add_all([family2, genus2])
        self.session.commit()

        mapper_search = search.get_strategy('MapperSearch')
        self.assertTrue(isinstance(mapper_search, search.MapperSearch))

        # search cls.parent.column
        results = mapper_search.search('genus where family.epithet=family1',
                                       self.session)
        self.assertEquals(len(results), 1)
        g0 = list(results)[0]
        self.assertTrue(isinstance(g0, Genus))
        self.assertEquals(g0.id, self.genus.id)

        # search cls.children.column
        results = mapper_search.search('family where genera.epithet=genus1',
                                       self.session)
        self.assertEquals(len(results), 1)
        f = list(results)[0]
        self.assertEqual(len(results), 1)
        self.assertTrue(isinstance(f, Family))
        self.assertEqual(f.id, self.family.id)
Beispiel #17
0
 def test_family_nocreate_updatediff_existing(self):
     ## update object in self.session
     obj = Family.retrieve_or_create(
         self.session,
         {"object": "taxon", "rank": "familia", "epithet": "Leguminosae", "qualifier": "s. lat."},
         create=False,
         update=True,
     )
     self.assertEquals(obj.qualifier, "s. lat.")
    def test_search_by_query_synonyms(self):
        """SynonymSearch strategy gives all synonyms of given taxon."""
        Family = self.Family
        Genus = self.Genus
        family2 = Family(family=u'family2')
        g2 = Genus(family=family2, genus=u'genus2')
        f3 = Family(family=u'fam3', qualifier=u's. lat.')
        g3 = Genus(family=f3, genus=u'Ixora')
        g4 = Genus(family=f3, genus=u'Schetti')
        self.session.add_all([family2, g2, f3, g3, g4])
        g4.accepted = g3
        self.session.commit()

        mapper_search = search.get_strategy('SynonymSearch')

        s = 'Schetti'
        results = mapper_search.search(s, self.session)
        self.assertEqual(results, [g3])
Beispiel #19
0
 def test_can_create_family(self):
     all_families = self.session.query(Family).all()
     fab = Family.retrieve_or_create(self.session, {"rank": "family", "epithet": "Fabaceae"})
     ## it's in the session, it wasn't there before.
     self.assertTrue(fab in self.session)
     self.assertFalse(fab in all_families)
     ## according to the session, it is in the database
     ses_families = self.session.query(Family).all()
     self.assertTrue(fab in ses_families)
    def test_search_by_query_synonyms_disabled(self):
        """SynonymSearch strategy gives all synonyms of given taxon."""
        Family = self.Family
        Genus = self.Genus
        family2 = Family(epithet=u'family2')
        g2 = Genus(family=family2, epithet=u'genus2')
        f3 = Family(epithet=u'fam3', aggregate=u'agg.')
        g3 = Genus(family=f3, epithet=u'Ixora')
        g4 = Genus(family=f3, epithet=u'Schetti')
        self.session.add_all([family2, g2, f3, g3, g4])
        g4.accepted = g3
        self.session.commit()

        prefs.prefs['bauble.search.return_synonyms'] = False
        mapper_search = search.get_strategy('SynonymSearch')

        s = 'Schetti'
        results = mapper_search.search(s, self.session)
        self.assertEqual(results, [])
    def test_search_by_query22None(self):
        """query with MapperSearch, joined tables, predicates using None

        results are irrelevant, because sqlite3 uses the empty string to
        represent None

        """

        # test does not depend on plugin functionality
        Family = self.Family
        Genus = self.Genus
        family2 = Family(epithet=u'family2')
        g2 = Genus(family=family2, epithet=u'genus2')
        f3 = Family(epithet=u'fam3', aggregate=u'agg.')
        g3 = Genus(family=f3, epithet=u'genus3')
        self.session.add_all([family2, g2, f3, g3])
        self.session.commit()

        mapper_search = search.get_strategy('MapperSearch')
        self.assertTrue(isinstance(mapper_search, search.MapperSearch))

        s = 'genus where family.aggregate is None'
        results = mapper_search.search(s, self.session)
        self.assertEqual(results, set([]))

        # make sure None isn't treated as the string 'None' and that
        # the query picks up the is operator
        s = 'genus where author is None'
        results = mapper_search.search(s, self.session)
        self.assertEqual(results, set([]))

        s = 'genus where author is not None'
        resultsNone = mapper_search.search(s, self.session)
        s = 'genus where NOT author = ""'
        resultsEmptyString = mapper_search.search(s, self.session)
        self.assertEqual(resultsNone, resultsEmptyString)

        s = 'genus where author != None'
        resultsNone = mapper_search.search(s, self.session)
        s = 'genus where NOT author = ""'
        resultsEmptyString = mapper_search.search(s, self.session)
        self.assertEqual(resultsNone, resultsEmptyString)
Beispiel #22
0
 def test_can_grab_existing_genera(self):
     orc = Family.retrieve_or_create(self.session, {"rank": "family", "epithet": "Orchidaceae"})
     all_genera_orc = self.session.query(Genus).filter(Genus.family == orc).all()
     mxl = Genus.retrieve_or_create(
         self.session, {"ht-rank": "family", "ht-epithet": "Orchidaceae", "rank": "genus", "epithet": "Maxillaria"}
     )
     enc = Genus.retrieve_or_create(
         self.session, {"ht-rank": "family", "ht-epithet": "Orchidaceae", "rank": "genus", "epithet": "Encyclia"}
     )
     self.assertTrue(mxl in set(all_genera_orc))
     self.assertTrue(enc in set(all_genera_orc))
 def syn_cell_data_func(column, renderer, model, iter, data=None):
     '''
     '''
     v = model[iter][0]
     author = None
     if v.author is None:
         author = ''
     else:
         author = utils.xml_safe(unicode(v.author))
     renderer.set_property('markup', '<i>%s</i> %s (<small>%s</small>)' \
                           % (Genus.str(v), author, Family.str(v.family)))
 def setUp(self):
     super(SearchTests, self).setUp()
     db.engine.execute('delete from genus')
     db.engine.execute('delete from family')
     from bauble.plugins.plants.family import Family
     from bauble.plugins.plants.genus import Genus
     self.family = Family(family=u'family1', qualifier=u's. lat.')
     self.genus = Genus(family=self.family, genus=u'genus1')
     self.Family = Family
     self.Genus = Genus
     self.session.add_all([self.family, self.genus])
     self.session.commit()
 def setUp(self):
     super(SearchTests, self).setUp()
     db.engine.execute('delete from genus')
     db.engine.execute('delete from family')
     from bauble.plugins.plants.family import Family
     from bauble.plugins.plants.genus import Genus
     self.family = Family(epithet=u'family1', aggregate=u'agg.')
     self.genus = Genus(family=self.family, epithet=u'genus1')
     self.Family = Family
     self.Genus = Genus
     self.session.add_all([self.family, self.genus])
     self.session.commit()
 def _syn_data_func(column, cell, model, iter, data=None):
     v = model[iter][0]
     syn = v.synonym
     cell.set_property('markup', '<i>%s</i> %s (<small>%s</small>)' \
                       % (Genus.str(syn),
                          utils.xml_safe(unicode(syn.author)),
                          Family.str(syn.family)))
     # set background color to indicate its new
     if v.id is None:
         cell.set_property('foreground', 'blue')
     else:
         cell.set_property('foreground', None)
 def setUp(self):
     super(BinomialSearchTests, self).setUp()
     db.engine.execute('delete from genus')
     db.engine.execute('delete from family')
     from bauble.plugins.plants.family import Family
     from bauble.plugins.plants.genus import Genus
     from bauble.plugins.plants.species import Species
     f1 = Family(epithet=u'family1', aggregate=u'agg.')
     g1 = Genus(family=f1, epithet=u'genus1')
     f2 = Family(epithet=u'family2')
     g2 = Genus(family=f2, epithet=u'genus2')
     f3 = Family(epithet=u'fam3', aggregate=u'agg.')
     g3 = Genus(family=f3, epithet=u'Ixora')
     sp = Species(epithet=u"coccinea", genus=g3)
     sp2 = Species(epithet=u"peruviana", genus=g3)
     sp3 = Species(epithet=u"chinensis", genus=g3)
     g4 = Genus(family=f3, epithet=u'Pachystachys')
     sp4 = Species(epithet=u'coccinea', genus=g4)
     self.session.add_all([f1, f2, g1, g2, f3, g3, sp, sp2, sp3, g4, sp4])
     self.session.commit()
     self.ixora, self.ic, self.pc = g3, sp, sp4
    def test_search_by_query_binomial(self):
        """can use genus_species binomial identification"""

        raise SkipTest("related to issue 192")
        Family = self.Family
        Genus = self.Genus
        from bauble.plugins.plants.species_model import Species
        family2 = Family(family=u'family2')
        g2 = Genus(family=family2, genus=u'genus2')
        f3 = Family(family=u'fam3', qualifier=u's. lat.')
        g3 = Genus(family=f3, genus=u'Ixora')
        sp = Species(sp=u"coccinea", genus=g3)
        self.session.add_all([family2, g2, f3, g3, sp])
        self.session.commit()

        mapper_search = search.get_strategy('MapperSearch')
        self.assertTrue(isinstance(mapper_search, search.MapperSearch))

        s = '"Ixora coccinea"'
        results = mapper_search.search(s, self.session)
        self.assertEqual(results, set([sp]))
    def test_search_by_query_vernacural(self):
        """can find species by vernacular name"""

        Family = self.Family
        Genus = self.Genus
        from bauble.plugins.plants.species_model import Species
        from bauble.plugins.plants.species_model import VernacularName
        family2 = Family(epithet=u'family2')
        g2 = Genus(family=family2, epithet=u'genus2')
        f3 = Family(epithet=u'fam3', aggregate=u'agg.')
        g3 = Genus(family=f3, epithet=u'Ixora')
        sp = Species(epithet=u"coccinea", genus=g3)
        vn = VernacularName(name=u"coral rojo", language=u"es", species=sp)
        self.session.add_all([family2, g2, f3, g3, sp, vn])
        self.session.commit()

        mapper_search = search.get_strategy('MapperSearch')
        self.assertTrue(isinstance(mapper_search, search.MapperSearch))

        s = "rojo"
        results = mapper_search.search(s, self.session)
        self.assertEqual(results, set([sp]))
    def test_search_by_query22id(self):
        "query with MapperSearch, joined tables, test on id of dependent table"

        # test does not depend on plugin functionality
        Family = self.Family
        Genus = self.Genus
        family2 = Family(epithet=u'family2')
        genus2 = Genus(family=family2, epithet=u'genus2')
        f3 = Family(epithet=u'fam3')
        g3 = Genus(family=f3, epithet=u'genus3')
        self.session.add_all([family2, genus2, f3, g3])
        self.session.commit()

        mapper_search = search.get_strategy('MapperSearch')
        self.assertTrue(isinstance(mapper_search, search.MapperSearch))

        # id is an ambiguous column because it occurs on plant,
        # accesion and species...the results here don't matter as much
        # as the fact that the query doesn't raise and exception
        s = 'plant where accession.species.id=1'
        results = mapper_search.search(s, self.session)
        list(results)
    def test_search_by_query12(self):
        "query with MapperSearch, single table, p1 OR p2"

        # test does not depend on plugin functionality
        Family = self.Family
        Genus = self.Genus
        f2 = Family(epithet=u'family2')
        g2 = Genus(family=f2, epithet=u'genus2')
        f3 = Family(epithet=u'fam3')
        # g3(homonym) is here just to have two matches on one value
        g3 = Genus(family=f3, epithet=u'genus2')
        g4 = Genus(family=f3, epithet=u'genus4')
        self.session.add_all([f2, g2, f3, g3, g4])
        self.session.commit()

        mapper_search = search.get_strategy('MapperSearch')
        self.assertTrue(isinstance(mapper_search, search.MapperSearch))

        # search with or conditions
        s = 'genus where epithet=genus2 OR epithet=genus1'
        results = mapper_search.search(s, self.session)
        self.assertEquals(sorted([r.id for r in results]),
                          [g.id for g in (self.genus, g2, g3)])
 def setUp(self):
     super(InOperatorSearch, self).setUp()
     db.engine.execute('delete from genus')
     db.engine.execute('delete from family')
     from bauble.plugins.plants.family import Family
     from bauble.plugins.plants.genus import Genus
     self.family = Family(epithet=u'family1', id=1)
     self.g1 = Genus(family=self.family, epithet=u'genus1', id=1)
     self.g2 = Genus(family=self.family, epithet=u'genus2', id=2)
     self.g3 = Genus(family=self.family, epithet=u'genus3', id=3)
     self.g4 = Genus(family=self.family, epithet=u'genus4', id=4)
     self.Family = Family
     self.Genus = Genus
     self.session.add_all([self.family, self.g1, self.g2, self.g3, self.g4])
     self.session.commit()
    def test_search_by_query12(self):
        "query with MapperSearch, single table, p1 OR p2"

        # test does not depend on plugin functionality
        Family = self.Family
        Genus = self.Genus
        family2 = Family(family=u'family2')
        genus2 = Genus(family=family2, genus=u'genus2')
        f3 = Family(family=u'fam3')
        g3 = Genus(family=f3, genus=u'genus2')
        g4 = Genus(family=f3, genus=u'genus4')
        self.session.add_all([family2, genus2, f3, g3, g4])
        self.session.commit()

        mapper_search = search.get_strategy('MapperSearch')
        self.assertTrue(isinstance(mapper_search, search.MapperSearch))

        # search with or conditions
        s = 'genus where genus=genus2 OR genus=genus1'
        results = mapper_search.search(s, self.session)
        self.assertEqual(len(results), 3)
        self.assert_(
            sorted([r.id for r in results]) ==
            [g.id for g in (self.genus, genus2, g3)])
    def test_search_by_query11(self):
        "query with MapperSearch, single table, single test"

        # test does not depend on plugin functionality
        Family = self.Family
        Genus = self.Genus
        family2 = Family(epithet=u'family2')
        genus2 = Genus(family=family2, epithet=u'genus2')
        self.session.add_all([family2, genus2])
        self.session.commit()

        mapper_search = search.get_strategy('MapperSearch')
        self.assertTrue(isinstance(mapper_search, search.MapperSearch))

        # search cls.column
        results = mapper_search.search('genus where epithet=genus1',
                                       self.session)
        self.assertEquals(len(results), 1)
        f = list(results)[0]
        self.assertTrue(isinstance(f, Genus))
        self.assertEqual(f.id, self.family.id)
Beispiel #35
0
 def test_grabbing_same_params_same_output_existing(self):
     orc1 = Family.retrieve_or_create(self.session, {"rank": "family", "epithet": "Orchidaceae"})
     orc2 = Family.retrieve_or_create(self.session, {"rank": "family", "epithet": "Orchidaceae"})
     self.assertTrue(orc1 is orc2)
Beispiel #36
0
 def test_grabbing_same_params_same_output_new(self):
     fab1 = Family.retrieve_or_create(self.session, {"rank": "family", "epithet": "Fabaceae"})
     fab2 = Family.retrieve_or_create(self.session, {"rank": "family", "epithet": "Fabaceae"})
     self.assertTrue(fab1 is fab2)
Beispiel #37
0
 def test_family_nocreate_noupdate_noexisting(self):
     # do not create if not existing
     obj = Family.retrieve_or_create(
         self.session, {"object": "taxon", "rank": "familia", "epithet": "Arecaceae"}, create=False
     )
     self.assertEquals(obj, None)