tests: Move zerver/fixtures to zerver/tests/fixtures for clarity.

Fixes #9153.
This commit is contained in:
Preston Hansen 2018-04-19 13:17:24 -05:00 committed by Tim Abbott
parent d0801dd602
commit 76d6c71595
38 changed files with 29 additions and 29 deletions

View File

@ -38,7 +38,7 @@ The Python-Markdown implementation is tested by
`frontend_tests/node_tests/markdown.js`. `frontend_tests/node_tests/markdown.js`.
A shared set of fixed test data ("test fixtures") is present in A shared set of fixed test data ("test fixtures") is present in
`zerver/fixtures/markdown_test_cases.json`, and is automatically used `zerver/tests/fixtures/markdown_test_cases.json`, and is automatically used
by both test suites; as a result, it is the preferred place to add new by both test suites; as a result, it is the preferred place to add new
tests for Zulip's markdown system. Some important notes on reading tests for Zulip's markdown system. Some important notes on reading
this file: this file:
@ -99,7 +99,7 @@ places:
`static/third/marked/lib/marked.js`), or `markdown.contains_backend_only_syntax` if `static/third/marked/lib/marked.js`), or `markdown.contains_backend_only_syntax` if
your changes won't be supported in the frontend processor. your changes won't be supported in the frontend processor.
* If desired, the typeahead logic in `static/js/composebox_typeahead.js`. * If desired, the typeahead logic in `static/js/composebox_typeahead.js`.
* The test suite, probably via adding entries to `zerver/fixtures/markdown_test_cases.json`. * The test suite, probably via adding entries to `zerver/tests/fixtures/markdown_test_cases.json`.
* The in-app markdown documentation (`templates/zerver/markdown_help.html`). * The in-app markdown documentation (`templates/zerver/markdown_help.html`).
* The list of changes to markdown at the end of this document. * The list of changes to markdown at the end of this document.

View File

@ -319,7 +319,7 @@ reads a bunch of sample inputs from a JSON fixture file, feeds them
to our GitHub integration code, and then verifies the output against to our GitHub integration code, and then verifies the output against
expected values from the same JSON fixture file. expected values from the same JSON fixture file.
Our fixtures live in `zerver/fixtures`. Our fixtures live in `zerver/tests/fixtures`.
### Mocks and stubs ### Mocks and stubs

View File

@ -56,7 +56,7 @@ module.prototype.hot = {
// Set up fixtures. // Set up fixtures.
global.read_fixture_data = (fn) => { global.read_fixture_data = (fn) => {
var full_fn = path.join(__dirname, '../../zerver/fixtures/', fn); var full_fn = path.join(__dirname, '../../zerver/tests/fixtures/', fn);
var data = JSON.parse(fs.readFileSync(full_fn, 'utf8', 'r')); var data = JSON.parse(fs.readFileSync(full_fn, 'utf8', 'r'));
return data; return data;
}; };

View File

@ -351,7 +351,7 @@ To trigger a notification using this webhook, use
(zulip-venv)vagrant@vagrant-ubuntu-trusty-64:/srv/zulip$ (zulip-venv)vagrant@vagrant-ubuntu-trusty-64:/srv/zulip$
./manage.py send_webhook_fixture_message \ ./manage.py send_webhook_fixture_message \
--fixture=zerver/fixtures/helloworld/hello.json \ --fixture=zerver/tests/fixtures/helloworld/hello.json \
'--url=http://localhost:9991/api/v1/external/helloworld?api_key=<api_key>' '--url=http://localhost:9991/api/v1/external/helloworld?api_key=<api_key>'
Or, use curl: Or, use curl:

View File

@ -727,7 +727,7 @@ def build_custom_checkers(by_lang):
'exclude': set(['zerver/webhooks/']), 'exclude': set(['zerver/webhooks/']),
'description': 'Fix tab-based whitespace'}, 'description': 'Fix tab-based whitespace'},
{'pattern': ':[\"\[\{]', {'pattern': ':[\"\[\{]',
'exclude': set(['zerver/webhooks/', 'zerver/fixtures/']), 'exclude': set(['zerver/webhooks/', 'zerver/tests/fixtures/']),
'description': 'Require space after : in JSON'}, 'description': 'Require space after : in JSON'},
] # type: RuleList ] # type: RuleList
markdown_rules = markdown_whitespace_rules + prose_style_rules + [ markdown_rules = markdown_whitespace_rules + prose_style_rules + [

View File

@ -10,6 +10,5 @@ templates/zilencer
puppet/zulip_ops puppet/zulip_ops
zproject/dev_settings.py zproject/dev_settings.py
zproject/test_settings.py zproject/test_settings.py
zerver/fixtures
zerver/tests zerver/tests
frontend_tests frontend_tests

View File

@ -8,7 +8,7 @@ import zulip
zulip_client = zulip.Client(site="http://localhost:9991", client="ZulipGithubPayloadSender/0.1") zulip_client = zulip.Client(site="http://localhost:9991", client="ZulipGithubPayloadSender/0.1")
payload_dir = "zerver/fixtures/github" payload_dir = "zerver/tests/fixtures/github"
for filename in os.listdir(payload_dir): for filename in os.listdir(payload_dir):
with open(os.path.join(payload_dir, filename)) as f: with open(os.path.join(payload_dir, filename)) as f:
req = json.loads(f.read()) req = json.loads(f.read())

View File

@ -11,7 +11,7 @@ EOF
exit 0 exit 0
fi fi
mkdir -p zerver/fixtures mkdir -p zerver/tests/fixtures
"$(dirname "$0")/../../scripts/setup/terminate-psql-sessions" zulip zulip_test zulip_test_base zulip_test_template "$(dirname "$0")/../../scripts/setup/terminate-psql-sessions" zulip zulip_test zulip_test_base zulip_test_template
@ -32,7 +32,7 @@ sh "$(dirname "$0")/../../scripts/setup/flush-memcached"
zerver.UserProfile zerver.Stream zerver.Recipient \ zerver.UserProfile zerver.Stream zerver.Recipient \
zerver.Subscription zerver.Message zerver.Huddle zerver.Realm \ zerver.Subscription zerver.Message zerver.Huddle zerver.Realm \
zerver.UserMessage zerver.Client \ zerver.UserMessage zerver.Client \
zerver.DefaultStream > zerver/fixtures/messages.json zerver.DefaultStream > zerver/tests/fixtures/messages.json
# create pristine template database, for fast fixture restoration after tests are run. # create pristine template database, for fast fixture restoration after tests are run.
psql -h localhost postgres zulip_test << EOF psql -h localhost postgres zulip_test << EOF

View File

@ -26,8 +26,9 @@ os.environ['DJANGO_SETTINGS_MODULE'] = 'zproject.settings'
from django.conf import settings from django.conf import settings
from zerver.lib.utils import split_by from zerver.lib.utils import split_by
FIXTURE_FILE = os.path.join(os.path.dirname(__file__), '../zerver/fixtures/authors.json') FIXTURE_FILE = os.path.join(os.path.dirname(__file__), '../zerver/tests/fixtures/authors.json')
duplicate_commits_file = os.path.join(os.path.dirname(__file__), '../zerver/fixtures/duplicate_commits.json') duplicate_commits_file = os.path.join(os.path.dirname(__file__),
'../zerver/tests/fixtures/duplicate_commits.json')
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument('--max-retries', type=int, default=3, parser.add_argument('--max-retries', type=int, default=3,
@ -143,7 +144,7 @@ def run_production() -> None:
def copy_fixture() -> None: def copy_fixture() -> None:
""" """
Copy test fixture file from zerver/fixtures. This is used to avoid Copy test fixture file from zerver/tests/fixtures. This is used to avoid
constantly fetching data from Github during testing. constantly fetching data from Github during testing.
""" """
subprocess.check_call(['cp', FIXTURE_FILE, settings.CONTRIBUTORS_DATA]) subprocess.check_call(['cp', FIXTURE_FILE, settings.CONTRIBUTORS_DATA])

View File

@ -4,7 +4,7 @@ import random
from typing import List, Dict, Any, Text, Optional from typing import List, Dict, Any, Text, Optional
def load_config() -> Dict[str, Any]: def load_config() -> Dict[str, Any]:
with open("zerver/fixtures/config.generate_data.json", "r") as infile: with open("zerver/tests/fixtures/config.generate_data.json", "r") as infile:
config = ujson.load(infile) config = ujson.load(infile)
return config return config

View File

@ -3,7 +3,7 @@ from typing import Dict
# Warning: If you change this parsing, please test using # Warning: If you change this parsing, please test using
# zerver/tests/test_decorators.py # zerver/tests/test_decorators.py
# And extend zerver/fixtures/user_agents_unique with any new test cases # And extend zerver/tests/fixtures/user_agents_unique with any new test cases
def parse_user_agent(user_agent: str) -> Dict[str, str]: def parse_user_agent(user_agent: str) -> Dict[str, str]:
match = re.match("^(?P<name>[^/ ]*[^0-9/(]*)(/(?P<version>[^/ ]*))?([ /].*)?$", user_agent) match = re.match("^(?P<name>[^/ ]*[^0-9/(]*)(/(?P<version>[^/ ]*))?([ /].*)?$", user_agent)
assert match is not None assert match is not None

View File

@ -235,7 +235,7 @@ class BugdownTest(ZulipTestCase):
def load_bugdown_tests(self) -> Tuple[Dict[Text, Any], List[List[Text]]]: def load_bugdown_tests(self) -> Tuple[Dict[Text, Any], List[List[Text]]]:
test_fixtures = {} test_fixtures = {}
data_file = open(os.path.join(os.path.dirname(__file__), '../fixtures/markdown_test_cases.json'), 'r') data_file = open(os.path.join(os.path.dirname(__file__), 'fixtures/markdown_test_cases.json'), 'r')
data = ujson.loads('\n'.join(data_file.readlines())) data = ujson.loads('\n'.join(data_file.readlines()))
for test in data['regular_tests']: for test in data['regular_tests']:
test_fixtures[test['name']] = test test_fixtures[test['name']] = test

View File

@ -1321,7 +1321,7 @@ class TestUserAgentParsing(ZulipTestCase):
def test_user_agent_parsing(self) -> None: def test_user_agent_parsing(self) -> None:
"""Test for our user agent parsing logic, using a large data set.""" """Test for our user agent parsing logic, using a large data set."""
user_agents_parsed = defaultdict(int) # type: Dict[str, int] user_agents_parsed = defaultdict(int) # type: Dict[str, int]
user_agents_path = os.path.join(settings.DEPLOY_ROOT, "zerver/fixtures/user_agents_unique") user_agents_path = os.path.join(settings.DEPLOY_ROOT, "zerver/tests/fixtures/user_agents_unique")
for line in open(user_agents_path).readlines(): for line in open(user_agents_path).readlines():
line = line.strip() line = line.strip()
match = re.match('^(?P<count>[0-9]+) "(?P<user_agent>.*)"$', line) match = re.match('^(?P<count>[0-9]+) "(?P<user_agent>.*)"$', line)

View File

@ -197,7 +197,7 @@ class AboutPageTest(ZulipTestCase):
# This block has unreliable test coverage due to the implicit # This block has unreliable test coverage due to the implicit
# caching here, so we exclude it from coverage. # caching here, so we exclude it from coverage.
if not os.path.exists(settings.CONTRIBUTORS_DATA): if not os.path.exists(settings.CONTRIBUTORS_DATA):
# Copy the fixture file in `zerver/fixtures` to `static/generated` # Copy the fixture file in `zerver/tests/fixtures` to `static/generated`
update_script = os.path.join(os.path.dirname(__file__), update_script = os.path.join(os.path.dirname(__file__),
'../../tools/update-authors-json') # nocoverage '../../tools/update-authors-json') # nocoverage
subprocess.check_call([update_script, '--use-fixture']) # nocoverage subprocess.check_call([update_script, '--use-fixture']) # nocoverage

View File

@ -325,7 +325,7 @@ class TestReplyExtraction(ZulipTestCase):
self.assertEqual(message.content, 'Reply') self.assertEqual(message.content, 'Reply')
MAILS_DIR = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "fixtures", "email") MAILS_DIR = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "tests", "fixtures", "email")
class TestScriptMTA(ZulipTestCase): class TestScriptMTA(ZulipTestCase):

View File

@ -347,7 +347,7 @@ class NarrowBuilderTest(ZulipTestCase):
class BuildNarrowFilterTest(TestCase): class BuildNarrowFilterTest(TestCase):
def test_build_narrow_filter(self) -> None: def test_build_narrow_filter(self) -> None:
fixtures_path = os.path.join(os.path.dirname(__file__), fixtures_path = os.path.join(os.path.dirname(__file__),
'../fixtures/narrow.json') 'fixtures/narrow.json')
scenarios = ujson.loads(open(fixtures_path, 'r').read()) scenarios = ujson.loads(open(fixtures_path, 'r').read())
self.assertTrue(len(scenarios) == 9) self.assertTrue(len(scenarios) == 9)
for scenario in scenarios: for scenario in scenarios:

View File

@ -484,7 +484,7 @@ class TestMissedMessages(ZulipTestCase):
# Run `relative_to_full_url()` function over test fixtures present in # Run `relative_to_full_url()` function over test fixtures present in
# 'markdown_test_cases.json' and check that it converts all the relative # 'markdown_test_cases.json' and check that it converts all the relative
# URLs to absolute URLs. # URLs to absolute URLs.
fixtures_file = os.path.join(settings.DEPLOY_ROOT, "zerver", fixtures_file = os.path.join(settings.DEPLOY_ROOT, "zerver", "tests",
"fixtures", "markdown_test_cases.json") "fixtures", "markdown_test_cases.json")
fixtures = ujson.load(open(fixtures_file)) fixtures = ujson.load(open(fixtures_file))
test_fixtures = {} test_fixtures = {}

View File

@ -43,7 +43,7 @@ from zilencer.models import RemoteZulipServer, RemotePushDeviceToken
from django.utils.timezone import now from django.utils.timezone import now
ZERVER_DIR = os.path.dirname(os.path.dirname(__file__)) ZERVER_DIR = os.path.dirname(os.path.dirname(__file__))
FIXTURES_FILE_PATH = os.path.join(ZERVER_DIR, "fixtures", "markdown_test_cases.json") FIXTURES_FILE_PATH = os.path.join(ZERVER_DIR, "tests", "fixtures", "markdown_test_cases.json")
class BouncerTestCase(ZulipTestCase): class BouncerTestCase(ZulipTestCase):
def setUp(self) -> None: def setUp(self) -> None:

View File

@ -154,7 +154,7 @@ class TestReport(ZulipTestCase):
def test_report_csp_violations(self) -> None: def test_report_csp_violations(self) -> None:
fixture_data_file = open(os.path.join(os.path.dirname(__file__), fixture_data_file = open(os.path.join(os.path.dirname(__file__),
'../fixtures/csp_report.json'), 'r') 'fixtures/csp_report.json'), 'r')
fixture_data = ujson.load(fixture_data_file) fixture_data = ujson.load(fixture_data_file)
params = ujson.dumps(fixture_data) params = ujson.dumps(fixture_data)
result = self.client_post("/report/csp_violations", params, content_type="application/json") result = self.client_post("/report/csp_violations", params, content_type="application/json")

View File

@ -473,7 +473,7 @@ class SlackImporter(ZulipTestCase):
mock_build_avatar: mock.Mock, mock_build_avatar: mock.Mock,
mock_process_uploads: mock.Mock, mock_process_uploads: mock.Mock,
mock_attachment: mock.Mock) -> None: mock_attachment: mock.Mock) -> None:
test_slack_dir = os.path.join(settings.DEPLOY_ROOT, "zerver", "fixtures", test_slack_dir = os.path.join(settings.DEPLOY_ROOT, "zerver", "tests", "fixtures",
"slack_fixtures") "slack_fixtures")
test_slack_zip_file = os.path.join(test_slack_dir, "test_slack_importer.zip") test_slack_zip_file = os.path.join(test_slack_dir, "test_slack_importer.zip")
test_slack_unzipped_file = os.path.join(test_slack_dir, "test_slack_importer") test_slack_unzipped_file = os.path.join(test_slack_dir, "test_slack_importer")
@ -489,7 +489,7 @@ class SlackImporter(ZulipTestCase):
# Also the unzipped data file should be removed if the test fails at 'do_convert_data' # Also the unzipped data file should be removed if the test fails at 'do_convert_data'
rm_tree(test_slack_unzipped_file) rm_tree(test_slack_unzipped_file)
user_data_fixture = os.path.join(settings.DEPLOY_ROOT, "zerver", "fixtures", user_data_fixture = os.path.join(settings.DEPLOY_ROOT, "zerver", "tests", "fixtures",
"slack_fixtures", "user_data.json") "slack_fixtures", "user_data.json")
mock_get_slack_api_data.side_effect = [ujson.load(open(user_data_fixture))['members'], {}] mock_get_slack_api_data.side_effect = [ujson.load(open(user_data_fixture))['members'], {}]

View File

@ -26,7 +26,7 @@ class SlackMessageConversion(ZulipTestCase):
def load_slack_message_conversion_tests(self) -> Dict[Any, Any]: def load_slack_message_conversion_tests(self) -> Dict[Any, Any]:
test_fixtures = {} test_fixtures = {}
data_file = open(os.path.join(os.path.dirname(__file__), '../fixtures/slack_message_conversion.json'), 'r') data_file = open(os.path.join(os.path.dirname(__file__), 'fixtures/slack_message_conversion.json'), 'r')
data = ujson.loads('\n'.join(data_file.readlines())) data = ujson.loads('\n'.join(data_file.readlines()))
for test in data['regular_tests']: for test in data['regular_tests']:
test_fixtures[test['name']] = test test_fixtures[test['name']] = test

View File

@ -11,7 +11,7 @@ from zerver.models import Realm, UserProfile
from zilencer.lib.stripe import StripeError, save_stripe_token, catch_stripe_errors from zilencer.lib.stripe import StripeError, save_stripe_token, catch_stripe_errors
from zilencer.models import Customer from zilencer.models import Customer
fixture_data_file = open(os.path.join(os.path.dirname(__file__), '../fixtures/stripe.json'), 'r') fixture_data_file = open(os.path.join(os.path.dirname(__file__), 'fixtures/stripe.json'), 'r')
fixture_data = ujson.load(fixture_data_file) fixture_data = ujson.load(fixture_data_file)
def mock_list_sources(*args: Any, **kwargs: Any) -> ListObject: def mock_list_sources(*args: Any, **kwargs: Any) -> ListObject:

View File

@ -17,7 +17,7 @@ To trigger a notification using this webhook, use
``` ```
(zulip-venv)vagrant@vagrant-ubuntu-trusty-64:/srv/zulip$ (zulip-venv)vagrant@vagrant-ubuntu-trusty-64:/srv/zulip$
./manage.py send_webhook_fixture_message \ ./manage.py send_webhook_fixture_message \
> --fixture=zerver/fixtures/helloworld/hello.json \ > --fixture=zerver/tests/fixtures/helloworld/hello.json \
> '--url=http://localhost:9991/api/v1/external/helloworld?api_key=&lt;api_key&gt;' > '--url=http://localhost:9991/api/v1/external/helloworld?api_key=&lt;api_key&gt;'
``` ```

View File

@ -317,7 +317,7 @@ class Command(BaseCommand):
# in the config.generate_data.json data set. This makes it # in the config.generate_data.json data set. This makes it
# possible for populate_db to run happily without Internet # possible for populate_db to run happily without Internet
# access. # access.
with open("zerver/fixtures/docs_url_preview_data.json", "r") as f: with open("zerver/tests/fixtures/docs_url_preview_data.json", "r") as f:
urls_with_preview_data = ujson.load(f) urls_with_preview_data = ujson.load(f)
for url in urls_with_preview_data: for url in urls_with_preview_data:
cache_set(url, urls_with_preview_data[url], PREVIEW_CACHE_NAME) cache_set(url, urls_with_preview_data[url], PREVIEW_CACHE_NAME)