-
Notifications
You must be signed in to change notification settings - Fork 2
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
Initialize Django module for one-off management commands #1
Closed
Closed
Changes from 1 commit
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
7a7d1ab
Scaffold Python package and move over source code
3dd7116
Add PR template and test artifacts
a35b00e
Adjust ecsmanage command to read configuration values
dbe4a70
Get ecsmanage command working
159e654
Make management command installable
a46dc8d
Initialize tests
b2e542c
Draft simple README
4096b3f
Add Travis config and drop support for py2.7 + py3.5
f42609d
Clean up Travis config
f929023
Document workarounds in .travis.yml
jeancochrane 80c3ba5
Clean up README
jeancochrane 0aff8d3
Specify Python 3.6+ support
jeancochrane 6c031a8
Use AWS region name for Boto3 clients
jeancochrane cc8ecbb
Update setup.py to reflect Python 3.6+ requirement
jeancochrane File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Initialize tests
Set up some simple tests for the package configuration.
- Loading branch information
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
if [[ -n "${ECSMANAGE_DEBUG}" ]]; then | ||
set -x | ||
fi | ||
|
||
function usage() { | ||
echo -n \ | ||
"Usage: $(basename "$0") | ||
|
||
Install the package for testing. | ||
" | ||
} | ||
|
||
if [ "${BASH_SOURCE[0]}" = "${0}" ]; then | ||
if [ "${1:-}" = "--help" ]; then | ||
usage | ||
else | ||
if ! [ -x "$(command -v python3)" ]; then | ||
echo "Error: python3 is not installed." | ||
exit 1j | ||
elif ! [ -x "$(command -v pip3)" ]; then | ||
echo "Error: pip3 is not installed." | ||
exit 1 | ||
else | ||
if ! [ -d ".venv" ]; then | ||
python3 -m venv .venv | ||
else | ||
./.venv/bin/pip3 install -e ".[tests]" | ||
fi | ||
fi | ||
fi | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
""" | ||
Django settings for testing purposes. | ||
""" | ||
SECRET_KEY = 'testing!' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
from django.core.management import call_command | ||
from django.core.management.base import CommandError | ||
from django.test import SimpleTestCase | ||
|
||
|
||
class ConfigurationTestCase(SimpleTestCase): | ||
""" | ||
Test the configuration of settings for the management command. | ||
""" | ||
def test_failure_when_no_settings(self): | ||
""" | ||
Test that the command throws an error when the ECSMANAGE_ENVIRONMENTS | ||
setting does not exist. | ||
""" | ||
with self.assertRaises(CommandError): | ||
call_command('ecsmanage', 'help') | ||
|
||
def test_failure_when_missing_environment(self): | ||
""" | ||
Test that the command throws an error when the environment passed to | ||
the CLI does not exist in ECSMANAGE_ENVIRONMENTS. | ||
""" | ||
ECSMANAGE_ENVIRONMENTS = { | ||
'staging': {}, | ||
'production': {} | ||
} | ||
with self.assertRaises(CommandError): | ||
with self.settings(ECSMANAGE_ENVIRONMENTS=ECSMANAGE_ENVIRONMENTS): | ||
call_command('ecsmanage', 'help', env='foobar') | ||
|
||
def test_failure_when_no_task_def_name(self): | ||
""" | ||
Test that the command throws an error when the configuration is missing | ||
a task definition name. | ||
""" | ||
ECSMANAGE_ENVIRONMENTS = { | ||
'staging': { | ||
'CLUSTER_NAME': 'foo', | ||
'SECURITY_GROUP_TAGS': {}, | ||
'SUBNET_TAGS': {}, | ||
}, | ||
} | ||
with self.assertRaises(CommandError): | ||
with self.settings(ECSMANAGE_ENVIRONMENTS=ECSMANAGE_ENVIRONMENTS): | ||
call_command('ecsmanage', 'help', env='staging') | ||
|
||
def test_failure_when_no_cluster_name(self): | ||
""" | ||
Test that the command throws an error when the configuration is missing | ||
a cluster name. | ||
""" | ||
ECSMANAGE_ENVIRONMENTS = { | ||
'staging': { | ||
'TASK_DEFINITION_NAME': 'foo', | ||
'SECURITY_GROUP_TAGS': {}, | ||
'SUBNET_TAGS': {}, | ||
}, | ||
} | ||
with self.assertRaises(CommandError): | ||
with self.settings(ECSMANAGE_ENVIRONMENTS=ECSMANAGE_ENVIRONMENTS): | ||
call_command('ecsmanage', 'help', env='staging') | ||
|
||
def test_failure_when_no_security_group_tags(self): | ||
""" | ||
Test that the command throws an error when the configuration is missing | ||
security group tags. | ||
""" | ||
ECSMANAGE_ENVIRONMENTS = { | ||
'staging': { | ||
'TASK_DEFINITION_NAME': 'foo', | ||
'CLUSTER_NAME': 'bar', | ||
'SUBNET_TAGS': {}, | ||
}, | ||
} | ||
with self.assertRaises(CommandError): | ||
with self.settings(ECSMANAGE_ENVIRONMENTS=ECSMANAGE_ENVIRONMENTS): | ||
call_command('ecsmanage', 'help', env='staging') | ||
|
||
def test_failure_when_no_subnet_tags(self): | ||
""" | ||
Test that the command throws an error when the configuration is missing | ||
subnet tags. | ||
""" | ||
ECSMANAGE_ENVIRONMENTS = { | ||
'staging': { | ||
'TASK_DEFINITION_NAME': 'foo', | ||
'CLUSTER_NAME': 'bar', | ||
'SECURITY_GROUP_TAGS': {}, | ||
}, | ||
} | ||
with self.assertRaises(CommandError): | ||
with self.settings(ECSMANAGE_ENVIRONMENTS=ECSMANAGE_ENVIRONMENTS): | ||
call_command('ecsmanage', 'help', env='staging') |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These tests only check user configurations. I tried to use Moto to mock Boto3 for integration tests, but I ran into two main problems:
describe_subnets
If 2) above can be overcome, then we could likely support at least partial tests for endpoints that aren't blocked by 1).