コード例 #1
0
ファイル: __init__.py プロジェクト: sydneyjd/pjuu
    def tearDown(self):
        """Flush the Redis database and drop the Mongo database

        """
        # Clear the databases
        r.flushdb()

        # Clean up Mongo only after each test.
        m.cx.drop_database(app.config.get('MONGO_DBNAME'))

        self.app_ctx.pop()
コード例 #2
0
ファイル: __init__.py プロジェクト: pjuu/pjuu
    def tearDown(self):
        """Flush the Redis database and drop the Mongo database

        """
        # Clear the databases
        r.flushdb()

        # Clean up Mongo only after each test.
        m.cx.drop_database(app.config.get("MONGO_DBNAME"))

        self.app_ctx.pop()
コード例 #3
0
ファイル: __init__.py プロジェクト: Velody/pjuu
    def setUp(self):
        """Recreate our indexes inside MongoDB

        """
        # Create flask app and context
        self.app = create_app(config_dict={
            'TESTING': 'True',
            'SERVER_NAME': 'localhost',
            'WTF_CSRF_ENABLED': False,
            'MONGO_DBNAME': 'pjuu_testing',
            'REDIS_DB': 2,
            'SESSION_REDIS_DB': 3
        })
        self.app_ctx = self.app.app_context()
        self.app_ctx.push()

        r.flushdb()

        # Ensure the MongoDB indexes are present
        ensure_indexes()
コード例 #4
0
ファイル: __init__.py プロジェクト: sydneyjd/pjuu
    def setUp(self):
        """Recreate our indexes inside MongoDB

        """
        # Create flask app and context
        self.app = create_app(
            config_dict={
                'TESTING': 'True',
                'SERVER_NAME': 'localhost',
                'WTF_CSRF_ENABLED': False,
                'MONGO_DBNAME': 'pjuu_testing',
                'REDIS_DB': 2,
                'SESSION_REDIS_DB': 3
            })
        self.app_ctx = self.app.app_context()
        self.app_ctx.push()

        r.flushdb()

        # Ensure the MongoDB indexes are present
        ensure_indexes()
コード例 #5
0
ファイル: __init__.py プロジェクト: pjuu/pjuu
    def setUp(self):
        """Recreate our indexes inside MongoDB

        """
        # Create flask app and context
        self.app = create_app(
            config_dict={
                "TESTING": "True",
                "SERVER_NAME": "localhost",
                "WTF_CSRF_ENABLED": False,
                "MONGO_DBNAME": "pjuu_testing",
                "REDIS_DB": 2,
                "SESSION_REDIS_DB": 3,
            }
        )
        self.app_ctx = self.app.app_context()
        self.app_ctx.push()

        r.flushdb()

        # Ensure the MongoDB indexes are present
        ensure_indexes()
コード例 #6
0
ファイル: test_users_backend.py プロジェクト: buskirka/pjuu
    def test_follow_unfollow_get_followers_following_is_following(self):
        """
        Test everything about following. There is not that much to it to
        deserve 3 seperate methods.
        """
        # Create two test users
        user1 = create_account('user1', '*****@*****.**', 'Password')
        user2 = create_account('user2', '*****@*****.**', 'Password')
        # Ensure is_following() is false atm
        self.assertFalse(is_following(user1, user2))
        self.assertFalse(is_following(user2, user1))
        # Ensure user 1 can follow user 2
        self.assertTrue(follow_user(user1, user2))
        # Ensure the user can't follow them again
        self.assertFalse(follow_user(user1, user2))
        # And visa-versa
        self.assertTrue(follow_user(user2, user1))
        # Ensre the user can't follow them again
        self.assertFalse(follow_user(user2, user1))
        # Ensure the id's are in the Redis sorted sets, followers and following
        self.assertIn(user2, r.zrange(k.USER_FOLLOWING.format(user1), 0, -1))
        self.assertIn(user2, r.zrange(k.USER_FOLLOWERS.format(user1), 0, -1))
        self.assertIn(user1, r.zrange(k.USER_FOLLOWING.format(user2), 0, -1))
        self.assertIn(user1, r.zrange(k.USER_FOLLOWERS.format(user2), 0, -1))
        # Ensure the get_followers and get_following functions return
        # the correct data
        self.assertEqual(len(get_following(user1).items), 1)
        self.assertEqual(len(get_following(user1).items), 1)
        self.assertEqual(len(get_following(user2).items), 1)
        self.assertEqual(len(get_following(user2).items), 1)
        # Ensure the totals are correct
        self.assertEqual(get_following(user1).total, 1)
        self.assertEqual(get_followers(user1).total, 1)
        self.assertEqual(get_following(user2).total, 1)
        self.assertEqual(get_followers(user2).total, 1)

        # Make sure is_following() returns correctly
        self.assertTrue(is_following(user1, user2))
        self.assertTrue(is_following(user2, user1))

        # User 1 unfollow user 2 and ensure the sorted sets are updated
        self.assertTrue(unfollow_user(user1, user2))
        self.assertNotIn(user2,
                         r.zrange(k.USER_FOLLOWING.format(user1), 0, -1))
        self.assertNotIn(user1,
                         r.zrange(k.USER_FOLLOWERS.format(user2), 0, -1))

        # Ensure the user can't unfollow the user again
        self.assertFalse(unfollow_user(user1, user2))
        # Ensure is_following shows correctly
        self.assertFalse(is_following(user1, user2))

        # Test what happens when we delete an account.

        # Ensure user 2 is still following user1
        self.assertTrue(is_following(user2, user1))

        # This should clean
        delete_account(user1)

        # Ensure this has cleaned user2 following list
        self.assertFalse(is_following(user2, user1))

        # Ensure get_followers and get_following return the correct value for
        # user2
        self.assertEqual(len(get_following(user2).items), 0)
        # Ensure the totals are correct
        self.assertEqual(get_following(user2).total, 0)
        self.assertEqual(get_followers(user2).total, 0)
        # Make sure is_following() returns correctly
        self.assertFalse(is_following(user1, user2))
        self.assertFalse(is_following(user2, user1))

        # I don't want to play with the above testing to much. I am adding
        # in a test for self cleaning lists. I am going to reset this test
        # case by manually flushing the Redis database :)
        r.flushdb()
        # Back to normal, I don't like artificially uping the number of tests.

        # Test the self cleaning lists in case there is an issue with Redis
        # during an account deletion. We need 2 new users.
        user1 = create_account('user1', '*****@*****.**', 'Password')
        user2 = create_account('user2', '*****@*****.**', 'Password')

        # Follow each other.
        self.assertTrue(follow_user(user1, user2))
        self.assertTrue(follow_user(user2, user1))

        # Manually delete user1
        m.db.users.remove({'_id': user1})

        # Ensure user1 appears in both user2's followers and following lists
        self.assertIn(user1, r.zrange(k.USER_FOLLOWERS.format(user2), 0, -1))
        self.assertIn(user1, r.zrange(k.USER_FOLLOWING.format(user2), 0, -1))

        # Ensure if we actuallt get the lists from the backend functions user1
        # is not there
        self.assertEqual(get_followers(user2).total, 0)
        self.assertEqual(get_following(user2).total, 0)