Example #1
0
 def test_default(self):
     """
     should return target class's primary key if no primary_key was passed
     as a kwarg
     """
     association = Association(target_klass=TargetModel, id='whatever')
     self.assertEqual(TargetModel.primary_key(), association.primary_key())
Example #2
0
 def setUp(self):
     self.klass = fixtures.association_models.Test
     self.id = 'associations'
     self.args = { 'foo': 'bar' }
     self.primary_key = 'primary_key'
     self.foreign_key = 'foreign_key'
     self.source_class = fixtures.association_models.Source
     self.association = Association(**self.args)
     self.association.target_klass = self.klass
     self.association.id = self.id
Example #3
0
 def setUp(self):
     self.klass = fixtures.association_models.Test
     self.id = "associations"
     self.args = {"foo": "bar"}
     self.primary_key = "primary_key"
     self.foreign_key = "foreign_key"
     self.source_class = fixtures.association_models.Source
     self.association = Association(self.klass, self.id, **self.args)
Example #4
0
 def test_eager_loadable_lambda(self):
     """should return false if a block is used for the param of
     any finder option"""
     for option in finder_options:
         self.assertEqual(False, Association(
             target_klass=self.klass,
             id=self.id,
             **{
                 option: lambda x: {}
             }
         ).eager_loadable())
Example #5
0
class GenericAssociationTestCase(BaseAssociationTestCase):

    def setUp(self):
        self.klass = fixtures.association_models.Test
        self.id = 'associations'
        self.args = { 'foo': 'bar' }
        self.primary_key = 'primary_key'
        self.foreign_key = 'foreign_key'
        self.source_class = fixtures.association_models.Source
        self.association = Association(**self.args)
        self.association.target_klass = self.klass
        self.association.id = self.id

    def test_initialize(self):
        """should take kwarg arguments on initialize"""
        self.assertEqual(self.klass, self.association.target_klass)
        self.assertEqual(self.id, self.association.id)
        self.assertEqual(self.args, self.association.options)

    def test_type_raises(self):
        """should raise a NotImplementedError on type"""
        self.assertRaises(NotImplementedError, self.association.type)

    def test_polymorphic_raises(self):
        """should raise a NotImplementedError on polymorphic"""
        self.assertRaises(NotImplementedError, self.association.polymorphic)

    def test_colletion_raises(self):
        """should raise a NotImplementedError on collection"""
        self.assertRaises(NotImplementedError, self.association.collection)

    def test_scope_raises(self):
        """should raise a NotImplementedError on scope"""
        self.assertRaises(NotImplementedError, self.association.scope)

    def test_foreign_key_returns_None(self):
        """should return None when no foreign_key was passed"""
        self.assertEqual(None, self.association.foreign_key)

    def test_foreign_key_returns_foreign_key(self):
        """should return the foreign_key that was passed in options"""
        self.association.foreign_key = self.foreign_key
        self.assertEqual(self.foreign_key, self.association.foreign_key)

    def test_eager_loadable(self):
        """should be eager_loadable when the moethods do not rely
        on instance data"""
        association = BelongsTo(target_klass=self.klass, id=self.id)
        self.assertEqual(True, association.eager_loadable())

    def test_eager_loadable_lambda(self):
        """should return false if a block is used for the param of
        any finder option"""
        for option in finder_options:
            self.assertEqual(False, Association(
                target_klass=self.klass,
                id=self.id,
                **{
                    option: lambda x: {}
                }
            ).eager_loadable())

    def test_eager_loadable_poly(self):
        """should return false for polymorphic belongs to associations"""
        association = BelongsTo(target_klass=self.klass, id=self.id, polymorphic=True)
        self.assertEqual(association.eager_loadable(), False)

    def test_source_klass(self):
        """should return the class that is passed in the options"""
        self.association.options['klass'] = self.source_class
        self.assertEqual(self.source_class, self.association.source_klass())