Ejemplo n.º 1
0
def iter_data():
    for data in iter_admin_users():
        user = User(**data)
        user.password = '******'
        yield user
    for data in iter_normal_users():
        yield User(**data)
Ejemplo n.º 2
0
 def create_user(self):
     user = User(
         username=self.username.data,
         email=self.email.data,
     )
     user.password = self.password.data
     user.role = User.ROLE_ACTIVE
     with db.auto_commit():
         db.session.add(user)
     return user
Ejemplo n.º 3
0
 def create_user(self):
     user = User(
         username=self.username.data,
         email=self.email.data,
     )
     user.password = self.password.data
     user.role = User.ROLE_ACTIVE
     with db.auto_commit():
         db.session.add(user)
     return user
Ejemplo n.º 4
0
 def get_creator_headers(self):
     user = User(username='******', email='*****@*****.**')
     user.status = 1
     user.role = 9
     self.app.config['ZERQU_CAFE_CREATOR_ROLE'] = 1
     db.session.add(user)
     db.session.commit()
     headers = self.get_authorized_header(
         user_id=user.id, scope='cafe:write',
     )
     return headers
Ejemplo n.º 5
0
 def test_no_permission(self):
     user = User(username='******', email='*****@*****.**')
     user.role = 1
     db.session.add(user)
     db.session.commit()
     self.app.config['ZERQU_CAFE_CREATOR_ROLE'] = 4
     headers = self.get_authorized_header(
         user_id=user.id, scope='cafe:write',
     )
     rv = self.client.post('/api/cafes', headers=headers)
     assert rv.status_code == 403
Ejemplo n.º 6
0
    def test_view_topic_likes(self):
        topic = Topic(title=u'hello', content=u'', user_id=1)
        db.session.add(topic)
        db.session.commit()
        for i in range(10, 100):
            db.session.add(TopicLike(user_id=i, topic_id=topic.id))
            name = 'foo-%d' % i
            user = User(id=i, username=name, email='*****@*****.**' % name)
            db.session.add(user)
        db.session.commit()

        url = '/api/topics/%d/likes' % topic.id
        rv = self.client.get(url)
        data = json.loads(rv.data)
        assert data['pagination']['total'] == 90

        db.session.add(TopicLike(user_id=1, topic_id=topic.id))
        db.session.commit()
        headers = self.get_authorized_header(user_id=2)
        rv = self.client.get(url, headers=headers)
        data = json.loads(rv.data)
        assert data['data'][0]['id'] != 1

        headers = self.get_authorized_header(user_id=1)
        rv = self.client.get(url, headers=headers)
        data = json.loads(rv.data)
        assert data['data'][0]['id'] == 1

        headers = self.get_authorized_header(user_id=12)
        rv = self.client.get(url, headers=headers)
        data = json.loads(rv.data)
        assert data['data'][0]['id'] == 12
Ejemplo n.º 7
0
    def prepare_data(self):
        users = [("zerqu", "*****@*****.**", None, 10), ("test", "*****@*****.**", "test-password", 1)]
        for username, email, password, role in users:
            user = User(username=username, email=email, role=role)
            if password:
                user.password = password
            db.session.add(user)
        db.session.commit()

        client = OAuthClient(
            user_id=1,
            name=u"iOS App",
            client_id="ios",
            client_secret="secret",
            is_confidential=True,
            _redirect_uris="http://localhost/oauth",
        )
        db.session.add(client)
        db.session.commit()
Ejemplo n.º 8
0
 def test_filter_count(self):
     b1 = User.cache.filter_count()
     b2 = User.cache.filter_count(reputation=0)
     for i in range(10):
         user = User(username='******' % i, email='*****@*****.**' % i)
         db.session.add(user)
     db.session.commit()
     a1 = User.cache.filter_count()
     a2 = User.cache.filter_count(reputation=0)
     # will auto clean cache
     assert a1 > b1
     # will not clean cache
     assert a2 == b2
Ejemplo n.º 9
0
    def prepare_data(self):
        users = [
            ('zerqu', '*****@*****.**', None, 10),
            ('test', '*****@*****.**', 'test-password', 1),
        ]
        for username, email, password, role in users:
            user = User(username=username, email=email, role=role)
            if password:
                user.password = password
            db.session.add(user)
        db.session.commit()

        client = OAuthClient(
            user_id=1,
            name=u'iOS App',
            client_id='ios',
            client_secret='secret',
            is_confidential=True,
            _redirect_uris='http://localhost/oauth',
        )
        db.session.add(client)
        db.session.commit()
Ejemplo n.º 10
0
    def test_model_events(self):
        user = User(username='******', email='*****@*****.**')
        db.session.add(user)
        db.session.commit()

        # get from database
        assert user == User.cache.get(user.id)
        # get from cache
        cached_user = User.cache.get(user.id)
        assert user != cached_user
        assert user.id == cached_user.id
        assert User.cache.filter_first(username='******') is not None

        # update cache
        user.username = '******'
        db.session.add(user)
        db.session.commit()
        assert User.cache.get(user.id).username == 'jinja'
        assert User.cache.filter_first(username='******') is None

        # delete cache
        db.session.delete(user)
        db.session.commit()
        assert User.cache.get(user.id) is None
Ejemplo n.º 11
0
    def test_get_many_dict(self):
        assert User.cache.get_dict([]) == {}

        for i in range(10):
            user = User(username='******' % i, email='*****@*****.**' % i)
            db.session.add(user)
        db.session.commit()

        first_id = User.cache.filter_first(username='******').id
        idents = [first_id + i for i in range(10)]
        missed = User.cache.get_dict(idents)
        assert len(missed.keys()) == 10

        cached = User.cache.get_dict(idents)
        assert list(missed.keys()).sort() == list(cached.keys()).sort()

        missed_names = [o.username for o in missed.values()]
        cached_names = [o.username for o in User.cache.get_many(idents)]
        assert missed_names.sort() == cached_names.sort()