-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unit & Integration test for
python_pip
workflow (#18)
Fixes #14
- Loading branch information
Showing
17 changed files
with
172 additions
and
90 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
""" | ||
AWS Lambda Builder Library | ||
""" | ||
__version__ = '0.0.1' |
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,5 @@ | ||
""" | ||
Officially supported builder workflows | ||
""" | ||
|
||
import aws_lambda_builders.workflows.python_pip |
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,5 @@ | ||
""" | ||
Builds Python Lambda functions using PIP dependency manager | ||
""" | ||
|
||
from .workflow import PythonPipWorkflow |
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
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,58 @@ | ||
|
||
import os | ||
import shutil | ||
import tempfile | ||
from unittest import TestCase | ||
|
||
from aws_lambda_builders.builder import LambdaBuilder | ||
from aws_lambda_builders.exceptions import WorkflowFailedError | ||
|
||
|
||
class TestPythonPipWorkflow(TestCase): | ||
""" | ||
Verifies that `python_pip` workflow works by building a Lambda that requires Numpy | ||
""" | ||
|
||
TEST_DATA_FOLDER = os.path.join(os.path.dirname(__file__), "testdata") | ||
|
||
def setUp(self): | ||
self.source_dir = self.TEST_DATA_FOLDER | ||
self.artifacts_dir = tempfile.mkdtemp() | ||
self.scratch_dir = tempfile.mkdtemp() | ||
|
||
self.manifest_path_valid = os.path.join(self.TEST_DATA_FOLDER, "requirements-numpy.txt") | ||
self.manifest_path_invalid = os.path.join(self.TEST_DATA_FOLDER, "requirements-invalid.txt") | ||
|
||
self.test_data_files = set(os.listdir(self.TEST_DATA_FOLDER)) | ||
|
||
self.builder = LambdaBuilder(language="python", | ||
dependency_manager="pip", | ||
application_framework=None) | ||
|
||
def tearDown(self): | ||
shutil.rmtree(self.artifacts_dir) | ||
shutil.rmtree(self.scratch_dir) | ||
|
||
def test_must_build_python_project(self): | ||
self.builder.build(self.source_dir, self.artifacts_dir, None, self.manifest_path_valid, | ||
runtime="python2.7") | ||
|
||
expected_files = self.test_data_files.union({"numpy", "numpy-1.15.4.data", "numpy-1.15.4.dist-info"}) | ||
output_files = set(os.listdir(self.artifacts_dir)) | ||
self.assertEquals(expected_files, output_files) | ||
|
||
def test_must_fail_to_resolve_dependencies(self): | ||
|
||
with self.assertRaises(WorkflowFailedError) as ctx: | ||
self.builder.build(self.source_dir, self.artifacts_dir, None, self.manifest_path_invalid, | ||
runtime="python2.7") | ||
|
||
self.assertIn("Invalid requirement: 'adfasf=1.2.3'", str(ctx.exception)) | ||
|
||
def test_must_fail_if_requirements_not_found(self): | ||
|
||
with self.assertRaises(WorkflowFailedError) as ctx: | ||
self.builder.build(self.source_dir, self.artifacts_dir, None, os.path.join("non", "existent", "manifest"), | ||
runtime="python2.7") | ||
|
||
self.assertIn("Requirements file not found", str(ctx.exception)) |
Empty file.
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,6 @@ | ||
import numpy | ||
|
||
|
||
def lambda_handler(event, context): | ||
# Just return the value of PI with two decimals - 3.14 | ||
return "{0:.2f}".format(numpy.pi) |
1 change: 1 addition & 0 deletions
1
tests/integration/workflows/python_pip/testdata/requirements-invalid.txt
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 @@ | ||
adfasf=1.2.3 |
1 change: 1 addition & 0 deletions
1
tests/integration/workflows/python_pip/testdata/requirements-numpy.txt
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 @@ | ||
numpy==1.15.4 |
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,31 @@ | ||
|
||
from unittest import TestCase | ||
from mock import patch | ||
|
||
from aws_lambda_builders.actions import ActionFailedError | ||
|
||
from aws_lambda_builders.workflows.python_pip.actions import PythonPipBuildAction | ||
from aws_lambda_builders.workflows.python_pip.packager import PackagerError | ||
|
||
|
||
class TestPythonPipBuildAction(TestCase): | ||
|
||
@patch("aws_lambda_builders.workflows.python_pip.actions.PythonPipDependencyBuilder") | ||
def test_action_must_call_builder(self, PythonPipDependencyBuilderMock): | ||
builder_instance = PythonPipDependencyBuilderMock.return_value | ||
|
||
action = PythonPipBuildAction("artifacts", "manifest", "runtime") | ||
action.execute() | ||
|
||
builder_instance.build_dependencies.assert_called_with("artifacts", "manifest", "runtime") | ||
|
||
@patch("aws_lambda_builders.workflows.python_pip.actions.PythonPipDependencyBuilder") | ||
def test_must_raise_exception_on_failure(self, PythonPipDependencyBuilderMock): | ||
builder_instance = PythonPipDependencyBuilderMock.return_value | ||
builder_instance.build_dependencies.side_effect = PackagerError() | ||
|
||
action = PythonPipBuildAction("artifacts", "manifest", "runtime") | ||
|
||
with self.assertRaises(ActionFailedError): | ||
action.execute() | ||
|
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
Oops, something went wrong.