Coverage for tests/test_postgresql.py : 62%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# This file is part of daf_butler. # # Developed for the LSST Data Management System. # This product includes software developed by the LSST Project # (http://www.lsst.org). # See the COPYRIGHT file at the top-level directory of this distribution # for details of code ownership. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>.
# It's possible but silly to have testing.postgresql installed without # having the postgresql server installed (because then nothing in # testing.postgresql would work), so we use the presence of that module # to test whether we can expect the server to be available.
def setUpClass(cls): cls.server = testing.postgresql.Postgresql()
def tearDownClass(cls): cls.server.stop()
namespace = f"namespace_{secrets.token_hex(8).lower()}" return PostgresqlDatabase.fromUri(origin=origin, uri=self.server.url(), namespace=namespace)
return PostgresqlDatabase.fromUri(origin=database.origin, uri=self.server.url(), namespace=database.namespace, writeable=writeable)
yield self.getNewConnection(database, writeable=False)
"""Test that too-long names for database entities other than tables and columns (which we preserve, and just expect to fit) are shrunk. """ db = self.makeEmptyDatabase(origin=1) with db.declareStaticTables(create=True) as context: # Table and field names are each below the 63-char limit even when # accounting for the prefix, but their combination (which will # appear in sequences and constraints) is not. tableName = "a_table_with_a_very_very_long_42_char_name" fieldName1 = "a_column_with_a_very_very_long_43_char_name" fieldName2 = "another_column_with_a_very_very_long_49_char_name" context.addTable( tableName, ddl.TableSpec( fields=[ ddl.FieldSpec( fieldName1, dtype=sqlalchemy.BigInteger, autoincrement=True, primaryKey=True ), ddl.FieldSpec( fieldName2, dtype=sqlalchemy.String, length=16, nullable=False, ), ], unique={(fieldName2,)}, ) ) # Add another table, this time dynamically, with a foreign key to the # first table. db.ensureTableExists( tableName + "_b", ddl.TableSpec( fields=[ ddl.FieldSpec( fieldName1 + "_b", dtype=sqlalchemy.BigInteger, autoincrement=True, primaryKey=True ), ddl.FieldSpec( fieldName2 + "_b", dtype=sqlalchemy.String, length=16, nullable=False, ), ], foreignKeys=[ ddl.ForeignKeySpec(tableName, source=(fieldName2 + "_b",), target=(fieldName2,)), ] ) )
unittest.main() |