def test_deploy_with_stage_file(self, mock_ioutil, mock_validate_path, mock_files):
        EBDeployer.execute_command.return_value = 0
        mock_validate_path.return_value = True
        mock_ioutil.read_file.return_value = "dev"
        mock_files.return_value = ['package-1.0.0.zip', 'foo.txt', 'bar.zip', 'package-1.0.0.jar']


        testutil.put_stdin(
            """
            {
              "source": {
                "access_key_id": "apiKey123",
                "secret_access_key": "secretKey321"
              },
              "params": {
                "env_file": "naming/env",
                "deploy": true,
                "artifact_file": "artifact/package-(.*).zip",
                "config_file": "source/ci/"
              }
            }
            """)

        self.assertEqual(out.execute(r'/tmp/put/'), 0)
        EBDeployer.execute_command.assert_called_with(['eb_deploy',
                                                        '-p', r'/tmp/put/artifact/package-1.0.0.zip',
                                                        '-e', 'dev'],
                                                       r'/tmp/put/source/ci/')
Exemplo n.º 2
0
    def test_remove_with_stage_file(self, mock_io_open, mock_validate_path,
                                    mock_s3blanker):
        Serverless.execute_command.return_value = 0
        mock_file = MagicMock()
        mock_io_open.return_value = mock_file
        mock_file.read.return_value = "release"
        mock_validate_path.return_value = True
        mock_class_s3blanker = mock_s3blanker()

        testutil.put_stdin("""
            {
              "source": {
                "access_key_id": "apiKey123",
                "secret_access_key": "secretKey321"
              },
              "params": {
                "stage_file": "release",
                "remove": true,
                "serverless_file": "source/ci/"
              }
            }
            """)

        self.assertEqual(out.execute(r'/tmp/put/'), 0)
        Serverless.execute_command.assert_called_with(
            ['remove', '--stage', 'release'], r'/tmp/put/source/ci')
        mock_class_s3blanker.empty_buckets_for_serverless_config.assert_called_with(
            '/tmp/put/source/ci/serverless.yml', 'release')
Exemplo n.º 3
0
    def test_deploy_with_stage_file(self, mock_shutil, mock_io_open,
                                    mock_validate_path):
        Serverless.execute_command.return_value = 0
        mock_file = MagicMock()
        mock_io_open.return_value = mock_file
        mock_file.read.return_value = "release"
        mock_validate_path.return_value = True

        testutil.put_stdin("""
            {
              "source": {
                "access_key_id": "apiKey123",
                "secret_access_key": "secretKey321"
              },
              "params": {
                "stage_file": "naming/stage",
                "deploy": true,
                "artifact_folder": "artifact/lambda",
                "serverless_file": "source/ci/"
              }
            }
            """)

        self.assertEqual(out.execute(r'/tmp/put/'), 0)
        mock_shutil.copyfile.assert_called_with(
            r'/tmp/put/source/ci/serverless.yml',
            r'/tmp/put/artifact/lambda/serverless.yml')
        Serverless.execute_command.assert_called_with(
            ['deploy', '--stage', 'release'], r'/tmp/put/artifact/lambda')
 def test_without_version(self):
     testutil.put_stdin(payloads.in_payload_without_version)
     io = testutil.mock_stderr()
     self.assertEqual(-1, input.execute(""))
     self.assertRegex(
         testutil.read_from_io(io),
         "JSON Validation ERROR: 'version' is a required property")
Exemplo n.º 5
0
    def test_deploy(self, mock_shutil, mock_validate_filepath):
        Serverless.execute_command.return_value = 0
        mock_validate_filepath.return_value = True
        testutil.put_stdin("""
            {
              "source": {
                "access_key_id": "apiKey123",
                "secret_access_key": "secretKey321"
              },
              "params": {
                "stage": "version-v1-dev",
                "deploy": true,
                "artifact_folder": "artifact/lambda",
                "serverless_file": "source/ci/"
              }
            }
            """)

        self.assertEqual(out.execute(r'/tmp/put/'), 0)
        mock_shutil.copyfile.assert_called_with(
            r'/tmp/put/source/ci/serverless.yml',
            r'/tmp/put/artifact/lambda/serverless.yml')
        Serverless.execute_command.assert_called_with(
            ['deploy', '--stage', 'version-v1-dev'],
            r'/tmp/put/artifact/lambda')
Exemplo n.º 6
0
    def test_valid_json(self, mock_s3client, mock_matcher):
        # Mock Setup
        mock_returned_s3client = mock_s3client()
        mock_s3client.does_bucket_exist.return_value = True
        mock_matcher.return_value = [
            'release-1.0.0.tar.gz', 'release-1.0.1.tar.gz'
        ]

        io = testutil.mock_stdout()
        testutil.put_stdin(payloads.check_payload)

        self.assertEqual(0, check.execute())

        # Mock Assertions
        mock_s3client.assert_called_with("apiKey123", "secretKey321",
                                         "eu-west-1")
        mock_returned_s3client.does_bucket_exist.assert_called_with(
            'bucketName')
        mock_returned_s3client.list_files.assert_called_with('bucketName')
        mock_matcher.assert_called_once_with("release-(.*).tar.gz",
                                             unittest.mock.ANY,
                                             "release-1.0.0.tar.gz")

        self.assertEqual(
            '[{"version": "release-1.0.0.tar.gz"}, {"version": "release-1.0.1.tar.gz"}]',
            testutil.read_from_io(io))
Exemplo n.º 7
0
    def test_valid_json_invalid_credentials_or_bucket_does_not_exist(
            self, mock_s3client):
        # Mock Setup
        mock_returned_s3client = mock_s3client()
        mock_returned_s3client.does_bucket_exist.return_value = False

        testutil.put_stdin(payloads.check_payload)
        self.assertEqual(-1, check.execute())
Exemplo n.º 8
0
    def test_invalid_json(self):
        testutil.put_stdin('{"sourcez":{'
                           '"apiKey":"apiKey123",'
                           '"secretKey":"secretKey321'
                           '"},'
                           '"version":{"version":"version-v1-dev"}}')

        self.assertEqual(-1, check.execute())
Exemplo n.º 9
0
    def test_valid_json_without_version(self, mock_class):
        # Mock Setup
        mock_class.does_bucket_exist.return_value = True

        io = testutil.mock_stdout()
        testutil.put_stdin(payloads.check_payload_without_version)
        self.assertEqual(0, check.execute())
        self.assertEqual("[]", testutil.read_from_io(io))
Exemplo n.º 10
0
    def test_params_required_json(self):
        testutil.put_stdin("""
            {
              "source": {
                "access_key_id": "apiKey123",
                "secret_access_key": "secretKey321"
              }
            }
            """)

        self.assertEqual(out.execute('/'), -1)
    def test_version_not_required_json(self):
        testutil.put_stdin(
            """
            {
               "source":{
                  "access_key_id": "apiKey123",
                  "secret_access_key": "secretKey321"
               }
            }
            """)

        self.assertEqual(check.execute(), 0)
Exemplo n.º 12
0
    def test_params_required_json(self):
        testutil.put_stdin("""
            {
              "source": {
                "user": "******",
                "password": "******",
                "host": "hostname"
              }
            }
            """)

        self.assertEqual(out.execute('/'), -1)
Exemplo n.º 13
0
 def test_invalid_prefix(self):
     test = "test/test"
     testutil.put_stdin(
         json.dumps({
             "source": {
                 "prefix": "tes2234"
             },
             "version": {
                 "version": "1.1.0"
             }
         }))
     self.assertEquals(input.execute(test), -1)
Exemplo n.º 14
0
 def test_call_to_json(self, mock_io, mock_io2):
     test = "test/test"
     testutil.put_stdin(
         json.dumps({
             "source": {
                 "prefix": "test"
             },
             "version": {
                 "version": "1.1.0"
             }
         }))
     input.execute(test)
     mock_io.dumps.assert_any_call({"version": {"version": "1.1.0"}})
    def test_version_is_empty(self):
        testutil.put_stdin(
            """
            {
               "source":{
                  "access_key_id": "apiKey123",
                  "secret_access_key": "secretKey321"
               },
               "version": {}
            }
            """)

        self.assertEqual(check.execute(), 0)
Exemplo n.º 16
0
    def test_invalid_json(self):
        testutil.put_stdin("""
            {
              "source": {
                "access_key_id": "apiKey123",
                "secret_access_key": "secretKey321"
              },
              "params": {
              }
            }
            """)

        self.assertEqual(in_.execute('/'), -1)
Exemplo n.º 17
0
 def test_call_to_fileIO(self, mock_io):
     test = "test/test"
     testutil.put_stdin(
         json.dumps({
             "source": {
                 "prefix": "test"
             },
             "version": {
                 "version": "1.1.0"
             }
         }))
     input.execute(test)
     mock_io.write_to_file.assert_any_call(test + "/default", "test_1_1_0")
     mock_io.write_to_file.assert_any_call(test + "/heroku", "test-1-1-0")
    def test_invalid_json(self):
        testutil.put_stdin(
            """
            {
               "sourcez":{
                  "access_key_id": "apiKey123",
                  "secret_access_key": "secretKey321"
               },
               "version":{
                  "schema": "version-v1-dev"
               }
            }
            """)

        self.assertEqual(check.execute(), -1)
Exemplo n.º 19
0
    def test_invalid_json(self):
        testutil.put_stdin("""
            {
               "sourcez":{
                  "user": "******",
                  "password": "******",
                  "host": "hostname"
               },
               "version":{
                  "version": ""
               }
            }
            """)

        self.assertEqual(check.execute(), -1)
Exemplo n.º 20
0
 def test_invalid_mysql(self, mock_mysql_handler):
     mock_mysql_handler.return_value = None
     testutil.put_stdin("""
         {
            "source":{
               "user": "******",
               "password": "******",
               "host": "hostname"
            },
            "version":{
               "version": "some-version"
            }
         }
         """)
     self.assertEqual(check.execute(), -1)
Exemplo n.º 21
0
 def test_returns_valid_json_with_version(self):
     testutil.put_stdin(
         """
         {
           "source": {
             "user": "******",
             "password": "******",
             "host": "hostname"
           },
           "version": {
             "version": "some-version"
           }
         }
         """)
     io = testutil.mock_stdout()
     self.assertEqual(in_.execute('/'), 0)
     self.assertEqual(testutil.read_from_io(io), '{"version": {"version": "some-version"}}')
Exemplo n.º 22
0
    def test_deploy_artifact_folder_needed(self):
        Serverless.execute_command.return_value = 0

        testutil.put_stdin("""
            {
              "source": {
                "access_key_id": "apiKey123",
                "secret_access_key": "secretKey321"
              },
              "params": {
                "stage": "version-v1-dev",
                "deploy": true,
                "serverless_file": "source/ci/"
              }
            }
            """)

        self.assertEqual(out.execute('/'), -1)
Exemplo n.º 23
0
 def test_valid_mysql(self, mock_mysql_handler):
     mock_actual_instance = mock_mysql_handler()
     io = testutil.mock_stdout()
     testutil.put_stdin("""
         {
            "source":{
               "user": "******",
               "password": "******",
               "host": "hostname"
            },
            "version":{
               "version": "some-version"
            }
         }
         """)
     self.assertEqual(check.execute(), 0)
     mock_actual_instance.close_connection.assert_called_once()
     self.assertEqual(testutil.read_from_io(io), "[{}]")
Exemplo n.º 24
0
    def test_json(self):
        testutil.put_stdin(
            """
            {
               "source":{
                  "access_key_id": "apiKey123",
                  "secret_access_key": "secretKey321"
               },
               "version":{
                  "schema": "version-v1-dev"
               }
            }
            """)

        self.assertEqual(check.execute(), 0)
        Serverless.execute_command.assert_called_once_with(['config', 'credentials',
                                                            '--provider', 'aws',
                                                            '--key', 'apiKey123',
                                                            '--secret', 'secretKey321'])
    def test_deploy_artifact_file_needed(self):
        EBDeployer.execute_command.return_value = 0

        testutil.put_stdin(
            """
            {
              "source": {
                "access_key_id": "apiKey123",
                "secret_access_key": "secretKey321"
              },
              "params": {
                "env": "dev",
                "deploy": true,
                "config_file": "source/ci/"
              }
            }
            """)

        self.assertEqual(out.execute('/'), -1)
Exemplo n.º 26
0
    def test_json(self):
        with patch("builtins.open", create=True) as mock_open:
            mock_open.return_value = MagicMock(spec=TextIOWrapper)

            testutil.put_stdin("""
                {
                  "source": {
                    "access_key_id": "apiKey123",
                    "secret_access_key": "secretKey321"
                  },
                  "version": {
                    "env": "dev"
                  }
                }
                """)

            self.assertEqual(in_.execute('/'), 0)
            file_handle = mock_open.return_value.__enter__.return_value
            file_handle.write.assert_called_with('dev')
    def test_valid_json(self, mock_s3client, mock_archive_util,
                        mock_os_remove):
        # Mock Setup
        mock_returned_s3client = mock_s3client()
        mock_returned_s3client.does_bucket_exist.return_value = True

        io = testutil.mock_stdout()
        testutil.put_stdin(payloads.in_payload)
        self.assertEqual(0, input.execute("some/destination"))

        filename = "some/destination/release-1.0.0.tar.gz"

        # Mock Assertions
        mock_returned_s3client.download_file.assert_called_once_with(
            "bucketName", "release-1.0.0.tar.gz", filename)
        mock_archive_util.assert_called_once_with(filename, "some/destination")

        mock_os_remove.assert_called_once_with(filename)

        self.assertEqual('{"version": {"version": "release-1.0.0.tar.gz"}}',
                         testutil.read_from_io(io))
    def test_remove(self, mock_validate_path):
        EBDeployer.execute_command.return_value = 0
        mock_validate_path.return_value = True

        testutil.put_stdin(
            """
            {
              "source": {
                "access_key_id": "apiKey123",
                "secret_access_key": "secretKey321"
              },
              "params": {
                "env": "dev",
                "remove": true,
                "config_file": "source/ci/"
              }
            }
            """)

        self.assertEqual(out.execute(r'/tmp/put/'), 0)
        EBDeployer.execute_command.assert_called_with(['eb_deploy',
                                                        '-e', 'dev', '-d'],
                                                       r'/tmp/put/source/ci/')
    def test_valid_json(self, mock_s3client, mock_archive_util, mock_io_util,
                        mock_os_remove):
        # Mock Setup
        mock_returned_s3client = mock_s3client()
        mock_returned_s3client.does_bucket_exist.return_value = True
        mock_io_util.return_value = "1.0.1"

        testutil.put_stdin(payloads.out_payload)

        io = testutil.mock_stdout()
        self.assertEqual(0, out.execute("some/directory"))

        # Mock Assertions
        mock_io_util.assert_called_once_with("some/directory/version/name")
        mock_archive_util.assert_called_once_with("release-1.0.1.tar.gz",
                                                  "some/directory/artifact/")
        mock_returned_s3client.upload_file.assert_called_once_with(
            "bucketName", "release-1.0.1.tar.gz",
            "some/directory/artifact/release-1.0.1.tar.gz")
        mock_os_remove.assert_called_once_with(
            "some/directory/artifact/release-1.0.1.tar.gz")

        self.assertEqual('{"version": {"version": "release-1.0.1.tar.gz"}}',
                         testutil.read_from_io(io))
 def test_load_and_validate_payload_invalid(self):
     testutil.put_stdin(self.invalid_payload)
     valid, payload = jsonutil.load_and_validate_payload(schemas, request.Request.CHECK)
     self.assertFalse(valid)
     self.assertIsNone(payload)