Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include various client related strings in test data #5224

Merged
merged 3 commits into from
Jul 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 14 additions & 13 deletions securedrop/create-dev-data.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import datetime
import os
import argparse
import math
from itertools import cycle

from flask import current_app
Expand All @@ -15,18 +16,11 @@
from sdconfig import config
from db import db
from models import Journalist, Reply, Source, Submission
from specialstrings import strings

submissions = cycle([
'This is a test submission without markup!',
'This is a test submission with markup and characters such as \, \\, \', \" and ". ' + # noqa: W605, E501
'<strong>This text should not be bold</strong>!'
])

replies = cycle([
'This is a test reply without markup!',
'This is a test reply with markup and characters such as \, \\, \', \" and ". ' + # noqa: W605, E501
'<strong>This text should not be bold</strong>!'
])
submissions = cycle(strings)
replies = cycle(strings)


def main(staging=False):
Expand Down Expand Up @@ -56,8 +50,13 @@ def main(staging=False):
first_name="Clark",
last_name="Kent")

NUM_SOURCES = os.getenv('NUM_SOURCES', 2)
if NUM_SOURCES == "ALL":
# We ingest two strings per source, so this will create the required
# number of sources to include all special strings
NUM_SOURCES = math.ceil(len(strings) / 2)
# Add test sources and submissions
num_sources = int(os.getenv('NUM_SOURCES', 2))
num_sources = int(NUM_SOURCES)
for i in range(1, num_sources + 1):
if i == 1:
# For the first source, the journalist who replied will be deleted
Expand All @@ -66,6 +65,7 @@ def main(staging=False):
)
continue
create_source_and_submissions(i, num_sources)

# Now let us delete one journalist
db.session.delete(journalist_tobe_deleted)
db.session.commit()
Expand All @@ -92,7 +92,7 @@ def add_test_user(username, password, otp_secret, is_admin=False,


def create_source_and_submissions(
source_index, source_count, num_submissions=2, num_replies=2, journalist_who_replied=None
source_index, source_count, num_submissions=2, num_replies=2, journalist_who_replied=None # noqa: W605, E501
):
# Store source in database
codename = current_app.crypto_util.genrandomid()
Expand All @@ -110,11 +110,12 @@ def create_source_and_submissions(
# Generate some test submissions
for _ in range(num_submissions):
source.interaction_count += 1
submission_text = next(submissions)
eloquence marked this conversation as resolved.
Show resolved Hide resolved
fpath = current_app.storage.save_message_submission(
source.filesystem_id,
source.interaction_count,
source.journalist_filename,
next(submissions)
submission_text
)
source.last_updated = datetime.datetime.utcnow()
submission = Submission(source, fpath)
Expand Down
144 changes: 144 additions & 0 deletions securedrop/specialstrings.py

Large diffs are not rendered by default.