def test_creation_attr_clash(self): """ """ # Create the first Facet attrs = [ { 'name' : 'test_creation_attr_clash_attr1', 'descr' : 'descr1', 'type' : 'string', 'default' : 'abc1', 'history' : True}, { 'name' : 'test_creation_attr_clash_attr2', 'descr' : 'descr2', 'type' : 'string', 'default' : 'abc2', 'history' : False}, { 'name' : 'test_creation_attr_clash_attr3', 'descr' : 'descr3', 'type' : 'string', 'default' : 'abc3'}, ] Facet.create_facet('test_creation_attr_clash_aFacet', 'aDescription', attrs) # Read the data created facet_data_before, attr_data_before = _read_database() # Create another one with one attribute in common attrs = [ { 'name' : 'test_creation_attr_clash_attr4', 'descr' : 'descr1', 'type' : 'string', 'default' : 'abc1', 'history' : True}, { 'name' : 'test_creation_attr_clash_attr2', 'descr' : 'descr2', 'type' : 'string', 'default' : 'abc2', 'history' : False}, { 'name' : 'test_creation_attr_clash_attr5', 'descr' : 'descr3', 'type' : 'string', 'default' : 'abc3'}, ] try: Facet.create_facet('test_creation_attr_clash_bFacet', 'aDescription', attrs) except IntegrityError: pass else: self.assertTrue(False, "Failed to raise error when creating an attribute with the same name") # Read the database again, it should be unchanged facet_data_after, attr_data_after = _read_database() self.assertEqual(facet_data_before, facet_data_after, 'New facet created with conflicting attribute names') self.assertEqual(attr_data_before, attr_data_after, 'New attributes created with conflicting attribute names')
def test_simple_creation(self): """ """ attrs = [ { 'name' : 'test_simple_creation_attr1', 'descr' : 'descr1', 'type' : 'string', 'default' : 'abc1', 'history' : True}, { 'name' : 'test_simple_creation_attr2', 'descr' : 'descr2', 'type' : 'string', 'default' : 'abc2', 'history' : False}, { 'name' : 'test_simple_creation_attr3', 'descr' : 'descr3', 'type' : 'string', 'default' : 'abc3'}, ] facet = Facet.create_facet('test_simple_creation_aFacet', 'aDescription', attrs) cursor = connection.cursor() cursor.execute('select * from facet where id = %s', [facet.id]) data = cursor.fetchall() self.assertEqual(data, ((facet.id, u'test_simple_creation_aFacet', u'aDescription'),), 'Incorrect entry in facet table') cursor.execute('select * from facetattr where facet_id = %s', [facet.id]) data = cursor.fetchall() self.assertEqual(data, ( (data[0][0], u'_test_simple_creation_aFacet', u'Indicates that the Facet is applied to the QArk', facet.id, u'string', None, None, None, 0), (data[1][0], u'test_simple_creation_attr1', u'descr1', facet.id, u'string', None, None, u'abc1', 1), (data[2][0], u'test_simple_creation_attr2', u'descr2', facet.id, u'string', None, None, u'abc2', 0), (data[3][0], u'test_simple_creation_attr3', u'descr3', facet.id, u'string', None, None, u'abc3', 0), ), 'Incorrect entry in facetattr table')
def test_managed_transaction_required(self): """ """ # Read the database all_data_before = _read_database() attrs = [ { 'name' : 'test_managed_transaction_required_attr1', 'descr' : 'descr1', 'type' : 'string', 'default' : 'abc1', 'history' : True}, { 'name' : 'test_managed_transaction_required_attr2', 'descr' : 'descr2', 'type' : 'string', 'default' : 'abc2', 'history' : False}, { 'name' : 'test_managed_transaction_required_attr3', 'descr' : 'descr3', 'type' : 'string', 'default' : 'abc3'}, ] try: Facet.create_facet('test_managed_transaction_required_aFacet', 'aDescription', attrs) except AssertionError: pass else: self.assertTrue(False, "Failed to raise exception when no transaction present") # Read the database again, it should be unchanged all_data_after = _read_database() self.assertEqual(all_data_before, all_data_after, 'Data committed to database outside of transaction')
def test_creation_missing_reqd_attr(self): """ """ # Read the database so far facet_data_before, attr_data_before = _read_database() # Create a Facet with a missing name attrs = [ { 'name' : 'test_creation_missing_reqd_attr1', 'descr' : 'descr1', 'type' : 'string', 'default' : 'abc1', 'history' : True}, { 'name' : 'test_creation_missing_reqd_attr2', 'descr' : 'descr2', 'type' : 'string', 'default' : 'abc2', 'history' : False}, { 'name' : 'test_creation_missing_reqd_attr3', 'descr' : 'descr3', 'type' : 'string', 'default' : 'abc3'}, ] try: Facet.create_facet(None, 'aDescription', attrs) except IntegrityError: pass else: self.assertTrue(False, 'Failed to raise error when creating facet with missing attribute name') # Create a Facet with an attribute with a missing name attrs = [ { 'name' : 'test_creation_missing_reqd_attr4', 'descr' : 'descr1', 'type' : 'string', 'default' : 'abc1', 'history' : True}, { 'name' : 'test_creation_missing_reqd_attr5', 'descr' : 'descr2', 'type' : 'string', 'default' : 'abc2', 'history' : False}, { 'name' : None, 'descr' : 'descr3', 'type' : 'string', 'default' : 'abc3'}, ] try: Facet.create_facet('test_creation_missing_reqd_attr_aFacet', 'aDescription', attrs) except IntegrityError: pass else: self.assertTrue(False, 'Failed to raise error when creating facet with missing attribute name') # Read the database again, it should be unchanged facet_data_after, attr_data_after = _read_database() self.assertEqual(facet_data_before, facet_data_after, 'New facet created with missing facet/attribute name') self.assertEqual(attr_data_before, attr_data_after, 'New attributes created with missing facet/attribute name')