Skip to content

Commit

Permalink
Fix/exclude add when initial zappa setting (#1242)
Browse files Browse the repository at this point in the history
* Fix exclude add when initial zappa setting

* add test about zappa init include exclude, etc.

* fix test code (test_zappa_init)

Consider django_settings (zappa latest version)

---------

Co-authored-by: monkut <shane.cousins@gmail.com>
  • Loading branch information
kyaryunha and monkut authored Nov 10, 2023
1 parent dd5d1f3 commit 581144c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
22 changes: 22 additions & 0 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import re
import shutil
import string
import subprocess
import sys
import tempfile
import unittest
Expand Down Expand Up @@ -1210,6 +1211,27 @@ def test_wsgi_from_apigateway_testbutton(self):
# CLI
##

def test_zappa_init(self):
# delete if file exists
if os.path.exists("zappa_settings.json"):
os.remove("zappa_settings.json")

process = subprocess.Popen(
["zappa", "init"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True
)
process.communicate("dev\nmy-zappa-bucket\ntest_settings\ndefault\nn\ny\n")
self.assertTrue(os.path.exists("zappa_settings.json"))

with open("zappa_settings.json", "r") as f:
zappa_settings = json.load(f)
self.assertEqual(zappa_settings["dev"]["s3_bucket"], "my-zappa-bucket")
self.assertEqual(zappa_settings["dev"]["django_settings"], "test_settings")
self.assertEqual(zappa_settings["dev"]["exclude"], ["boto3", "dateutil", "botocore", "s3transfer", "concurrent"])

# delete the file
if os.path.exists("zappa_settings.json"):
os.remove("zappa_settings.json")

def test_cli_sanity(self):
zappa_cli = ZappaCLI()
return
Expand Down
3 changes: 2 additions & 1 deletion zappa/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1874,6 +1874,7 @@ def init(self, settings_file="zappa_settings.json"):
"s3_bucket": bucket,
"runtime": get_venv_from_python_version(),
"project_name": self.get_project_name(),
"exclude": ["boto3", "dateutil", "botocore", "s3transfer", "concurrent"],
}
}

Expand Down Expand Up @@ -2445,7 +2446,7 @@ def create_package(self, output=None, use_zappa_release: Optional[str] = None):
disable_progress=self.disable_progress,
)
else:
exclude = self.stage_config.get("exclude", ["boto3", "dateutil", "botocore", "s3transfer", "concurrent"])
exclude = self.stage_config.get("exclude", [])

# Create a single zip that has the handler and application
self.zip_path = self.zappa.create_lambda_zip( # type: ignore[attr-defined]
Expand Down

0 comments on commit 581144c

Please sign in to comment.