Skip to content

Commit

Permalink
39-set_start_method-to-spawn-for-windows (#46)
Browse files Browse the repository at this point in the history
* set_start_method to "spawn" for windows
Fixes #39

* fixes for mongodb

* Jm-updates-tests-mongo (#45)

* fix typo

* adds db

* swap destination for cruise

* move tests to their own file

* fix typo

* updates pages for cruise/cruise-id
  • Loading branch information
kjaymiller authored Feb 5, 2024
1 parent 2888f62 commit c42d321
Show file tree
Hide file tree
Showing 7 changed files with 191 additions and 84 deletions.
78 changes: 78 additions & 0 deletions templates/flask_test_pages_mongodb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import pytest

from flaskapp import models


@pytest.fixture
def client(app_with_db):
return app_with_db.test_client()


def test_index(client):
response = client.get("/")

assert response.status_code == 200
assert b"Welcome to ReleCloud" in response.data


def test_about(client):
response = client.get("/about")

assert response.status_code == 200
assert b"About ReleCloud" in response.data


def test_destinations(client):
response = client.get("/destinations")

assert response.status_code == 200
assert b"Destinations" in response.data
assert b"The Sun" in response.data


def test_destination_detail(client):
sun = models.Destination.objects(name="The Sun").first()
response = client.get(f"/destination/{sun.id}")

assert response.status_code == 200
assert b"The Sun" in response.data


def test_cruise_detail(client):
sun_and_earth = models.Cruise.objects(name="The Sun and Earth").first()
response = client.get(f"/cruise/{sun_and_earth.id}")

assert response.status_code == 200
assert b"The Sun and Earth" in response.data


def test_info_request(client):
response = client.get("/info_request")

assert response.status_code == 200
assert b"Request Info" in response.data


def test_create_info_request(client):
sun_and_earth = models.Cruise.objects(name="The Sun and Earth").first()
response = client.post(
"/info_request",
data={
"name": "Amanda Valdez",
"email": "[email protected]",
"notes": "Please send me more information.",
"cruise_id": f"{sun_and_earth.id}",
},
)

assert response.status_code == 302
assert (
response.headers["Location"]
== "/info_request?message=Thank+you,+Amanda+Valdez!+We+will+email+you+when+we+have+more+information!"
)

info_request = models.InfoRequest.objects(name="Amanda Valdez").first()
assert info_request.name == "Amanda Valdez"
assert info_request.email == "[email protected]"
assert info_request.notes == "Please send me more information."
assert info_request.cruise == sun_and_earth
82 changes: 82 additions & 0 deletions templates/flask_test_pages_postgres.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import pytest
from sqlalchemy import select

from flaskapp import db, models


@pytest.fixture
def client(app_with_db):
return app_with_db.test_client()


def test_index(client):
response = client.get("/")

assert response.status_code == 200
assert b"Welcome to ReleCloud" in response.data


def test_about(client):
response = client.get("/about")

assert response.status_code == 200
assert b"About ReleCloud" in response.data


def test_destinations(client):
response = client.get("/destinations")

assert response.status_code == 200
assert b"Destinations" in response.data
assert b"The Sun" in response.data


def test_destination_detail(app_with_db, client):
with app_with_db.app_context():
sun = db.session.query(models.Destination).filter(models.Destination.name == "The Sun").first()
response = client.get(f"/destination/{sun.id}")

assert response.status_code == 200
assert b"The Sun" in response.data


def test_cruise_detail(app_with_db, client):
with app_with_db.app_context():
sun_and_earth = db.session.query(models.Cruise).where(models.Cruise.name == "The Sun and Earth").first()
response = client.get(f"/cruise/{sun_and_earth.id}")

assert response.status_code == 200
assert b"The Sun and Earth" in response.data


def test_info_request(client):
response = client.get("/info_request")

assert response.status_code == 200
assert b"Request Info" in response.data


def test_create_info_request(app_with_db, client):
with app_with_db.app_context():
sun_and_earth = db.session.query(models.Cruise).where(models.Cruise.name == "The Sun and Earth").first()
response = client.post(
"/info_request",
data={
"name": "Amanda Valdez",
"email": "[email protected]",
"notes": "Please send me more information.",
"cruise_id": f"{sun_and_earth.id}",
},
)

assert response.status_code == 302
assert (
response.headers["Location"]
== "/info_request?message=Thank+you,+Amanda+Valdez!+We+will+email+you+when+we+have+more+information!"
)

info_request = db.session.query(models.InfoRequest).order_by(models.InfoRequest.id.desc()).first()
assert info_request.name == "Amanda Valdez"
assert info_request.email == "[email protected]"
assert info_request.notes == "Please send me more information."
assert info_request.cruise_id == sun_and_earth.id
20 changes: 15 additions & 5 deletions tools/update_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,11 @@ def update_readme():

print(f"{len(list(combos))}: Total Combinations")

def create_base_folder():
def create_base_folder(base_folder=None):
"""Creates the base folder for the repo"""
base_path = pathlib.Path(f"update_repos/{random_cc_folder_prefix}")
if not base_folder:
base_folder = random_cc_folder_prefix
base_path = pathlib.Path(f"update_repos/{base_folder}")
base_path.mkdir(parents=True, exist_ok=True)
return base_path
# TODO: Get repos by pattern
Expand Down Expand Up @@ -298,18 +300,26 @@ def update_repos(
"-s",
help="The source to use for cruft updates `source` parameter. Setting this will change the .cruft.json file to use the provided source permanently.",
)]=None,
base_folder: Annotated[str, typer.Option("--base-folder")]=None,
) -> None:

"""Updates all repos that match the provided pattern or all of the repos if no pattern is provided."""
logger.info(f"Request updates to repos matching \"{pattern}\" requested. Attrs: \n\t{branch=}\n\t{checkout=}")
path = create_base_folder()
patterns = get_repos_by_pattern(pattern)
patterns_str = '\n- '.join(patterns)
logger.info(f"Found {len(patterns)} repos matching \"{pattern}\"\n{patterns_str}")
logger.info(f"Found {len(patterns)} repos matching \"{pattern}\"\n- {patterns_str}")
force = source is not None

for repo in patterns:
update_repo(repo=repo, path=path, branch=branch, checkout=checkout, submit_pr=submit_pr, source=source, force=force)
update_repo(
repo=repo,
path=create_base_folder(base_folder),
branch=branch,
checkout=checkout,
submit_pr=submit_pr,
source=source,
force=force,
)

if __name__ == "__main__":
app()
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def create_app(test_config=None):
db.init_app(app)
migrate.init_app(app, db)
{% endif %}
{% if 'mongodb' in cookiecutter.db_resource %}
{% if 'mongo' in cookiecutter.db_resource %}
db = engine.connect(host=app.config.get("DATABASE_URI")) # noqa: F841
{% endif %}

Expand All @@ -61,7 +61,6 @@ def create_app(test_config=None):
@click.option("--filename", default="seed_data.json")
def seed_data(filename{% if 'mongodb' in cookiecutter.db_resource %}, drop{% endif %}):
from . import seeder

{% if 'postgres' in cookiecutter.db_resource %}
seeder.seed_data(db, filename)
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ def create_info_request():
name=name,
email=request.form["email"],
notes=request.form["notes"],
{% if 'postgres' in cookiecutter.db_resource %}
cruise_id=request.form["cruise_id"],
{% endif %}
{% if 'mongodb' in cookiecutter.db_resource %}
cruise=request.form["cruise_id"],
{% endif %}
)
{% if 'postgres' in cookiecutter.db_resource %}
db.session.add(db_info_request)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,76 +1,7 @@
import pytest

from flaskapp import db, models


@pytest.fixture
def client(app_with_db):
return app_with_db.test_client()


def test_index(client):
response = client.get("/")

assert response.status_code == 200
assert b"Welcome to ReleCloud" in response.data


def test_about(client):
response = client.get("/about")

assert response.status_code == 200
assert b"About ReleCloud" in response.data


def test_destinations(client):
response = client.get("/destinations")

assert response.status_code == 200
assert b"Destinations" in response.data
assert b"The Sun" in response.data


def test_destination_detail(client):
response = client.get("/destination/1")

assert response.status_code == 200
assert b"The Sun" in response.data


def test_cruise_detail(client):
response = client.get("/cruise/1")

assert response.status_code == 200
assert b"The Sun and Earth" in response.data


def test_info_request(client):
response = client.get("/info_request")

assert response.status_code == 200
assert b"Request Info" in response.data


def test_create_info_request(app_with_db, client):
response = client.post(
"/info_request",
data={
"name": "Amanda Valdez",
"email": "[email protected]",
"notes": "Please send me more information.",
"cruise_id": "12345",
},
)

assert response.status_code == 302
assert (
response.headers["Location"]
== "/info_request?message=Thank+you,+Amanda+Valdez!+We+will+email+you+when+we+have+more+information!"
)

with app_with_db.app_context():
info_request = db.session.query(models.InfoRequest).order_by(models.InfoRequest.id.desc()).first()
assert info_request.name == "Amanda Valdez"
assert info_request.email == "[email protected]"
assert info_request.notes == "Please send me more information."
assert info_request.cruise_id == 12345
{# Template found in "templates" directory at root #}
{% if 'postgres' in cookiecutter.db_resource %}
{% include "flask_test_pages_postgres.py" %}
{% endif %}
{% if 'mongo' in cookiecutter.db_resource %}
{% include "flask_test_pages_mongodb.py" %}
{% endif %}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@

{% if cookiecutter.project_backend in ("flask", "fastapi") %}
# Set start method to "fork" to avoid issues with pickling on OSes that default to "spawn"
if sys.platform != "win32":
if sys.platform == "win32":
multiprocessing.set_start_method("spawn")
else:
multiprocessing.set_start_method("fork")
{% endif %}

Expand Down

0 comments on commit c42d321

Please sign in to comment.