def test_it_should_not_allow_someone_you_have_blocked_to_follow_you(self):
        amico = Amico(redis_connection=self.redis_connection)
        amico.block(1, 11)

        amico.redis_connection.zcard(
            '%s:%s:%s:%s' %
            (Amico.DEFAULTS['namespace'],
             Amico.DEFAULTS['following_key'],
             Amico.DEFAULTS['default_scope_key'],
             11)).should.equal(0)
        amico.redis_connection.zcard(
            '%s:%s:%s:%s' %
            (Amico.DEFAULTS['namespace'],
             Amico.DEFAULTS['blocked_key'],
             Amico.DEFAULTS['default_scope_key'],
             1)).should.equal(1)

        amico.follow(11, 1)

        amico.redis_connection.zcard(
            '%s:%s:%s:%s' %
            (Amico.DEFAULTS['namespace'],
             Amico.DEFAULTS['following_key'],
             Amico.DEFAULTS['default_scope_key'],
             11)).should.equal(0)
        amico.redis_connection.zcard(
            '%s:%s:%s:%s' %
            (Amico.DEFAULTS['namespace'],
             Amico.DEFAULTS['blocked_key'],
             Amico.DEFAULTS['default_scope_key'],
             1)).should.equal(1)
 def test_it_should_return_the_correct_pending_with_list(self):
     amico = Amico(
         options={
             'pending_follow': True},
         redis_connection=self.redis_connection)
     amico.follow(1, 11)
     amico.follow(11, 1)
     amico.pending_with(1).should.equal(["11"])
     amico.pending_with(11).should.equal(["1"])
 def test_it_should_return_true_if_both_individuals_are_following_each_other(
         self):
     amico = Amico(redis_connection=self.redis_connection)
     amico.follow(1, 11)
     amico.is_reciprocated(1, 11).should.be.false
     amico.follow(11, 1)
     amico.is_reciprocated(1, 11).should.be.true
    def test_it_should_return_that_you_are_being_followed(self):
        amico = Amico(redis_connection=self.redis_connection)
        amico.follow(1, 11)
        amico.is_follower(11, 1).should.be.true
        amico.is_follower(1, 11).should.be.false

        amico.follow(11, 1)
        amico.is_follower(1, 11).should.be.true
    def test_it_should_clear_pending_pending_with_relationships(self):
        amico = Amico(
            options={
                'pending_follow': True},
            redis_connection=self.redis_connection)
        amico.follow(1, 11)
        amico.pending_count(11).should.equal(1)

        amico.clear(1)

        amico.pending_count(11).should.equal(0)
    def test_it_should_not_allow_you_to_follow_yourself(self):
        amico = Amico(redis_connection=self.redis_connection)
        amico.follow(1, 1)

        amico.redis_connection.zcard(
            '%s:%s:%s:%s' %
            (Amico.DEFAULTS['namespace'],
             Amico.DEFAULTS['following_key'],
             Amico.DEFAULTS['default_scope_key'],
             1)).should.equal(0)
        amico.redis_connection.zcard(
            '%s:%s:%s:%s' %
            (Amico.DEFAULTS['namespace'],
             Amico.DEFAULTS['followers_key'],
             Amico.DEFAULTS['default_scope_key'],
             1)).should.equal(0)
    def test_it_should_return_the_correct_blocked_by_page_count(self):
        amico = Amico(redis_connection=self.redis_connection)
        self.__add_reciprocal_followers(amico, block_relationship=True)

        amico.blocked_by_page_count(1).should.equal(1)
        amico.blocked_by_page_count(1, 10).should.equal(3)
        amico.blocked_by_page_count(1, 5).should.equal(5)
    def test_it_should_return_the_correct_reciprocated_page_count(self):
        amico = Amico(redis_connection=self.redis_connection)
        self.__add_reciprocal_followers(amico)

        amico.reciprocated_page_count(1).should.equal(1)
        amico.reciprocated_page_count(1, 10).should.equal(3)
        amico.reciprocated_page_count(1, 5).should.equal(5)
    def test_it_should_add_each_individual_to_the_reciprocated_set_if_you_both_follow_each_other(
            self):
        amico = Amico(redis_connection=self.redis_connection)
        amico.follow(1, 11)
        amico.follow(11, 1)

        amico.redis_connection.zcard(
            '%s:%s:%s:%s' %
            (Amico.DEFAULTS['namespace'],
             Amico.DEFAULTS['reciprocated_key'],
             Amico.DEFAULTS['default_scope_key'],
             1)).should.equal(1)
        amico.redis_connection.zcard(
            '%s:%s:%s:%s' %
            (Amico.DEFAULTS['namespace'],
             Amico.DEFAULTS['reciprocated_key'],
             Amico.DEFAULTS['default_scope_key'],
             11)).should.equal(1)
Exemple #10
0
    def test_it_should_return_the_correct_pending_with_page_count(self):
        amico = Amico(
            options={
                'pending_follow': True},
            redis_connection=self.redis_connection)
        self.__add_reciprocal_followers(amico)

        amico.pending_with_page_count(1).should.equal(1)
        amico.pending_with_page_count(1, 10).should.equal(3)
        amico.pending_with_page_count(1, 5).should.equal(5)
Exemple #11
0
 def test_it_should_allow_you_to_block_someone_you_have_blocked(self):
     amico = Amico(redis_connection=self.redis_connection)
     amico.block(1, 11)
     amico.is_blocked(1, 11).should.be.true
     amico.redis_connection.zcard(
         '%s:%s:%s:%s' %
         (Amico.DEFAULTS['namespace'],
          Amico.DEFAULTS['blocked_by_key'],
          Amico.DEFAULTS['default_scope_key'],
          11)).should.equal(1)
     amico.unblock(1, 11)
     amico.is_blocked(1, 11).should.be.false
     amico.redis_connection.zcard(
         '%s:%s:%s:%s' %
         (Amico.DEFAULTS['namespace'],
          Amico.DEFAULTS['blocked_by_key'],
          Amico.DEFAULTS['default_scope_key'],
          11)).should.equal(0)
Exemple #12
0
 def test_following_should_page_correctly(self):
     amico = Amico(redis_connection=self.redis_connection)
     self.__add_reciprocal_followers(amico)
     amico.following(
         1,
         page_options={
             'page': 1,
             'page_size': 5}).should.have.length_of(5)
     amico.following(
         1,
         page_options={
             'page': 1,
             'page_size': 10}).should.have.length_of(10)
     amico.following(
         1,
         page_options={
             'page': 1,
             'page_size': 26}).should.have.length_of(25)
Exemple #13
0
 def test_it_should_return_that_someone_is_blocking_you(self):
     amico = Amico(redis_connection=self.redis_connection)
     amico.block(1, 11)
     amico.is_blocked_by(11, 1).should.be.true
Exemple #14
0
 def test_it_should_respect_scope_when_checking_if_a_relationship_is_reciprocated(
         self):
     amico = Amico(redis_connection=self.redis_connection)
     amico.follow(1, 11, scope='another_scope')
     amico.follow(11, 1, scope='another_scope')
     amico.is_reciprocated(1, 11).should.be.false
     amico.is_reciprocated(1, 11, scope='another_scope').should.be.true
     amico.follow(1, 11)
     amico.follow(11, 1)
     amico.is_reciprocated(1, 11).should.be.true
Exemple #15
0
 def test_it_should_remove_the_pending_relationship_if_you_block_someone(
         self):
     amico = Amico(
         options={
             'pending_follow': True},
         redis_connection=self.redis_connection)
     amico.follow(11, 1)
     amico.is_pending(11, 1).should.be.true
     amico.is_pending_with(1, 11).should.be.true
     amico.block(1, 11)
     amico.is_pending(11, 1).should.be.false
     amico.is_pending_with(1, 11).should.be.false
     amico.is_blocked(1, 11).should.be.true
Exemple #16
0
    def test_it_should_remove_the_pending_relationship_without_following_or_blocking(
            self):
        amico = Amico(
            options={
                'pending_follow': True},
            redis_connection=self.redis_connection)
        amico.follow(1, 11)
        amico.is_pending(1, 11).should.be.true
        amico.is_pending_with(11, 1).should.be.true

        amico.deny(1, 11)

        amico.is_following(1, 11).should.be.false
        amico.is_pending(1, 11).should.be.false
        amico.is_pending_with(11, 1).should.be.false
        amico.is_blocked(1, 11).should.be.false
Exemple #17
0
 def test_it_should_return_the_correct_reciprocated_list(self):
     amico = Amico(redis_connection=self.redis_connection)
     amico.follow(1, 11)
     amico.follow(11, 1)
     amico.reciprocated(1).should.equal(["11"])
     amico.reciprocated(11).should.equal(["1"])
Exemple #18
0
    def test_it_should_remove_the_pending_relationship_and_add_to_following_and_followers_if_accept_is_called_and_add_to_reciprocated_relationship(
            self):
        amico = Amico(
            options={
                'pending_follow': True},
            redis_connection=self.redis_connection)
        amico.follow(1, 11)
        amico.follow(11, 1)
        amico.is_pending(1, 11).should.be.true
        amico.is_pending(11, 1).should.be.true

        amico.accept(1, 11)

        amico.is_pending(1, 11).should.be.false
        amico.is_pending(11, 1).should.be.true
        amico.is_following(1, 11).should.be.true
        amico.is_following(11, 1).should.be.false
        amico.is_follower(11, 1).should.be.true
        amico.is_follower(1, 11).should.be.false

        amico.accept(11, 1)

        amico.is_pending(1, 11).should.be.false
        amico.is_pending(11, 1).should.be.false
        amico.is_following(1, 11).should.be.true
        amico.is_following(11, 1).should.be.true
        amico.is_follower(11, 1).should.be.true
        amico.is_follower(1, 11).should.be.true
        amico.is_reciprocated(1, 11).should.be.true
Exemple #19
0
 def test_it_should_return_the_correct_blocked_by_list(self):
     amico = Amico(redis_connection=self.redis_connection)
     amico.block(11, 1)
     amico.block(12, 1)
     amico.blocked_by(1).should.equal(["12", "11"])
Exemple #20
0
 def test_it_should_return_that_someone_is_being_blocked(self):
     amico = Amico(redis_connection=self.redis_connection)
     amico.block(1, 11)
     amico.is_blocked(1, 11).should.be.true
     amico.is_following(11, 1).should.be.false
Exemple #21
0
    def test_it_should_remove_follower_and_following_relationships(self):
        amico = Amico(redis_connection=self.redis_connection)
        amico.follow(1, 11)
        amico.follow(11, 1)

        amico.following_count(1).should.equal(1)
        amico.followers_count(1).should.equal(1)
        amico.reciprocated_count(1).should.equal(1)
        amico.following_count(11).should.equal(1)
        amico.followers_count(11).should.equal(1)
        amico.reciprocated_count(11).should.equal(1)

        amico.clear(1)

        amico.following_count(1).should.equal(0)
        amico.followers_count(1).should.equal(0)
        amico.reciprocated_count(1).should.equal(0)
        amico.following_count(11).should.equal(0)
        amico.followers_count(11).should.equal(0)
        amico.reciprocated_count(11).should.equal(0)
Exemple #22
0
    def test_it_should_return_the_correct_page_count_for_various_types_of_relationships(
            self):
        amico = Amico(redis_connection=self.redis_connection)
        self.__add_reciprocal_followers(amico, count=6)

        amico.page_count(1, 'following').should.equal(1)
        amico.page_count(1, 'followers').should.equal(1)
        amico.page_count(1, 'reciprocated').should.equal(1)

        self.redis_connection.flushdb()
        self.__add_reciprocal_followers(
            amico,
            count=6,
            block_relationship=True)

        amico.page_count(1, 'blocked').should.equal(1)
        amico.page_count(1, 'blocked_by').should.equal(1)

        self.redis_connection.flushdb()
        amico = Amico(
            options={
                'pending_follow': True},
            redis_connection=self.redis_connection)
        self.__add_reciprocal_followers(amico, count=6)

        amico.page_count(1, 'pending').should.equal(1)
Exemple #23
0
    def test_it_should_clear_blocked_blocked_by_relationships(self):
        amico = Amico(redis_connection=self.redis_connection)
        amico.block(1, 11)
        amico.blocked_count(1).should.equal(1)
        amico.blocked_by_count(11).should.equal(1)

        amico.clear(11)

        amico.blocked_count(1).should.equal(0)
        amico.blocked_by_count(11).should.equal(0)
Exemple #24
0
    def test_it_should_return_the_correct_list_when_calling_all_for_various_types(
            self):
        amico = Amico(redis_connection=self.redis_connection)
        self.__add_reciprocal_followers(amico, count=6)

        for type in ['following', 'followers', 'reciprocated']:
            list = amico.all(1, type)
            list.should.have.length_of(4)

        # pending
        self.redis_connection.flushdb()
        amico = Amico(
            options={
                'pending_follow': True},
            redis_connection=self.redis_connection)
        self.__add_reciprocal_followers(amico, count=6)

        for type in ['following', 'followers', 'reciprocated']:
            list = amico.all(1, type)
            list.should.have.length_of(0)

        amico.all(1, 'pending').should.have.length_of(4)

        # blocked
        self.redis_connection.flushdb()
        amico = Amico(redis_connection=self.redis_connection)
        self.__add_reciprocal_followers(
            amico,
            count=6,
            block_relationship=True)

        for type in ['following', 'followers', 'reciprocated']:
            list = amico.all(1, type)
            list.should.have.length_of(0)

        amico.all(1, 'blocked').should.have.length_of(4)
        amico.all(1, 'blocked_by').should.have.length_of(4)
Exemple #25
0
 def test_it_should_return_the_correct_followers_list(self):
     amico = Amico(redis_connection=self.redis_connection)
     amico.follow(1, 11)
     amico.follow(2, 11)
     amico.followers(11).should.equal(["2", "1"])
Exemple #26
0
 def test_it_should_return_the_correct_following_list(self):
     amico = Amico(redis_connection=self.redis_connection)
     amico.follow(1, 11)
     amico.follow(1, 12)
     amico.following(1).should.equal(["12", "11"])
Exemple #27
0
    def test_it_should_not_allow_you_to_block_yourself(self):
        amico = Amico(redis_connection=self.redis_connection)
        amico.block(1, 1)

        amico.is_blocked(1, 1).should.be.false