summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fatcat/sql.py66
-rw-r--r--tests/test_backend.py6
2 files changed, 69 insertions, 3 deletions
diff --git a/fatcat/sql.py b/fatcat/sql.py
index 01da5873..c6e1aa4e 100644
--- a/fatcat/sql.py
+++ b/fatcat/sql.py
@@ -1,10 +1,13 @@
+import random
from fatcat import app, db
from fatcat.models import *
def populate_db():
+ """
+ TODO: doesn't create an edit trail (yet)
+ """
- # XXX: doesn't create an edit trail (yet)
n_elkies = CreatorRevision(
name="Noam D. Elkies",
sortname="Elkies, N",
@@ -30,3 +33,64 @@ def populate_db():
# title="Full Band All-sky Search for Periodic Gravitational Waves in the O1 LIGO Data")
db.session.commit()
+
+def populate_complex_db(count=100):
+ """
+ TODO: doesn't create an edit trail (yet)
+ """
+
+ first_names = ("Sarah", "Robin", "Halko", "Jefferson", "Max", "桃井",
+ "Koizumi", "Rex", "Billie", "Tenzin")
+ last_names = ("Headroom", "はるこ", "Jun'ichirō", "Wong", "Smith")
+
+ author_revs = []
+ author_ids = []
+ for i in range(count):
+ first = random.choice(first_names)
+ last = random.choice(last_names)
+ ar = CreatorRevision(
+ name="{} {}".format(first, last),
+ sortname="{}, {}".format(last, first[0]),
+ orcid=None)
+ author_revs.append(ar)
+ author_ids.append(CreatorId(revision_id=ar.id))
+
+ title_start = ("All about ", "When I grow up I want to be",
+ "The final word on", "Infinity: ", "The end of")
+ title_ends = ("Humankind", "Bees", "Democracy", "Avocados")
+ work_revs = []
+ work_ids = []
+ release_revs = []
+ release_ids = []
+ for i in range(count):
+ title = "{} {}".format(random.choice(title_start), random.choice(title_ends))
+ work = WorkRevision(title=title)
+ work_id = WorkId(revision_id=work.id)
+ authors = set(random.sample(author_ids, 5))
+ release = ReleaseRevision(
+ title=work.title,
+ creators=list(authors),
+ work_id=work.id)
+ release_id = ReleaseId(revision_id=release.id)
+ work.primary_release = release.id
+ authors.add(random.choice(author_ids))
+ release2 = ReleaseRevision(
+ title=work.title + " (again)",
+ creators=list(authors),
+ work_id=work.id)
+ release_id2 = ReleaseId(revision_id=release2.id)
+ work_revs.append(work)
+ work_ids.append(work_id)
+ release_revs.append(release)
+ release_revs.append(release2)
+ release_ids.append(release_id)
+ release_ids.append(release_id2)
+
+ db.session.add_all(author_revs)
+ db.session.add_all(author_ids)
+ db.session.add_all(work_revs)
+ db.session.add_all(work_ids)
+ db.session.add_all(release_revs)
+ db.session.add_all(release_ids)
+
+ db.session.commit()
diff --git a/tests/test_backend.py b/tests/test_backend.py
index 345c8a95..07a2a906 100644
--- a/tests/test_backend.py
+++ b/tests/test_backend.py
@@ -53,6 +53,8 @@ class FatcatTestCase(unittest.TestCase):
assert obj['title']
assert obj['work_type'] == "journal-article"
- def test_something(self):
-
+ def test_populate(self):
fatcat.sql.populate_db()
+
+ def test_populate_complex(self):
+ fatcat.sql.populate_complex_db()