-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
51 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,59 @@ | ||
# -*- coding: utf-8 -*- | ||
import bcrypt | ||
|
||
from cms.db import SessionGen, Task, Contest, Statement, Dataset, Admin | ||
from cmscommon.crypto import build_password | ||
from cms.db import ( | ||
SessionGen, | ||
Task, | ||
Contest, | ||
Statement, | ||
Dataset, | ||
Admin, | ||
User, | ||
Participation, | ||
) | ||
from cms.db.filecacher import FileCacher | ||
from cmsocial.db import SocialContest, SocialTask | ||
from cmsocial.db import SocialContest, SocialTask, SocialUser, SocialParticipation | ||
|
||
dummy_pdf = b"%PDF-1.0\n1 0 obj<</Type/Catalog/Pages 2 0 R>>endobj\n2 0 obj<</Type/Pages/Kids[3 0 R]/Count 1>>endobj\n3 0 obj<</Type/Page/Parent 2 0 R/Resources<<>>/MediaBox[0 0 9 9]>>endobj\nxref\n0 4\n0000000000 65535 f\n0000000009 00000 n\n0000000052 00000 n\n0000000101 00000 n\ntrailer<</Root 1 0 R/Size 4>>\nstartxref\n174\n%%EOF" | ||
|
||
|
||
def main(): | ||
with SessionGen() as s: | ||
# Create "admin" account with password "admin" | ||
admin = Admin( | ||
name="Admin", | ||
username="admin", | ||
authentication="plaintext:admin", | ||
authentication=build_password("admin"), | ||
permission_all=True, | ||
) | ||
contest = Contest(name="dev", description="Dev Contest") | ||
|
||
# Create "training" contest | ||
contest = Contest(name="training", description="Dev Contest") | ||
social_contest = SocialContest( | ||
Contest=contest, | ||
cookie_domain="olinfo.it", | ||
cookie_domain="dev.olinfo.it", | ||
analytics="fake-analytics-id", | ||
forum="https://forum.olinfo.it", | ||
top_left_name="Dev", | ||
title="Dev Contest", | ||
) | ||
|
||
# Create "test" user with "password" password | ||
user = User( | ||
username="test", | ||
password=build_password( | ||
bcrypt.hashpw("password".encode(), bcrypt.gensalt()).decode(), | ||
method="bcrypt", | ||
), | ||
first_name="Test", | ||
last_name="User", | ||
email="[email protected]", | ||
) | ||
participation = Participation(contest=contest, user=user) | ||
social_user = SocialUser(user=user) | ||
social_participation = SocialParticipation(participation=participation) | ||
|
||
# Add "test1" task | ||
file_cacher = FileCacher() | ||
task1 = Task( | ||
name="test1", | ||
|
@@ -46,5 +76,19 @@ def main(): | |
) | ||
social_task1 = SocialTask(task=task1) | ||
|
||
s.add_all([admin, contest, social_contest, task1, statement1, social_task1]) | ||
# Commit everything to the database | ||
s.add_all( | ||
[ | ||
admin, | ||
contest, | ||
social_contest, | ||
task1, | ||
statement1, | ||
social_task1, | ||
user, | ||
participation, | ||
social_user, | ||
social_participation, | ||
] | ||
) | ||
s.commit() |