Beispiel #1
0
    def test_read_foreign_keys_reverse(self, connection):
        
        name = None
        table2s = mro.table2.select()
        table1_refs = [str(x.table1_id.value) for x in table2s if x.table1_id.value is not None]
        table = mro.table1.select_one('id in (' + ','.join(table1_refs) + ')')

        assert table.name != None
        assert table.table2s != None
        assert len(table.table2s) > 1

        num_table2s = len(table.table2s)
        mro.table2(name = 'table2_added', table1_id = table.id)

        assert len(table.table2s) == num_table2s
        table.table2s() # updates the reference list
        assert len(table.table2s) == num_table2s + 1

        num_table2s = len(table.table2s)
        table2 = mro.table2(name = 'table2_added2', table1_id = None)
        assert len(table.table2s) == num_table2s

        with pytest.raises(PermissionError) as excinfo:
            table.table2s[0] = table2
        assert excinfo.value.args[0] == "Cannot set specific value on foreign key reference list."
        
        table.table2s.append(table2)

        assert len(table.table2s) == num_table2s + 1
        # make sure the change is reflected in the database
        table.table2s() # updates the reference list
        assert len(table.table2s) == num_table2s + 1
Beispiel #2
0
 def test_write_foreign_keys(self, connection):
     table1 = mro.table1.select_one()
     table2sCount = len(table1.table2s)
     table2 = mro.table2(name = 'table2_added2', table1_id = None)
     table2.table1_id = table1
     assert table2.table1_id.value == table1.id
     assert table2sCount == len(table1.table2s)
     table1.table2s()
     assert table2sCount + 1 == len(table1.table2s)