Example #1
0
def populate_db():
    fcontr = FeedController()
    ccontr = CategoryController()
    uctrl = UserController()
    uctrl.create(is_admin=True,
                 is_api=True,
                 cluster_enabled=False,
                 login='******',
                 password='******')
    user1, user2 = [
        uctrl.create(login=name,
                     cluster_enabled=False,
                     email="*****@*****.**" % name,
                     password=name) for name in ["user1", "user2"]
    ]

    for iteration in range(2):
        article_total = 0

        for user in (user1, user2):
            for iter_cat in range(3):
                cat_id = None
                if iter_cat:
                    cat_id = ccontr.create(user_id=user.id,
                                           name=to_name(
                                               user, iteration, iter_cat)).id
                feed_id = fcontr.create(
                    link="feed%d%d" % (iteration, iter_cat),
                    user_id=user.id,
                    category_id=cat_id,
                    title=to_name(user, iteration, iter_cat, iter_cat)).id
                for iter_art in range(3):
                    entry = to_name(user, iteration, iter_cat, iter_cat,
                                    iter_art)

                    tags = [
                        to_name(user, iteration, iter_cat, iter_cat, iter_art,
                                str(i)) for i in range(2)
                    ]
                    article_total += 1
                    ArticleController().create(
                        entry_id=entry,
                        feed_id=feed_id,
                        user_id=user.id,
                        tags=tags,
                        category_id=cat_id,
                        title=entry,
                        link='http://test.te/%d' % article_total,
                        date=utc_now() + timedelta(seconds=iteration),
                        content="content %d" % article_total)

    session.commit()
    session.flush()
    ClusterController().clusterize_pending_articles()
Example #2
0
    def process_ids(cls, social_id, username, email):  # pragma: no cover

        labels = {"method": "get", "uri": "/oauth/callback/" + cls.provider}
        if social_id is None:
            SERVER.labels(result="4XX", **labels).inc()
            raise UnprocessableEntity('No social id, authentication failed')
        ucontr = UserController()
        try:
            user = ucontr.get(**{'%s_identity' % cls.provider: social_id})
        except NotFound:
            user = None
        if not user and not conf.oauth.allow_signup:
            SERVER.labels(result="4XX", **labels).inc()
            raise BadRequest('Account creation is not allowed through OAuth.')
        if not user:
            if username and not ucontr.read(login=username).count():
                login = username
            else:
                login = '******' % (cls.provider, username or social_id)
            user = ucontr.create(
                **{
                    '%s_identity' % cls.provider: social_id,
                    'login': login,
                    'email': email
                })
        jwt_ext = current_app.extensions['jwt']
        access_token = jwt_ext.jwt_encode_callback(user).decode('utf8')
        SERVER.labels(result="2XX", **labels).inc()
        return {
            "access_token":
            "%s %s" % (conf.auth.jwt_header_prefix, access_token)
        }, 200
Example #3
0
 def test_password(self):
     login = '******'
     passwd = 'test_password'
     ucontr = UserController()
     user = ucontr.create(login=login, password=passwd)
     self.assertNotEqual(passwd, user.password)
     self.assertEqual(user, ucontr.check_password(login, passwd))
     self.assertIsNone(ucontr.check_password(login, passwd * 2))
     passwd *= 2
     ucontr.update({'id': user.id}, {'password': passwd})
     user = ucontr.get(id=user.id)
     self.assertNotEqual(passwd, user.password)
     self.assertEqual(user, ucontr.check_password(login, passwd))
     self.assertIsNone(ucontr.check_password(login, passwd * 2))