Skip to content

Commit c42d321

Browse files
authored
39-set_start_method-to-spawn-for-windows (#46)
* 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
1 parent 2888f62 commit c42d321

File tree

7 files changed

+191
-84
lines changed

7 files changed

+191
-84
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import pytest
2+
3+
from flaskapp import models
4+
5+
6+
@pytest.fixture
7+
def client(app_with_db):
8+
return app_with_db.test_client()
9+
10+
11+
def test_index(client):
12+
response = client.get("/")
13+
14+
assert response.status_code == 200
15+
assert b"Welcome to ReleCloud" in response.data
16+
17+
18+
def test_about(client):
19+
response = client.get("/about")
20+
21+
assert response.status_code == 200
22+
assert b"About ReleCloud" in response.data
23+
24+
25+
def test_destinations(client):
26+
response = client.get("/destinations")
27+
28+
assert response.status_code == 200
29+
assert b"Destinations" in response.data
30+
assert b"The Sun" in response.data
31+
32+
33+
def test_destination_detail(client):
34+
sun = models.Destination.objects(name="The Sun").first()
35+
response = client.get(f"/destination/{sun.id}")
36+
37+
assert response.status_code == 200
38+
assert b"The Sun" in response.data
39+
40+
41+
def test_cruise_detail(client):
42+
sun_and_earth = models.Cruise.objects(name="The Sun and Earth").first()
43+
response = client.get(f"/cruise/{sun_and_earth.id}")
44+
45+
assert response.status_code == 200
46+
assert b"The Sun and Earth" in response.data
47+
48+
49+
def test_info_request(client):
50+
response = client.get("/info_request")
51+
52+
assert response.status_code == 200
53+
assert b"Request Info" in response.data
54+
55+
56+
def test_create_info_request(client):
57+
sun_and_earth = models.Cruise.objects(name="The Sun and Earth").first()
58+
response = client.post(
59+
"/info_request",
60+
data={
61+
"name": "Amanda Valdez",
62+
"email": "[email protected]",
63+
"notes": "Please send me more information.",
64+
"cruise_id": f"{sun_and_earth.id}",
65+
},
66+
)
67+
68+
assert response.status_code == 302
69+
assert (
70+
response.headers["Location"]
71+
== "/info_request?message=Thank+you,+Amanda+Valdez!+We+will+email+you+when+we+have+more+information!"
72+
)
73+
74+
info_request = models.InfoRequest.objects(name="Amanda Valdez").first()
75+
assert info_request.name == "Amanda Valdez"
76+
assert info_request.email == "[email protected]"
77+
assert info_request.notes == "Please send me more information."
78+
assert info_request.cruise == sun_and_earth
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import pytest
2+
from sqlalchemy import select
3+
4+
from flaskapp import db, models
5+
6+
7+
@pytest.fixture
8+
def client(app_with_db):
9+
return app_with_db.test_client()
10+
11+
12+
def test_index(client):
13+
response = client.get("/")
14+
15+
assert response.status_code == 200
16+
assert b"Welcome to ReleCloud" in response.data
17+
18+
19+
def test_about(client):
20+
response = client.get("/about")
21+
22+
assert response.status_code == 200
23+
assert b"About ReleCloud" in response.data
24+
25+
26+
def test_destinations(client):
27+
response = client.get("/destinations")
28+
29+
assert response.status_code == 200
30+
assert b"Destinations" in response.data
31+
assert b"The Sun" in response.data
32+
33+
34+
def test_destination_detail(app_with_db, client):
35+
with app_with_db.app_context():
36+
sun = db.session.query(models.Destination).filter(models.Destination.name == "The Sun").first()
37+
response = client.get(f"/destination/{sun.id}")
38+
39+
assert response.status_code == 200
40+
assert b"The Sun" in response.data
41+
42+
43+
def test_cruise_detail(app_with_db, client):
44+
with app_with_db.app_context():
45+
sun_and_earth = db.session.query(models.Cruise).where(models.Cruise.name == "The Sun and Earth").first()
46+
response = client.get(f"/cruise/{sun_and_earth.id}")
47+
48+
assert response.status_code == 200
49+
assert b"The Sun and Earth" in response.data
50+
51+
52+
def test_info_request(client):
53+
response = client.get("/info_request")
54+
55+
assert response.status_code == 200
56+
assert b"Request Info" in response.data
57+
58+
59+
def test_create_info_request(app_with_db, client):
60+
with app_with_db.app_context():
61+
sun_and_earth = db.session.query(models.Cruise).where(models.Cruise.name == "The Sun and Earth").first()
62+
response = client.post(
63+
"/info_request",
64+
data={
65+
"name": "Amanda Valdez",
66+
"email": "[email protected]",
67+
"notes": "Please send me more information.",
68+
"cruise_id": f"{sun_and_earth.id}",
69+
},
70+
)
71+
72+
assert response.status_code == 302
73+
assert (
74+
response.headers["Location"]
75+
== "/info_request?message=Thank+you,+Amanda+Valdez!+We+will+email+you+when+we+have+more+information!"
76+
)
77+
78+
info_request = db.session.query(models.InfoRequest).order_by(models.InfoRequest.id.desc()).first()
79+
assert info_request.name == "Amanda Valdez"
80+
assert info_request.email == "[email protected]"
81+
assert info_request.notes == "Please send me more information."
82+
assert info_request.cruise_id == sun_and_earth.id

tools/update_info.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,11 @@ def update_readme():
112112

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

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

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

311313
for repo in patterns:
312-
update_repo(repo=repo, path=path, branch=branch, checkout=checkout, submit_pr=submit_pr, source=source, force=force)
314+
update_repo(
315+
repo=repo,
316+
path=create_base_folder(base_folder),
317+
branch=branch,
318+
checkout=checkout,
319+
submit_pr=submit_pr,
320+
source=source,
321+
force=force,
322+
)
313323

314324
if __name__ == "__main__":
315325
app()

{{cookiecutter.__src_folder_name}}/src/flask/flaskapp/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def create_app(test_config=None):
4646
db.init_app(app)
4747
migrate.init_app(app, db)
4848
{% endif %}
49-
{% if 'mongodb' in cookiecutter.db_resource %}
49+
{% if 'mongo' in cookiecutter.db_resource %}
5050
db = engine.connect(host=app.config.get("DATABASE_URI")) # noqa: F841
5151
{% endif %}
5252

@@ -61,7 +61,6 @@ def create_app(test_config=None):
6161
@click.option("--filename", default="seed_data.json")
6262
def seed_data(filename{% if 'mongodb' in cookiecutter.db_resource %}, drop{% endif %}):
6363
from . import seeder
64-
6564
{% if 'postgres' in cookiecutter.db_resource %}
6665
seeder.seed_data(db, filename)
6766
{% endif %}

{{cookiecutter.__src_folder_name}}/src/flask/flaskapp/pages.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,12 @@ def create_info_request():
5858
name=name,
5959
email=request.form["email"],
6060
notes=request.form["notes"],
61+
{% if 'postgres' in cookiecutter.db_resource %}
6162
cruise_id=request.form["cruise_id"],
63+
{% endif %}
64+
{% if 'mongodb' in cookiecutter.db_resource %}
65+
cruise=request.form["cruise_id"],
66+
{% endif %}
6267
)
6368
{% if 'postgres' in cookiecutter.db_resource %}
6469
db.session.add(db_info_request)
Lines changed: 7 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,7 @@
1-
import pytest
2-
3-
from flaskapp import db, models
4-
5-
6-
@pytest.fixture
7-
def client(app_with_db):
8-
return app_with_db.test_client()
9-
10-
11-
def test_index(client):
12-
response = client.get("/")
13-
14-
assert response.status_code == 200
15-
assert b"Welcome to ReleCloud" in response.data
16-
17-
18-
def test_about(client):
19-
response = client.get("/about")
20-
21-
assert response.status_code == 200
22-
assert b"About ReleCloud" in response.data
23-
24-
25-
def test_destinations(client):
26-
response = client.get("/destinations")
27-
28-
assert response.status_code == 200
29-
assert b"Destinations" in response.data
30-
assert b"The Sun" in response.data
31-
32-
33-
def test_destination_detail(client):
34-
response = client.get("/destination/1")
35-
36-
assert response.status_code == 200
37-
assert b"The Sun" in response.data
38-
39-
40-
def test_cruise_detail(client):
41-
response = client.get("/cruise/1")
42-
43-
assert response.status_code == 200
44-
assert b"The Sun and Earth" in response.data
45-
46-
47-
def test_info_request(client):
48-
response = client.get("/info_request")
49-
50-
assert response.status_code == 200
51-
assert b"Request Info" in response.data
52-
53-
54-
def test_create_info_request(app_with_db, client):
55-
response = client.post(
56-
"/info_request",
57-
data={
58-
"name": "Amanda Valdez",
59-
"email": "[email protected]",
60-
"notes": "Please send me more information.",
61-
"cruise_id": "12345",
62-
},
63-
)
64-
65-
assert response.status_code == 302
66-
assert (
67-
response.headers["Location"]
68-
== "/info_request?message=Thank+you,+Amanda+Valdez!+We+will+email+you+when+we+have+more+information!"
69-
)
70-
71-
with app_with_db.app_context():
72-
info_request = db.session.query(models.InfoRequest).order_by(models.InfoRequest.id.desc()).first()
73-
assert info_request.name == "Amanda Valdez"
74-
assert info_request.email == "[email protected]"
75-
assert info_request.notes == "Please send me more information."
76-
assert info_request.cruise_id == 12345
1+
{# Template found in "templates" directory at root #}
2+
{% if 'postgres' in cookiecutter.db_resource %}
3+
{% include "flask_test_pages_postgres.py" %}
4+
{% endif %}
5+
{% if 'mongo' in cookiecutter.db_resource %}
6+
{% include "flask_test_pages_mongodb.py" %}
7+
{% endif %}

{{cookiecutter.__src_folder_name}}/src/tests/local/conftest.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@
4747

4848
{% if cookiecutter.project_backend in ("flask", "fastapi") %}
4949
# Set start method to "fork" to avoid issues with pickling on OSes that default to "spawn"
50-
if sys.platform != "win32":
50+
if sys.platform == "win32":
51+
multiprocessing.set_start_method("spawn")
52+
else:
5153
multiprocessing.set_start_method("fork")
5254
{% endif %}
5355

0 commit comments

Comments
 (0)