def test_empty_col_sequence(self):
        """
        Test utils.reset_sequence on a column without a Sequence()

        This only tests that reset_sequence() doesn't fail if there is
        no sequence.
        """

        # test that a column without an explicit sequence works
        table = Table('test_reset_sequence', self.metadata,
                           Column('id', Integer, primary_key=True))
        self.metadata.create_all()
        #self.insert = table.insert()#.compile()
        #db.engine.execute(self.insert, values=[{'id': 1}])
        utils.reset_sequence(table.c.id)
Example #2
0
    def test_empty_col_sequence(self):
        """
        Test utils.reset_sequence on a column without a Sequence()

        This only tests that reset_sequence() doesn't fail if there is
        no sequence.
        """

        # test that a column without an explicit sequence works
        table = Table('test_reset_sequence', self.metadata,
                      Column('id', Integer, primary_key=True))
        self.metadata.create_all()
        #self.insert = table.insert()#.compile()
        #db.engine.execute(self.insert, values=[{'id': 1}])
        utils.reset_sequence(table.c.id)
def setUp_data():
    """
    bauble.plugins.plants.test.setUp_test_data()

    if this method is called again before tearDown_test_data is called you
    will get an error about the test data rows already existing in the database
    """
    import copy
    for mapper, data in test_data_table_control:
        table = mapper.__table__
        # insert row by row instead of doing an insert many since each
        # row will have different columns
        for row in data:
            table.insert().execute(row).close()
        for col in table.c:
            utils.reset_sequence(col)
 def test_with_col_sequence(self):
     """
     Test utils.reset_sequence on a column that has an Sequence()
     """
     # UPDATE: 10/18/2011 -- we don't use Sequence() explicitly,
     # just autoincrement=True on primary_key columns so this test
     # probably isn't necessary
     table = Table('test_reset_sequence', self.metadata,
                   Column('id', Integer,
                          Sequence('test_reset_sequence_id_seq'),
                          primary_key=True, unique=True))
     self.metadata.create_all()
     rangemax = 10
     for i in range(1, rangemax+1):
         table.insert().values(id=i).execute()
     utils.reset_sequence(table.c.id)
     currval = self.get_currval(table.c.id)
     self.assert_(currval > rangemax, currval)
def setUp_data():
    """
    create_test_data()
    #if this method is called again before tearDown_test_data is called you
    #will get an error about the test data rows already existing in the database
    """
    for cls, data in test_data_table_control:
        table = cls.__table__
        for row in data:
            table.insert().execute(row).close()
        for col in table.c:
            utils.reset_sequence(col)
    i = Institution()
    i.name = u'TestInstitution'
    i.technical_contact = u'TestTechnicalContact Name'
    i.email = u'*****@*****.**'
    i.contact = u'TestContact Name'
    i.code = u'TestCode'
Example #6
0
 def test_with_col_sequence(self):
     """
     Test utils.reset_sequence on a column that has an Sequence()
     """
     # UPDATE: 10/18/2011 -- we don't use Sequence() explicitly,
     # just autoincrement=True on primary_key columns so this test
     # probably isn't necessary
     table = Table(
         'test_reset_sequence', self.metadata,
         Column('id',
                Integer,
                Sequence('test_reset_sequence_id_seq'),
                primary_key=True,
                unique=True))
     self.metadata.create_all()
     rangemax = 10
     for i in range(1, rangemax + 1):
         table.insert().values(id=i).execute()
     utils.reset_sequence(table.c.id)
     currval = self.get_currval(table.c.id)
     self.assert_(currval > rangemax, currval)
            error(traceback.format_exc())
            transaction.rollback()
            self.__error = True
            self.__error_exc = e
            raise
        else:
            transaction.commit()

        # unfortunately inserting an explicit value into a column that
        # has a sequence doesn't update the sequence, we shortcut this
        # by setting the sequence manually to the max(column)+1
        col = None
        try:
            for table, filename in sorted_tables:
                for col in table.c:
                    utils.reset_sequence(col)
        except Exception, e:
            col_name = None
            try:
                col_name = col.name
            except Exception:
                pass
            msg = _('Error: Could not set the sequence for column: %s') \
                  % col_name
            utils.message_details_dialog(_(utils.xml_safe_utf8(msg)),
                                         traceback.format_exc(),
                                         type=gtk.MESSAGE_ERROR)


# TODO: we don't use the progress dialog any more but we'll leave this
# around to remind us when we support cancelling via the progress statusbar
Example #8
0
            logger.error(traceback.format_exc())
            transaction.rollback()
            self.__error = True
            self.__error_exc = e
            raise
        else:
            transaction.commit()

        # unfortunately inserting an explicit value into a column that
        # has a sequence doesn't update the sequence, we shortcut this
        # by setting the sequence manually to the max(column)+1
        col = None
        try:
            for table, filename in sorted_tables:
                for col in table.c:
                    utils.reset_sequence(col)
        except Exception, e:
            col_name = None
            try:
                col_name = col.name
            except Exception:
                pass
            msg = _('Error: Could not set the sequence for column: %s') \
                % col_name
            utils.message_details_dialog(_(utils.xml_safe(msg)),
                                         traceback.format_exc(),
                                         type=gtk.MESSAGE_ERROR)

# TODO: we don't use the progress dialog any more but we'll leave this
# around to remind us when we support cancelling via the progress statusbar
#