aboutsummaryrefslogtreecommitdiff
path: root/tests/fixtures.py
blob: bc783847cc847e9494340881f30d22864349ab53 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from pyaggr3g470r.models import db_create, db_empty, User, Article, Feed


def populate_db(db):
    role_admin, role_user = db_create(db)
    user1, user2 = [User(nickname=name, email="%s@test.te" % name,
                         pwdhash=name, roles=[role_user], activation_key="")
                    for name in ["user1", "user2"]]
    db.session.add(user1)
    db.session.add(user2)
    db.session.commit()

    for user in (user1, user2):
        for feed_name in ['feed1', 'feed2', 'feed3']:
            feed = Feed(link=feed_name, user_id=user.id,
                        title="%r %r" % (user.nickname, feed_name))
            db.session.add(feed)
            db.session.commit()
            for article in ['article1', 'article2', 'article3']:
                article = Article(entry_id=article, link=article,
                                  feed_id=feed.id, user_id=user.id,
                                  title="%r %r %r" % (user.nickname,
                                                      feed.title, article),
                                  content=article)
                db.session.add(article)
            db.session.commit()

    db.session.commit()


def reset_db(db):
    db_empty(db)
bgstack15