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

Rewrite tests with pytest fixtures #2948

Merged
36 commits merged into from
Mar 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
806bf04
setup pytest fixtures for source app
heartsucker Feb 16, 2018
f5f6be3
pytest fixtures: test_page_not_found
heartsucker Feb 16, 2018
7b1314c
pytest fixtures: test_index
heartsucker Feb 16, 2018
527665f
pytest fixtures: test_all_words_in_wordlist_validate
heartsucker Feb 16, 2018
7eb9c9e
pytest fixtures: test_generate
heartsucker Feb 16, 2018
ed3bae2
pytest fixtures: test_generate_already_logged_in
heartsucker Feb 16, 2018
24b7db0
pytest fixtures: test_create_new_source
heartsucker Feb 16, 2018
63cdd25
pytest fixtures: test_generate_too_long_codename
heartsucker Feb 16, 2018
a220d63
pytest fixtures: test_create_duplicate_codename
heartsucker Feb 16, 2018
dcf6936
pytest fixtures: test_lookup
heartsucker Feb 16, 2018
eee0a8c
pytest fixtures: test_login_and_logout
heartsucker Feb 18, 2018
82bec20
pytest fixtures: test_user_must_log_in_for_protected_views
heartsucker Feb 18, 2018
d31b563
pytest fixtures: test_login_with_whitespace
heartsucker Feb 18, 2018
74b53d1
pytest fixtures: test_initial_submission_notification
heartsucker Feb 18, 2018
2419289
pytest fixtures: test_submit_message
heartsucker Feb 18, 2018
6f7b4c2
pytest fixtures: test_submit_empty_message
heartsucker Feb 18, 2018
5eb88d9
pytest fixtures: test_submit_big_message
heartsucker Feb 18, 2018
d4868ad
pytest fixtures: test_submit_file
heartsucker Feb 18, 2018
8b0842d
pytest fixtures: test_submit_both
heartsucker Feb 18, 2018
7b706ef
pytest fixtures: test_submit_message_with_low_entropy
heartsucker Feb 18, 2018
31aaddc
pytest fixtures: test_submit_message_with_enough_entropy
heartsucker Feb 18, 2018
ac98d0e
pytest fixtures: test_delete_all_successfully_deletes_replies
heartsucker Feb 18, 2018
229fd45
pytest fixtures: test_delete_all_replies_already_deleted
heartsucker Feb 18, 2018
41bdd26
pytest fixtures: test_submit_sanitizes_filename
heartsucker Feb 18, 2018
0434729
pytest fixtures: test_tor2web_warning_headers
heartsucker Feb 18, 2018
ad0c908
pytest fixtures: test_tor2web_warning
heartsucker Feb 18, 2018
91a2655
pytest fixtures: test_why_use_tor_browser
heartsucker Feb 18, 2018
e059a22
pytest fixtures: test_why_journalist_key
heartsucker Feb 18, 2018
5995b06
pytest fixtures: test_metadata_route
heartsucker Feb 18, 2018
ba0dc76
pytest fixtures: test_login_with_overly_long_codename
heartsucker Feb 18, 2018
36c7fe7
pytest fixtures: test_failed_normalize_timestamps_logs_warning
heartsucker Feb 18, 2018
2ef9cc0
pytest fixtures: test_source_is_deleted_while_logged_in
heartsucker Feb 18, 2018
f7ea332
pytest fixtures: test_login_with_invalid_codename
heartsucker Feb 18, 2018
9906680
pytest fixtures: test_source_session_expiration
heartsucker Feb 18, 2018
372c565
pytest fixtures: test_csrf_error_page
heartsucker Feb 18, 2018
0b25f12
drop class from test cases
heartsucker Feb 18, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 49 additions & 9 deletions securedrop/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
# -*- coding: utf-8 -*-
import os
import shutil
import signal
import subprocess
import logging

import gnupg
import logging
import os
import psutil
import pytest
import shutil
import signal
import subprocess

os.environ['SECUREDROP_ENV'] = 'test' # noqa
from sdconfig import config
from sdconfig import SDConfig, config as original_config

from os import path

from db import db
from source_app import create_app as create_source_app

# TODO: the PID file for the redis worker is hard-coded below.
# Ideally this constant would be provided by a test harness.
Expand Down Expand Up @@ -44,11 +49,46 @@ def pytest_collection_modifyitems(config, items):


@pytest.fixture(scope='session')
def setUptearDown():
_start_test_rqworker(config)
def setUpTearDown():
_start_test_rqworker(original_config)
yield
_stop_test_rqworker()
_cleanup_test_securedrop_dataroot(config)
_cleanup_test_securedrop_dataroot(original_config)


@pytest.fixture(scope='function')
def config(tmpdir):
'''Clone the module so we can modify it per test.'''

cnf = SDConfig()

data = tmpdir.mkdir('data')
keys = data.mkdir('keys')
store = data.mkdir('store')
tmp = data.mkdir('tmp')
sqlite = data.join('db.sqlite')

gpg = gnupg.GPG(homedir=str(keys))
with open(path.join(path.dirname(__file__),
'files',
'test_journalist_key.pub')) as f:
gpg.import_keys(f.read())

cnf.SECUREDROP_DATA_ROOT = str(data)
cnf.GPG_KEY_DIR = str(keys)
cnf.STORE_DIR = str(store)
cnf.TEMP_DIR = str(tmp)
cnf.DATABASE_FILE = str(sqlite)

return cnf


@pytest.fixture(scope='function')
def source_app(config):
app = create_source_app(config)
with app.app_context():
db.create_all()
return app


def _start_test_rqworker(config):
Expand Down
2 changes: 1 addition & 1 deletion securedrop/tests/pytest.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[pytest]
testpaths = . functional
usefixtures = setUptearDown
usefixtures = setUpTearDown
addopts = --cov=../securedrop/
Loading