def test_random_str(): assert len(random_str(10)) == 10
def install_test_data(dbsession, settings): countries = dbsession.query(Country).all() # Teams teams = [] for __ in xrange(30): team = Team(name=random_str(10), email="%s@%s.%s" % (random_str(10), random_str(7), random_str(3) ), password=random_str(10), country=random.choice(countries), local=random.choice([False, True]), active=random.choice([True, True, False]), ) teams.append(team) dbsession.add_all(teams) # Categories categories = [] for __ in xrange(5): cat = Category(name=random_str(10)) categories.append(cat) dbsession.add_all(categories) # Challenges challenges = [] for __ in xrange(27): if random.randint(0, 100) < 80: cat = random.choice(categories) else: cat = None challenge = Challenge(title=random_str(10), text=random_str(50), solution=random_str(10), base_points=random.choice(range(100, 501, 100)), online=random.choice([True, True, False]), published=random.choice([True, True, False]), category=cat, ) if random.randint(0, 100) > 90: challenge.base_points = 0 challenge.manual = True challenges.append(challenge) dbsession.add_all(challenges) # News announcements = [] for __ in xrange(10): news = News(message=random_str(100), published=(True if random.randint(0, 100) < 90 else False), challenge=random.choice([None] + challenges)) announcements.append(news) dbsession.add_all(announcements) # Submissions submissions = [] for challenge in challenges: for team in teams: if random.randint(0, 100) < 30 or not team.active: continue submission = Submission(additional_pts=0) submission.team = team submission.challenge = challenge submissions.append(submission) dbsession.add_all(submissions) # Mass Mails (dont really send!) mails = [] recipients = [team.email for team in teams] for __ in xrange(10): mail = MassMail(subject=random_str(10), message=random_str(100), recipients=recipients, from_=unicode(settings["mail.default_sender"]), ) mails.append(mail) dbsession.add_all(mails)