def test_pollerset_insert_last(self): """ PollerSet insert_first puts new rows last""" first_row = model.PollerRow() second_row = model.PollerRow() self.obj.insert(0, first_row) eq_(len(self.obj.poller_rows), 1) eq_(first_row.position, 0) self.obj.append(second_row) eq_(len(self.obj.poller_rows), 2) eq_(first_row.position, 0) eq_(second_row.position, 1)
def create_poller_sets(self): no_backend = model.Backend.by_display_name(u'No Backend') for row in database_data.poller_sets: (ps_name, at_name, poller_rows) = row atype = model.AttributeType.by_display_name(at_name) if atype is None: raise ValueError( "Attribute type {0} not found.".format(at_name)) ps = model.PollerSet(ps_name) ps.attribute_type = atype poller_row_pos = 0 for poller_row in poller_rows: pr = model.PollerRow() pr.poller_set = ps pr.poller = model.Poller.by_display_name(poller_row[0]) if pr.poller is None: raise ValueError("Bad poller name \"{0}\".".format( poller_row[0])) if poller_row[1] == u'': pr.backend = no_backend else: pr.backend = model.Backend.by_display_name(poller_row[1]) if pr.backend is None: raise ValueError("Bad backend name \"{0}\".".format( poller_row[1])) pr.position = poller_row_pos poller_row_pos += 1 ps.poller_rows.append(pr) model.DBSession.add(ps)
def test_pollerset_row_to(self): """ PollerSet row_to relocates third row to position 3""" first_row = model.PollerRow() second_row = model.PollerRow() third_row = model.PollerRow() self.obj.insert(0, first_row) self.obj.append(second_row) self.obj.append(third_row) eq_(len(self.obj.poller_rows), 3) eq_(first_row.position, 0) eq_(second_row.position, 1) eq_(third_row.position, 2) self.obj.row_to(1, third_row) eq_(len(self.obj.poller_rows), 3) eq_(first_row.position, 0) eq_(second_row.position, 2) eq_(third_row.position, 1)
def test_pollerset_row_swap(self): """ PollerSet row_swap swaps rows 2 and 3""" first_row = model.PollerRow() second_row = model.PollerRow() third_row = model.PollerRow() self.obj.insert(0, first_row) self.obj.append(second_row) self.obj.append(third_row) eq_(len(self.obj.poller_rows), 3) eq_(first_row.position, 0) eq_(second_row.position, 1) eq_(third_row.position, 2) self.obj.row_swap(1, 2) eq_(len(self.obj.poller_rows), 3) eq_(first_row.position, 0) eq_(second_row.position, 2) eq_(third_row.position, 1)