Beispiel #1
0
    def test_get_foreign_key_for(self):
        def add_in_registry():
            @register(Model)
            class Test:

                id = Integer(primary_key=True)

            @register(Model)
            class Test2:

                id = Integer(primary_key=True)
                test_id = Integer(foreign_key=Model.Test.use('id'))

        registry = self.init_registry(add_in_registry)
        mr = ModelRepr('Model.Test2')
        mas = mr.foreign_keys_for(registry, 'Model.Test')
        assert len(mas) == 1
        assert [x.attribute_name for x in mas] == ['test_id']
Beispiel #2
0
 def test_without_model(self, registry_blok):
     with pytest.raises(ModelReprException):
         ModelRepr(None)
Beispiel #3
0
 def test_from_declaration(self):
     mr = ModelRepr('Model.System.Model')
     mra = ModelAdapter(mr)
     assert mr is mra
Beispiel #4
0
 def test_get_registry_name(self, registry_blok):
     mr = ModelRepr('Model.System.Model')
     assert mr.model_name == 'Model.System.Model'
Beispiel #5
0
 def test_get_primary_keys(self, registry_blok):
     registry = registry_blok
     mr = ModelRepr('Model.System.Model')
     mas = mr.primary_keys(registry)
     assert len(mas) == 1
     assert [x.attribute_name for x in mas] == ['name']
Beispiel #6
0
 def test_unexisting_model(self, registry_blok):
     registry = registry_blok
     mr = ModelRepr('Model.Unexisting.Model')
     with pytest.raises(ModelReprException):
         mr.check_model(registry)
Beispiel #7
0
 def test_get_tablename(self, registry_blok):
     registry = registry_blok
     mr = ModelRepr('Model.System.Model')
     assert mr.tablename(registry) == 'system_model'
Beispiel #8
0
 def test_capable_by_model_repr(self):
     assert ModelMapper.capable(ModelRepr('Model.System.Model'))
Beispiel #9
0
 def test_model_repr(self):
     assert ModelMapper(ModelRepr('Model.System.Model'), None)
Beispiel #10
0
 def test_from_declaration(self):
     mr = ModelRepr('Model.System.Model')
     mra = ModelAdapter(mr)
     self.assertIs(mr, mra)
Beispiel #11
0
 def test_str(self, registry_blok):
     mr = ModelRepr('Model.System.Model')
     assert str(mr) == 'Model.System.Model'
Beispiel #12
0
 def test_without_model(self):
     with self.assertRaises(ModelReprException):
         ModelRepr(None)
Beispiel #13
0
 def test_get_primary_keys(self):
     registry = self.init_registry(None)
     mr = ModelRepr('Model.System.Model')
     mas = mr.primary_keys(registry)
     self.assertEqual(len(mas), 1)
     self.assertEqual([x.attribute_name for x in mas], ['name'])
Beispiel #14
0
 def test_get_registry_name(self):
     mr = ModelRepr('Model.System.Model')
     self.assertEqual(mr.model_name, 'Model.System.Model')
Beispiel #15
0
 def test_get_tablename(self):
     registry = self.init_registry(None)
     mr = ModelRepr('Model.System.Model')
     self.assertEqual(mr.tablename(registry), 'system_model')
Beispiel #16
0
 def test_unexisting_model(self):
     registry = self.init_registry(None)
     mr = ModelRepr('Model.Unexisting.Model')
     with self.assertRaises(ModelReprException):
         mr.check_model(registry)