Commit 09cc7eba2857954e03828f66dbe11a7da96a2f0f
1 parent
ca9934fa
Exists in
master
and in
1 other branch
- addded option --demo in init.db to add fake students, otherwise initialize empty.
Showing
2 changed files
with
10 additions
and
8 deletions
Show diff stats
README.md
@@ -70,9 +70,10 @@ The following commands will show how to run a demonstration test: | @@ -70,9 +70,10 @@ The following commands will show how to run a demonstration test: | ||
70 | ```.bash | 70 | ```.bash |
71 | cd WHERE/YOU/INSTALLED/perguntations | 71 | cd WHERE/YOU/INSTALLED/perguntations |
72 | 72 | ||
73 | -# create database. | ||
74 | -# a database with fake students is created if no CSV file is provided | ||
75 | -./initdb.py OPTIONAL_CSV_FILE | 73 | +# create and initialize database either from a CSV file, fake students or empty |
74 | +./initdb.py students.csv # from CSV file | ||
75 | +./initdb.py --demo # initialize with fake students | ||
76 | +./initdb.py # empty | ||
76 | mv students.db demo/ | 77 | mv students.db demo/ |
77 | 78 | ||
78 | # edit test configuration and check if everything looks right | 79 | # edit test configuration and check if everything looks right |
initdb.py
@@ -20,7 +20,7 @@ def fix(name): | @@ -20,7 +20,7 @@ def fix(name): | ||
20 | # Parse command line options | 20 | # Parse command line options |
21 | argparser = argparse.ArgumentParser(description='Create new database from a CSV file (SIIUE format)') | 21 | argparser = argparse.ArgumentParser(description='Create new database from a CSV file (SIIUE format)') |
22 | argparser.add_argument('--db', default='students.db', type=str, help='database filename') | 22 | argparser.add_argument('--db', default='students.db', type=str, help='database filename') |
23 | -# argparser.add_argument('--demo', default='students.db', type=str, help='add demo students') | 23 | +argparser.add_argument('--demo', action='store_true', help='initialize database with a few fake students') |
24 | argparser.add_argument('csvfile', nargs='?', type=str, default='', help='CSV filename') | 24 | argparser.add_argument('csvfile', nargs='?', type=str, default='', help='CSV filename') |
25 | args = argparser.parse_args() | 25 | args = argparser.parse_args() |
26 | 26 | ||
@@ -50,8 +50,8 @@ try: | @@ -50,8 +50,8 @@ try: | ||
50 | sys.exit(1) | 50 | sys.exit(1) |
51 | else: | 51 | else: |
52 | session.add_all([Student(id=r['N.º'], name=fix(r['Nome']), password='') for r in csvreader]) | 52 | session.add_all([Student(id=r['N.º'], name=fix(r['Nome']), password='') for r in csvreader]) |
53 | - else: | ||
54 | - # otherwise add a few fake students | 53 | + elif args.demo: |
54 | + # add a few fake students | ||
55 | fakes = [ | 55 | fakes = [ |
56 | ['1888', 'Fernando Pessoa'], | 56 | ['1888', 'Fernando Pessoa'], |
57 | ['1799', 'Almeida Garrett'], | 57 | ['1799', 'Almeida Garrett'], |
@@ -74,14 +74,15 @@ except Exception: | @@ -74,14 +74,15 @@ except Exception: | ||
74 | 74 | ||
75 | else: | 75 | else: |
76 | n = session.query(Student).count() | 76 | n = session.query(Student).count() |
77 | - print('New database created: {0}\n{1} users inserted:'.format(args.db, n)) | 77 | + print('New database created: {0}\n{1} user(s) inserted:'.format(args.db, n)) |
78 | 78 | ||
79 | users = session.query(Student).order_by(Student.id).all() | 79 | users = session.query(Student).order_by(Student.id).all() |
80 | print(' {0:8} - {1} (administrator)'.format(users[0].id, users[0].name)) | 80 | print(' {0:8} - {1} (administrator)'.format(users[0].id, users[0].name)) |
81 | if n > 1: | 81 | if n > 1: |
82 | print(' {0:8} - {1}'.format(users[1].id, users[1].name)) | 82 | print(' {0:8} - {1}'.format(users[1].id, users[1].name)) |
83 | if n > 3: | 83 | if n > 3: |
84 | - print(' .\n .\n .') | 84 | + print(' ... ...') |
85 | + # print(' .\n .\n .') | ||
85 | if n > 2: | 86 | if n > 2: |
86 | print(' {0:8} - {1}'.format(users[-1].id, users[-1].name)) | 87 | print(' {0:8} - {1}'.format(users[-1].id, users[-1].name)) |
87 | 88 |