Example #1
0
    def test_query_2(self, extract_columns_mock, build_from_clause_mock):
        """Verify function strucutre of query().
        """
        session_mock = Mock()
        map_mock = Mock()

        extract_columns_mock.return_value = self.columns
        build_from_clause_mock.return_value = self.phage

        querying.query(session_mock, self.graph, map_mock, where=self.columns)

        extract_columns_mock.assert_any_call(self.columns)
        build_from_clause_mock.assert_called_once_with(self.graph, [map_mock] +
                                                       self.columns)
Example #2
0
    def query(self, table_map):
        """Queries for ORM object instances conditioned on Filter values.

        :param table_map: SQLAlchemy ORM map object.
        :type table_map: str
        :type table_map: DeclarativeMeta
        :returns: List of mapped object instances.
        :rtype: list
        """
        self.check()

        if not self._values:
            return []

        if isinstance(table_map, str):
            table_map = cartography.get_map(self._mapper, table_map)
        elif isinstance(table_map, DeclarativeMeta):
            pass
        else:
            raise TypeError("Table map object must be either "
                            "type str or DeclarativeMeta.")

        in_clause = self._key.in_(self._values)

        instances = q.query(self._session,
                            self._graph,
                            table_map,
                            where=in_clause)
        return instances
Example #3
0
    def test_query_1(self):
        """Verify query() correctly queries for SQLAlchemy ORM instances.
        """
        phage_map = self.mapper.classes["phage"]

        instances = querying.query(self.session, self.graph, phage_map)

        first_instance = instances[0]

        first_instance.PhageID
        first_instance.Cluster
        first_instance.Subcluster

        self.session.close()
Example #4
0
    def test_query_2(self):
        """Verify query() retrieves expected data.
        """
        phage_map = self.mapper.classes["phage"]

        instances = querying.query(self.session,
                                   self.graph,
                                   phage_map,
                                   where=phage_map.Cluster == "A")

        phageids = []
        for instance in instances:
            phageids.append(instance.PhageID)

        self.assertTrue("Trixie" in phageids)
        self.assertTrue("D29" in phageids)
        self.assertFalse("Myrna" in phageids)

        self.session.close()