def init_database():
    db.create_all()

    country1 = Country(name="TestCountry")
    db.session.add(country1)
    db.session.commit()

    interest1 = Interest(
        activity="testInterest1", interest_class="General", interest_type="Outdoors"
    )
    db.session.add(interest1)
    interest2 = Interest(
        activity="testInterest2", interest_class="Collection", interest_type="Indoors"
    )
    db.session.add(interest2)
    db.session.commit()

    user = User(
        username="******",
        birthdate="1990-03-13",
        gender="Male",
        about_me="Test Test text",
        email="*****@*****.**",
        country_id="1",
    )
    user.set_password("testPassword")
    db.session.add(user)

    db.session.commit()

    yield db

    db.drop_all()
Beispiel #2
0
def init_database():
    db.create_all()

    country1 = Country(name="TestCountry1")
    db.session.add(country1)
    country2 = Country(name="TestCountry2")
    db.session.add(country2)
    db.session.commit()

    user1 = User(
        username="******",
        email="*****@*****.**",
        birthdate="1901-01-01",
        country_id="1",
    )
    user1.set_password("testPassword")
    db.session.add(user1)
    user2 = User(
        username="******",
        email="*****@*****.**",
        birthdate="1912-12-12",
        country_id="2",
    )
    user2.set_password("authTester2Password")
    db.session.add(user2)
    db.session.commit()

    yield db

    db.drop_all()
Beispiel #3
0
def add_users(count):
    click.echo(f"Seeding user table with {count} new users.")
    count_users = 0
    while count_users < int(count):
        try:
            user = User(
                username=fake.name(),
                email=fake.email(),
                birthdate=fake.date(),
                gender="Female",
                about_me=fake.text(max_nb_chars=500),
                country_id=Country.query.order_by(func.random()).first().id,
            )
            user.set_password(fake.text(max_nb_chars=20))

            languages = Language.query.order_by(func.random()).limit(
                randrange(1, 4))
            interests = Interest.query.order_by(func.random()).limit(
                randrange(4, 10))
            # Remove duplicates
            user.languages = list(dict.fromkeys(languages))
            user.interests = list(dict.fromkeys(interests))

            db.session.add(user)
            count_users += 1
        except AssertionError:
            pass  # Skips that user e.g. faker randomized user with same name
    db.session.commit()
    click.echo("Done.")
def init_database():
    db.create_all()

    country1 = Country(name="TestCountry")
    db.session.add(country1)
    db.session.commit()

    language1 = Language(name="testLanguage1")
    db.session.add(language1)
    language2 = Language(name="testLanguage2")
    db.session.add(language2)
    db.session.commit()

    user = User(
        username="******",
        birthdate="1990-03-13",
        gender="Male",
        about_me="Test Test text",
        email="*****@*****.**",
        country_id="1",
    )
    user.set_password("testPassword")
    db.session.add(user)

    db.session.commit()

    yield db

    db.drop_all()
Beispiel #5
0
def create_user():
    body = request.get_json()
    user = User()
    user.from_dict(body)
    user.set_password(body["password"])
    db.session.add(user)
    db.session.commit()
    return user
Beispiel #6
0
def init_database():
    db.create_all()

    country1 = Country(name="Chad")
    db.session.add(country1)
    country2 = Country(name="Sweden")
    db.session.add(country2)
    db.session.commit()

    user1 = User(
        username="******", email="*****@*****.**", country_id="1"
    )
    user1.set_password("testPassword")
    db.session.add(user1)
    user2 = User(
        username="******", email="*****@*****.**", country_id="2"
    )
    user2.set_password("testPass2")
    db.session.add(user2)
    db.session.commit()

    penpal1 = PenPal(created_date=time.time())
    db.session.add(penpal1)
    db.session.commit()

    letter1 = Letter(
        text="Hi I'm letterTester",
        sent_date=time.time(),
        penpal_id=penpal1.id,
        penpal=penpal1,
        user_id=user1.id,
        user=user1,
    )
    db.session.add(letter1)
    letter2 = Letter(
        text="Hi I'm letterTester2",
        sent_date=time.time(),
        penpal_id=penpal1.id,
        penpal=penpal1,
        user_id=user2.id,
        user=user2,
    )
    db.session.add(letter2)
    db.session.commit()

    yield db

    db.drop_all()
Beispiel #7
0
def init_database():
    db.create_all()

    country1 = Country(name="Testina")
    db.session.add(country1)
    country2 = Country(name="Tested states")
    db.session.add(country2)
    country3 = Country(name="Testistan")
    db.session.add(country3)
    db.session.commit()

    user1 = User(
        username="******",
        birthdate="1990-03-13",
        gender="Male",
        about_me="Test Test text",
        email="*****@*****.**",
        country_id="1",
    )
    user1.set_password("testPassword")
    db.session.add(user1)
    user2 = User(
        username="******",
        birthdate="1998-06-22",
        gender="Female",
        about_me="Test Test text",
        email="*****@*****.**",
        country_id="2",
    )
    user2.set_password("testPass2")
    db.session.add(user2)

    db.session.commit()

    yield db

    db.drop_all()