コード例 #1
0
 def setUp(self):
     reset_registry(registry)
     self.r = define_relationship('user_follow', User, User)
     self.foo = User.objects.create_user(username='******')
     self.bar = User.objects.create_user(username='******')
     self.jaz = User.objects.create_user(username='******')
     reset_relationship('user_follow')
コード例 #2
0
 def setUp(self):
     reset_registry(registry)
     self.r = define_relationship('user_follow', User, User)
     self.foo = User.objects.create_user(username='******')
     self.bar = User.objects.create_user(username='******')
     self.jaz = User.objects.create_user(username='******')
     reset_relationship('user_follow')
コード例 #3
0
def test_define_relationship():
    r1 = define_relationship('rel1', 'auth.User', 'auth.User')
    assert 'rel1' in registry
    assert r1 in registry.values()
    assert isinstance(r1, Relationship)
    assert r1.name == 'rel1'
    assert r1.from_content_type.model_class() is User
    assert r1.to_content_type.model_class() is User
    assert str(r1) == 'rel1 (user -> user)'
    
    r2 = define_relationship('rel2', User, User)
    assert 'rel2' in registry
    assert r2 in registry.values()
    assert isinstance(r2, Relationship)
    assert r2.name == 'rel2'
    assert r2.from_content_type.model_class() is User
    assert r2.to_content_type.model_class() is User
    assert str(r2) == 'rel2 (user -> user)'
コード例 #4
0
def test_define_relationship():
    r1 = define_relationship('rel1', 'auth.User', 'auth.User')
    assert 'rel1' in registry
    assert r1 in registry.values()
    assert isinstance(r1, Relationship)
    assert r1.name == 'rel1'
    assert r1.from_content_type.model_class() is User
    assert r1.to_content_type.model_class() is User
    assert str(r1) == 'rel1 (user -> user)'

    r2 = define_relationship('rel2', User, User)
    assert 'rel2' in registry
    assert r2 in registry.values()
    assert isinstance(r2, Relationship)
    assert r2.name == 'rel2'
    assert r2.from_content_type.model_class() is User
    assert r2.to_content_type.model_class() is User
    assert str(r2) == 'rel2 (user -> user)'
コード例 #5
0
def test_connection_removed():
    foo = User.objects.create_user(username='******')
    bar = User.objects.create_user(username='******')
    r = define_relationship('rel', User, User)

    def handler(signal, sender, connection, **kwargs):
        assert sender is r
        assert connection.relationship is r
        assert connection.from_object == foo
        assert connection.to_object == bar
        assert kwargs == {}

    try:
        connection_removed.connect(handler, sender=r)
        c = create_connection(r, foo, bar)
        c.delete()
    finally:
        connection_removed.disconnect(handler)
        foo.delete()
        bar.delete()
コード例 #6
0
def test_connection_removed():
    foo = User.objects.create_user(username='******')
    bar = User.objects.create_user(username='******')
    r = define_relationship('rel', User, User)
    
    def handler(signal, sender, connection, **kwargs):
        assert sender is r
        assert connection.relationship is r
        assert connection.from_object == foo
        assert connection.to_object == bar
        assert kwargs == {}
    
    try:
        connection_removed.connect(handler, sender=r)
        c = create_connection(r, foo, bar)
        c.delete()
    finally:
        connection_removed.disconnect(handler)
        foo.delete()
        bar.delete()
コード例 #7
0
def test_get_relationship():
    r = define_relationship('rel', User, User)
    assert r is get_relationship('rel')
    assert r is get_relationship(r)
    assert_raises(Relationship.DoesNotExist, get_relationship, 'invalid')
コード例 #8
0
def test_relationship_name_max_length():
    assert_raises(AssertionError, define_relationship, 'x' * (NAME_MAX_LENGTH + 1), User, User)
    define_relationship('x' * NAME_MAX_LENGTH, User, User)
コード例 #9
0
def test_define_relationship_raises_for_duplicate():
    define_relationship('r1', User, User)
    assert_raises_regex(KeyError, "^'r1'$", define_relationship, 'r1', User, User)
コード例 #10
0
def test_get_relationship():
    r = define_relationship('rel', User, User)
    assert r is get_relationship('rel')
    assert r is get_relationship(r)
    assert_raises(Relationship.DoesNotExist, get_relationship, 'invalid')
コード例 #11
0
def test_relationship_name_max_length():
    assert_raises(AssertionError, define_relationship,
                  'x' * (NAME_MAX_LENGTH + 1), User, User)
    define_relationship('x' * NAME_MAX_LENGTH, User, User)
コード例 #12
0
def test_define_relationship_raises_for_duplicate():
    define_relationship('r1', User, User)
    assert_raises_regex(KeyError, "^'r1'$", define_relationship, 'r1', User,
                        User)