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

test: two small tweaks to the tests #376

Merged
merged 2 commits into from
Aug 11, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions tests/common_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,30 @@

from .venv import all_files

# Fixture names aren't always used in test functions. Disable completely.
# pylint: disable=unused-argument

def test_github_org_is_right(options_baked):

def test_github_org_is_right(options_baked, configuration):
"""Make sure no one hard-coded openedx as the GitHub organization."""
wrong_github = f"github.com/openedx/{options_baked['repo_name']}"
org = configuration["github_org"]
repo = configuration["repo_name"]

right_github = f"github.com/{org}/{repo}"
if org != "openedx":
wrong_github = f"github.com/openedx/{repo}"
else:
wrong_github = None

rights = 0
wrongs = 0
for name in all_files():
with open(name) as f:
for line in f:
assert wrong_github not in line
if right_github in line:
rights += 1
if wrong_github is not None:
if wrong_github in line:
wrongs += 1
assert rights > 1
assert wrongs == 0
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ def options_baked(cookies_session, configuration, custom_template):
with bake_in_temp_dir(cookies_session, extra_context=configuration, template=custom_template):
sh.make('upgrade')
sh.pip('install', '-r', 'requirements/test.txt')
yield configuration
yield
6 changes: 3 additions & 3 deletions tests/test_cookiecutter_django_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ def test_readme(options_baked, custom_template):
sh.twine("check", "dist/*")


def test_models(options_baked):
def test_models(options_baked, configuration):
"""The generated models.py file should pass a sanity check."""
if "models" not in options_baked:
if "models" not in configuration:
pytest.skip("No models to check")
model_txt = Path("cookie_lover/models.py").read_text()
for model_name in options_baked.get("models").split(","):
for model_name in configuration.get("models").split(","):
pattern = fr'^class {model_name}\(TimeStampedModel\):$'
assert re.search(pattern, model_txt, re.MULTILINE)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_cookiecutter_python_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"author_email": "cookie@monster.org",
"author_name": "Cookie Monster",
"library_name": "cookie_lover",
"github_org": "bakery_org",
"github_org": "openedx",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I infer that you've made this change to test the new branch, and that the other cookiecutter tests use non-openedx orgs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this was to have a mixture of organizations across all of the tests.

"repo_name": "cookie_repo",
}

Expand Down