Exemple #1
0
    def test_info_public_keys(self):
        """Test DomainObject to_public_json method works."""
        user = User()
        user.name = 'daniel'
        user.info = dict(container='3', avatar='img.png', token='secret')
        user_dict = user.dictize()
        json = user.to_public_json()
        err_msg = "Wrong value"
        assert json['name'] == user.name, err_msg
        err_msg = "Missing fields"
        assert json.keys().sort() == user.public_attributes().sort(), err_msg
        err_msg = "There should be info keys"
        assert json['info']['container'] == '3', err_msg
        assert json['info']['avatar'] == 'img.png', err_msg
        err_msg = "This key should be missing"
        assert json['info'].get('token') is None, err_msg

        json = user.to_public_json(data=user_dict)
        err_msg = "Wrong value"
        assert json['name'] == user.name, err_msg
        err_msg = "Missing fields"
        assert json.keys().sort() == user.public_attributes().sort(), err_msg
        err_msg = "There should be info keys"
        assert json['info']['container'] == '3', err_msg
        assert json['info']['avatar'] == 'img.png', err_msg
        err_msg = "This key should be missing"
        assert json['info'].get('token') is None, err_msg
    def test_user_public_attributes(self):
        """Test public attributes works."""
        user = User(email_addr="*****@*****.**",
                    name="johndoe",
                    pro=1,
                    fullname="John Doe",
                    locale="en")
        public_attributes = [
            'created', 'name', 'fullname', 'locale', 'info', 'n_answers',
            'registered_ago', 'rank', 'score'
        ]

        user.set_password("juandiso")
        print(sorted(public_attributes))
        print(sorted(user.public_attributes()))
        assert sorted(public_attributes) == sorted(user.public_attributes())
        data = user.to_public_json()
        err_msg = "There are some keys that should not be public"
        assert sorted(list(data.keys())) == sorted(public_attributes), err_msg
        all_attributes = list(user.dictize().keys())
        s = set(public_attributes)
        private_attributes = [x for x in all_attributes if x not in s]
        for attr in private_attributes:
            err_msg = "This attribute should be private %s" % attr
            assert data.get(attr) is None, err_msg
Exemple #3
0
    def test_to_public_json(self):
        """Test DomainObject to_public_json method works."""
        user = User()
        user.name = 'daniel'
        user_dict = user.dictize()
        json = user.to_public_json()
        err_msg = "Wrong value"
        assert json['name'] == user.name, err_msg
        err_msg = "Missing fields"
        assert json.keys().sort() == user.public_attributes().sort(), err_msg

        json = user.to_public_json(data=user_dict)
        err_msg = "Wrong value"
        assert json['name'] == user.name, err_msg
        err_msg = "Missing fields"
        assert json.keys().sort() == user.public_attributes().sort(), err_msg
Exemple #4
0
    def test_get_users_page_returns_fields(self):
        user = UserFactory.create()
        TaskRunFactory.create(user=user)
        fields = User.public_attributes()

        users = cached_users.get_users_page(1)

        for field in fields:
            assert field in list(users[0].keys()), field
        assert len(list(users[0].keys())) == len(fields)
Exemple #5
0
    def test_get_users_page_returns_fields(self):
        user = UserFactory.create()
        TaskRunFactory.create(user=user)
        fields = User.public_attributes()

        users = cached_users.get_users_page(1)

        for field in fields:
            assert field in users[0].keys(), field
        assert len(users[0].keys()) == len(fields)
Exemple #6
0
    def test_get_leaderboard_returns_fields(self):
        """Test CACHE USERS get_leaderboard returns user fields"""
        user = UserFactory.create()
        TaskRunFactory.create(user=user)
        fields = User.public_attributes()

        leaderboard = cached_users.get_leaderboard(1)

        for field in fields:
            assert field in leaderboard[0].keys(), field
        assert len(leaderboard[0].keys()) == len(fields)
    def test_info_public_keys(self):
        """Test DomainObject to_public_json method works."""
        user = User()
        user.name = 'daniel'
        user.info = dict(container='3',
                         avatar='img.png',
                         token='secret',
                         badges=['awesome.png', 'incredible.png'],
                         hidden=True)
        user_dict = user.dictize()
        json = user.to_public_json()
        err_msg = "Wrong value"
        assert json['name'] == user.name, err_msg
        err_msg = "Missing fields"
        assert list(
            json.keys()).sort() == user.public_attributes().sort(), err_msg
        err_msg = "There should be info keys"
        assert json['info']['container'] == '3', err_msg
        assert json['info']['avatar'] == 'img.png', err_msg
        err_msg = "This key should be missing"
        assert json['info'].get('token') is None, err_msg

        json = user.to_public_json(data=user_dict)
        err_msg = "Wrong value"
        assert json['name'] == user.name, err_msg
        err_msg = "Missing fields"
        assert list(
            json.keys()).sort() == user.public_attributes().sort(), err_msg
        err_msg = "There should be info keys"
        assert json['info']['container'] == '3', err_msg
        assert json['info']['avatar'] == 'img.png', err_msg
        err_msg = "This key should be missing"
        assert json['info'].get('token') is None, err_msg

        with patch.dict(self.flask_app.config,
                        {'USER_INFO_PUBLIC_FIELDS': ['badges']}):
            json = user.to_public_json()
            assert list(json['info'].keys()).sort() == User().public_info_keys(
            ).sort(), err_msg
            assert 'badges' in list(json['info'].keys())
            assert 'hidden' not in list(json['info'].keys())
Exemple #8
0
    def test_get_leaderboard_returns_fields(self):
        """Test CACHE USERS get_leaderboard returns user fields"""
        user = UserFactory.create()
        TaskRunFactory.create(user=user)
        fields = User.public_attributes()

        update_leaderboard()
        leaderboard = cached_users.get_leaderboard(1)

        for field in fields:
            assert field in leaderboard[0].keys(), field
        assert len(leaderboard[0].keys()) == len(fields)
Exemple #9
0
    def test_user_public_attributes(self):
        """Test public attributes works."""
        user = User(
            email_addr="*****@*****.**",
            name="johndoe",
            pro=1,
            fullname="John Doe",
            locale="en")
        public_attributes = ['created', 'name', 'fullname', 'locale', 'info',
                             'task_runs', 'registered_ago', 'rank', 'score']

        user.set_password("juandiso")
        assert public_attributes.sort() == user.public_attributes().sort()
        data = user.to_public_json()
        err_msg = "There are some keys that should not be public"
        assert data.keys().sort() == public_attributes.sort(), err_msg
        all_attributes = user.dictize().keys()
        s = set(public_attributes)
        private_attributes = [x for x in all_attributes if x not in s]
        for attr in private_attributes:
            err_msg = "This attribute should be private %s" % attr
            assert data.get(attr) is None, err_msg