Ejemplo n.º 1
0
    def test_github_download_rate_is_exceeded(self):  # noqa
        ctx = utils.FormattedDict({
            'BUILD_DIR': tempfile.gettempdir(),
            'PHP_VM': 'php',
            'TMPDIR': tempfile.gettempdir(),
            'LIBDIR': 'lib',
            'CACHE_DIR': 'cache',
            'WEBDIR': ''
        })

        instance_stub = Dingus()
        instance_stub._set_return_value("""{"rate": {"limit": 60, "remaining": 0}}""")

        stream_output_stub = Dingus(
            'test_github_oauth_token_uses_curl : stream_output')

        with patches({
            'StringIO.StringIO.getvalue': instance_stub,
            'composer.extension.stream_output': stream_output_stub,
        }):
            ct = self.extension_module.ComposerExtension(ctx)
            result = ct._github_rate_exceeded(False)

        assert result is True, \
            '_github_oauth_token_is_valid returned %s, expected True' % result
Ejemplo n.º 2
0
    def test_github_oauth_token_is_valid_uses_curl(self):
        ctx = utils.FormattedDict({
            'BUILD_DIR': '/usr/awesome',
            'PHP_VM': 'php',
            'TMPDIR': tempfile.gettempdir(),
            'LIBDIR': 'lib',
            'CACHE_DIR': 'cache',
        })

        instance_stub = Dingus()
        instance_stub._set_return_value("""{"resources": {}}""")

        stream_output_stub = Dingus(
            'test_github_oauth_token_uses_curl : stream_output')

        with patches({
            'StringIO.StringIO.getvalue': instance_stub,
            'composer.extension.stream_output': stream_output_stub,
        }):
            ct = self.extension_module.ComposerExtension(ctx)
            ct._github_oauth_token_is_valid('MADE_UP_TOKEN_VALUE')
            executed_command = stream_output_stub.calls()[0].args[1]

        assert stream_output_stub.calls().once(), \
            'stream_output() was called more than once'
        assert executed_command.find('curl') == 0, \
            'Curl was not called, executed_command was %s' % executed_command
        assert executed_command.find(
            '-H "Authorization: token MADE_UP_TOKEN_VALUE"') > 0, \
            'No token was passed to curl. Command was: %s' % executed_command
        assert executed_command.find('https://api.github.com/rate_limit') > 0,\
            'No URL was passed to curl. Command was: %s' % executed_command
Ejemplo n.º 3
0
    def test_build_composer_environment_has_missing_key(self):
        os.environ['SOME_KEY'] = 'does not matter'
        ctx = utils.FormattedDict({
            'BUILD_DIR': '/usr/awesome',
            'PHP_VM': 'php',
            'TMPDIR': 'tmp',
            'LIBDIR': 'lib',
            'CACHE_DIR': 'cache',
            'SOME_KEY': utils.wrap('{exact_match}')
        })

        write_config_stub = Dingus()

        with patches({
            'composer.extension.PHPComposerStrategy.write_config': write_config_stub
        }):
            self.extension_module.ComposerExtension(ctx)
            cr = self.extension_module.ComposerCommandRunner(ctx, None)

            try:
                built_environment = cr._build_composer_environment()
                assert "{exact_match}" == built_environment['SOME_KEY'], \
                    "value should match"
            except KeyError, e:
                assert 'exact_match' != e.message, \
                    "Should not try to evaluate value [%s]" % e
                raise
Ejemplo n.º 4
0
    def test_build_composer_environment_inherits_from_ctx(self):
        ctx = utils.FormattedDict(
            {
                "BUILD_DIR": "/usr/awesome",
                "WEBDIR": "",
                "PHPRC": "/usr/awesome/phpini",
                "PHP_VM": "php",
                "TMPDIR": "tmp",
                "LIBDIR": "lib",
                "CACHE_DIR": "cache",
                "OUR_SPECIAL_KEY": "SPECIAL_VALUE",
            }
        )

        environ_stub = Dingus()
        environ_stub._set_return_value(["OUR_SPECIAL_KEY"])

        write_config_stub = Dingus()

        with patches(
            {"os.environ.keys": environ_stub, "composer.extension.PHPComposerStrategy.write_config": write_config_stub}
        ):

            self.extension_module.ComposerExtension(ctx)
            cr = self.extension_module.ComposerCommandRunner(ctx, None)

            built_environment = cr._build_composer_environment()

        assert "OUR_SPECIAL_KEY" in built_environment, "OUR_SPECIAL_KEY was not found in the built_environment variable"
        assert built_environment["OUR_SPECIAL_KEY"] == "SPECIAL_VALUE", (
            '"OUR_SPECIAL_KEY" key in built_environment was %s; expected "SPECIAL_VALUE"'
            % built_environment["OUR_SPECIAL_KEY"]
        )
Ejemplo n.º 5
0
    def test_github_oauth_token_is_valid_uses_curl(self):
        ctx = utils.FormattedDict(
            {
                "BUILD_DIR": "/usr/awesome",
                "PHP_VM": "php",
                "TMPDIR": tempfile.gettempdir(),
                "LIBDIR": "lib",
                "CACHE_DIR": "cache",
                "WEBDIR": "",
            }
        )

        instance_stub = Dingus()
        instance_stub._set_return_value("""{"resources": {}}""")

        stream_output_stub = Dingus("test_github_oauth_token_uses_curl : stream_output")

        with patches(
            {"StringIO.StringIO.getvalue": instance_stub, "composer.extension.stream_output": stream_output_stub}
        ):
            ct = self.extension_module.ComposerExtension(ctx)
            ct._github_oauth_token_is_valid("MADE_UP_TOKEN_VALUE")
            executed_command = stream_output_stub.calls()[0].args[1]

        assert stream_output_stub.calls().once(), "stream_output() was called more than once"
        assert executed_command.find("curl") == 0, "Curl was not called, executed_command was %s" % executed_command
        assert executed_command.find('-H "Authorization: token MADE_UP_TOKEN_VALUE"') > 0, (
            "No token was passed to curl. Command was: %s" % executed_command
        )
        assert executed_command.find("https://api.github.com/rate_limit") > 0, (
            "No URL was passed to curl. Command was: %s" % executed_command
        )
Ejemplo n.º 6
0
    def test_build_composer_environment_inherits_from_ctx(self):
        ctx = utils.FormattedDict({
            'BUILD_DIR': '/usr/awesome',
            'PHPRC': '/usr/awesome/phpini',
            'PHP_VM': 'php',
            'TMPDIR': 'tmp',
            'LIBDIR': 'lib',
            'CACHE_DIR': 'cache',
            'OUR_SPECIAL_KEY': 'SPECIAL_VALUE'
        })

        environ_stub = Dingus()
        environ_stub._set_return_value(['OUR_SPECIAL_KEY'])

        write_config_stub = Dingus()

        with patches({
            'os.environ.keys': environ_stub,
            'composer.extension.PHPComposerStrategy.write_config': write_config_stub
        }):

            self.extension_module.ComposerExtension(ctx)
            cr = self.extension_module.ComposerCommandRunner(ctx, None)

            built_environment = cr._build_composer_environment()

        assert 'OUR_SPECIAL_KEY' in built_environment, \
            'OUR_SPECIAL_KEY was not found in the built_environment variable'
        assert built_environment['OUR_SPECIAL_KEY'] == 'SPECIAL_VALUE',  \
            '"OUR_SPECIAL_KEY" key in built_environment was %s; expected "SPECIAL_VALUE"' % built_environment['OUR_SPECIAL_KEY']
Ejemplo n.º 7
0
    def test_build_composer_environment_has_missing_key(self):
        os.environ["SOME_KEY"] = "does not matter"
        ctx = utils.FormattedDict(
            {
                "BUILD_DIR": "/usr/awesome",
                "WEBDIR": "",
                "PHP_VM": "php",
                "TMPDIR": "tmp",
                "LIBDIR": "lib",
                "CACHE_DIR": "cache",
                "SOME_KEY": utils.wrap("{exact_match}"),
            }
        )

        write_config_stub = Dingus()

        with patches({"composer.extension.PHPComposerStrategy.write_config": write_config_stub}):
            self.extension_module.ComposerExtension(ctx)
            cr = self.extension_module.ComposerCommandRunner(ctx, None)

            try:
                built_environment = cr._build_composer_environment()
                assert "{exact_match}" == built_environment["SOME_KEY"], "value should match"
            except KeyError, e:
                assert "exact_match" != e.message, "Should not try to evaluate value [%s]" % e
                raise
Ejemplo n.º 8
0
    def test_build_composer_environment_existing_path(self):
        ctx = utils.FormattedDict(
            {
                "BUILD_DIR": "/usr/awesome",
                "WEBDIR": "",
                "PHP_VM": "php",
                "TMPDIR": "tmp",
                "LIBDIR": "lib",
                "CACHE_DIR": "cache",
                "PATH": "/bin:/usr/bin",
            }
        )

        write_config_stub = Dingus()

        with patches({"composer.extension.PHPComposerStrategy.write_config": write_config_stub}):
            self.extension_module.ComposerExtension(ctx)
            cr = self.extension_module.ComposerCommandRunner(ctx, None)

            built_environment = cr._build_composer_environment()

        assert "PATH" in built_environment, "should have PATH set"
        assert built_environment["PATH"].endswith(":/usr/awesome/php/bin"), (
            "PATH should contain path to PHP, found [%s]" % built_environment["PATH"]
        )
Ejemplo n.º 9
0
    def test_build_composer_environment_converts_vars_to_str(self):
        ctx = utils.FormattedDict({
            'BUILD_DIR': '/usr/awesome',
            'PHP_VM': 'php',
            'TMPDIR': 'tmp',
            'LIBDIR': 'lib',
            'CACHE_DIR': 'cache',
            'PHPRC': '/usr/awesome/phpini',
            'MY_DICTIONARY': {'KEY': 'VALUE'},
        })

        write_config_stub = Dingus()

        with patches({
            'composer.extension.PHPComposerStrategy.write_config': write_config_stub
        }):
            self.extension_module.ComposerExtension(ctx)
            cr = self.extension_module.ComposerCommandRunner(ctx, None)

            built_environment = cr._build_composer_environment()

        for key, val in built_environment.iteritems():
            assert type(val) == str, \
                "Expected [%s]:[%s] to be type `str`, but found type [%s]" % (
                    key, val, type(val))
Ejemplo n.º 10
0
    def test_build_composer_environment_has_missing_key(self):
        os.environ['SOME_KEY'] = 'does not matter'
        ctx = utils.FormattedDict({
            'BUILD_DIR': '/usr/awesome',
            'PHP_VM': 'php',
            'TMPDIR': 'tmp',
            'LIBDIR': 'lib',
            'CACHE_DIR': 'cache',
            'SOME_KEY': utils.wrap('{exact_match}')
        })

        write_config_stub = Dingus()

        with patches({
            'composer.extension.PHPComposerStrategy.write_config': write_config_stub
        }):
            self.extension_module.ComposerExtension(ctx)
            cr = self.extension_module.ComposerCommandRunner(ctx, None)

            try:
                built_environment = cr._build_composer_environment()
                assert "{exact_match}" == built_environment['SOME_KEY'], \
                    "value should match"
            except KeyError, e:
                assert 'exact_match' != e.message, \
                    "Should not try to evaluate value [%s]" % e
                raise
Ejemplo n.º 11
0
    def test_build_composer_environment_inherits_from_ctx(self):
        ctx = utils.FormattedDict({
            'BUILD_DIR': '/usr/awesome',
            'PHPRC': '/usr/awesome/phpini',
            'PHP_VM': 'php',
            'TMPDIR': 'tmp',
            'LIBDIR': 'lib',
            'CACHE_DIR': 'cache',
            'OUR_SPECIAL_KEY': 'SPECIAL_VALUE'
        })

        environ_stub = Dingus()
        environ_stub._set_return_value(['OUR_SPECIAL_KEY'])

        write_config_stub = Dingus()

        with patches({
            'os.environ.keys': environ_stub,
            'composer.extension.PHPComposerStrategy.write_config': write_config_stub
        }):

            self.extension_module.ComposerExtension(ctx)
            cr = self.extension_module.ComposerCommandRunner(ctx, None)

            built_environment = cr._build_composer_environment()

        assert 'OUR_SPECIAL_KEY' in built_environment, \
            'OUR_SPECIAL_KEY was not found in the built_environment variable'
        assert built_environment['OUR_SPECIAL_KEY'] == 'SPECIAL_VALUE',  \
            '"OUR_SPECIAL_KEY" key in built_environment was %s; expected "SPECIAL_VALUE"' % built_environment['OUR_SPECIAL_KEY']
Ejemplo n.º 12
0
    def test_github_oauth_token_is_valid_interprets_github_api_401_as_false(self):  # noqa
        ctx = utils.FormattedDict({
            'BUILD_DIR': tempfile.gettempdir(),
            'PHP_VM': 'php',
            'TMPDIR': tempfile.gettempdir(),
            'LIBDIR': 'lib',
            'CACHE_DIR': 'cache',
            'WEBDIR': ''
        })

        instance_stub = Dingus()
        instance_stub._set_return_value("""{}""")

        stream_output_stub = Dingus(
            'test_github_oauth_token_uses_curl : stream_output')

        with patches({
            'StringIO.StringIO.getvalue': instance_stub,
            'composer.extension.stream_output': stream_output_stub,
        }):
            ct = self.extension_module.ComposerExtension(ctx)
            result = ct._github_oauth_token_is_valid('MADE_UP_TOKEN_VALUE')

        assert result is False, \
            '_github_oauth_token_is_valid returned %s, expected False' % result
Ejemplo n.º 13
0
    def test_github_oauth_token_is_valid_interprets_github_api_401_as_false(
            self):  # noqa
        ctx = utils.FormattedDict({
            'BP_DIR': '',
            'BUILD_DIR': tempfile.gettempdir(),
            'PHP_VM': 'php',
            'TMPDIR': tempfile.gettempdir(),
            'LIBDIR': 'lib',
            'CACHE_DIR': 'cache',
            'WEBDIR': ''
        })

        instance_stub = Dingus()
        instance_stub._set_return_value("""{}""")

        stream_output_stub = Dingus(
            'test_github_oauth_token_uses_curl : stream_output')

        with patches({
                'StringIO.StringIO.getvalue': instance_stub,
                'composer.extension.stream_output': stream_output_stub,
        }):
            ct = self.extension_module.ComposerExtension(ctx)
            result = ct._github_oauth_token_is_valid('MADE_UP_TOKEN_VALUE')

        assert result is False, \
            '_github_oauth_token_is_valid returned %s, expected False' % result
Ejemplo n.º 14
0
    def test_github_download_rate_is_exceeded(self):  # noqa
        ctx = utils.FormattedDict({
            'BP_DIR': '',
            'BUILD_DIR': tempfile.gettempdir(),
            'PHP_VM': 'php',
            'TMPDIR': tempfile.gettempdir(),
            'LIBDIR': 'lib',
            'CACHE_DIR': 'cache',
            'WEBDIR': ''
        })

        instance_stub = Dingus()
        instance_stub._set_return_value(
            """{"rate": {"limit": 60, "remaining": 0}}""")

        stream_output_stub = Dingus(
            'test_github_oauth_token_uses_curl : stream_output')

        with patches({
                'StringIO.StringIO.getvalue': instance_stub,
                'composer.extension.stream_output': stream_output_stub,
        }):
            ct = self.extension_module.ComposerExtension(ctx)
            result = ct._github_rate_exceeded(False)

        assert result is True, \
            '_github_oauth_token_is_valid returned %s, expected True' % result
Ejemplo n.º 15
0
    def test_github_oauth_token_is_valid_uses_curl(self):
        ctx = utils.FormattedDict({
            'BP_DIR': '',
            'BUILD_DIR': '/usr/awesome',
            'PHP_VM': 'php',
            'TMPDIR': tempfile.gettempdir(),
            'LIBDIR': 'lib',
            'CACHE_DIR': 'cache',
            'WEBDIR': ''
        })

        instance_stub = Dingus()
        instance_stub._set_return_value("""{"resources": {}}""")

        stream_output_stub = Dingus(
            'test_github_oauth_token_uses_curl : stream_output')

        with patches({
                'StringIO.StringIO.getvalue': instance_stub,
                'composer.extension.stream_output': stream_output_stub,
        }):
            ct = self.extension_module.ComposerExtension(ctx)
            ct._github_oauth_token_is_valid('MADE_UP_TOKEN_VALUE')
            executed_command = stream_output_stub.calls()[0].args[1]

        assert stream_output_stub.calls().once(), \
            'stream_output() was called more than once'
        assert executed_command.find('curl') == 0, \
            'Curl was not called, executed_command was %s' % executed_command
        assert executed_command.find(
            '-H "Authorization: token MADE_UP_TOKEN_VALUE"') > 0, \
            'No token was passed to curl. Command was: %s' % executed_command
        assert executed_command.find('https://api.github.com/rate_limit') > 0,\
            'No URL was passed to curl. Command was: %s' % executed_command
Ejemplo n.º 16
0
    def test_build_composer_environment_existing_path(self):
        ctx = utils.FormattedDict({
            'BP_DIR': '',
            'BUILD_DIR': '/usr/awesome',
            'WEBDIR': '',
            'PHP_VM': 'php',
            'TMPDIR': 'tmp',
            'LIBDIR': 'lib',
            'CACHE_DIR': 'cache',
            'PATH': '/bin:/usr/bin'
        })

        write_config_stub = Dingus()

        with patches({
                'composer.extension.PHPComposerStrategy.write_config':
                write_config_stub
        }):
            self.extension_module.ComposerExtension(ctx)
            cr = self.extension_module.ComposerCommandRunner(ctx, None)

            built_environment = cr._build_composer_environment()

        assert 'PATH' in built_environment, "should have PATH set"
        assert built_environment['PATH'].endswith(":/usr/awesome/php/bin"), \
            "PATH should contain path to PHP, found [%s]" \
            % built_environment['PATH']
Ejemplo n.º 17
0
    def test_build_composer_environment_forbids_overwriting_key_vars(self):
        ctx = utils.FormattedDict({
            'BP_DIR': '',
            'BUILD_DIR': '/usr/awesome',
            'WEBDIR': '',
            'PHP_VM': 'php',
            'TMPDIR': 'tmp',
            'LIBDIR': 'lib',
            'CACHE_DIR': 'cache',
            'PHPRC': '/usr/awesome/phpini',
        })

        write_config_stub = Dingus()

        with patches({
                'composer.extension.PHPComposerStrategy.write_config':
                write_config_stub
        }):
            self.extension_module.ComposerExtension(ctx)
            cr = self.extension_module.ComposerCommandRunner(ctx, None)

            built_environment = cr._build_composer_environment()

        eq_(built_environment['LD_LIBRARY_PATH'], '/usr/awesome/php/lib')
        eq_(built_environment['PHPRC'], 'tmp')
Ejemplo n.º 18
0
    def test_build_composer_environment_sets_composer_env_vars(self):
        ctx = utils.FormattedDict({
            'BUILD_DIR': '/tmp/build',
            'CACHE_DIR': '/tmp/cache',
            'LIBDIR': 'lib',
            'TMPDIR': '/tmp',
            'PHP_VM': 'php'
        })

        write_config_stub = Dingus()

        with patches({
            'composer.extension.PHPComposerStrategy.write_config': write_config_stub
        }):

            self.extension_module.ComposerExtension(ctx)
            cr = self.extension_module.ComposerCommandRunner(ctx, None)

            built_environment = cr._build_composer_environment()

        assert 'COMPOSER_VENDOR_DIR' in built_environment, \
            'Expect to find COMPOSER_VENDOR_DIR in built_environment'
        assert 'COMPOSER_BIN_DIR' in built_environment, \
            'Expect to find COMPOSER_BIN_DIR in built_environment'
        assert 'COMPOSER_CACHE_DIR' in built_environment, \
            'Expect to find COMPOSER_CACHE_DIR in built_environment'
Ejemplo n.º 19
0
    def test_build_composer_environment_sets_composer_env_vars(self):
        ctx = utils.FormattedDict({
            'BUILD_DIR': '/tmp/build',
            'CACHE_DIR': '/tmp/cache',
            'LIBDIR': 'lib',
            'TMPDIR': '/tmp',
            'PHP_VM': 'php'
        })

        write_config_stub = Dingus()

        with patches({
            'composer.extension.PHPComposerStrategy.write_config': write_config_stub
        }):

            self.extension_module.ComposerExtension(ctx)
            cr = self.extension_module.ComposerCommandRunner(ctx, None)

            built_environment = cr._build_composer_environment()

        assert 'COMPOSER_VENDOR_DIR' in built_environment, \
            'Expect to find COMPOSER_VENDOR_DIR in built_environment'
        assert 'COMPOSER_BIN_DIR' in built_environment, \
            'Expect to find COMPOSER_BIN_DIR in built_environment'
        assert 'COMPOSER_CACHE_DIR' in built_environment, \
            'Expect to find COMPOSER_CACHE_DIR in built_environment'
Ejemplo n.º 20
0
    def test_build_composer_environment_existing_path(self):
        ctx = utils.FormattedDict({
            'BUILD_DIR': '/usr/awesome',
            'WEBDIR': '',
            'PHP_VM': 'php',
            'TMPDIR': 'tmp',
            'LIBDIR': 'lib',
            'CACHE_DIR': 'cache',
            'PATH': '/bin:/usr/bin'
        })

        write_config_stub = Dingus()

        with patches({
            'composer.extension.PHPComposerStrategy.write_config': write_config_stub
        }):
            self.extension_module.ComposerExtension(ctx)
            cr = self.extension_module.ComposerCommandRunner(ctx, None)

            built_environment = cr._build_composer_environment()

        assert 'PATH' in built_environment, "should have PATH set"
        assert built_environment['PATH'].endswith(":/usr/awesome/php/bin"), \
            "PATH should contain path to PHP, found [%s]" \
            % built_environment['PATH']
Ejemplo n.º 21
0
    def test_build_composer_environment_converts_vars_to_str(self):
        ctx = utils.FormattedDict({
            'BUILD_DIR': '/usr/awesome',
            'PHP_VM': 'php',
            'TMPDIR': 'tmp',
            'LIBDIR': 'lib',
            'CACHE_DIR': 'cache',
            'PHPRC': '/usr/awesome/phpini',
            'MY_DICTIONARY': {'KEY': 'VALUE'},
        })

        write_config_stub = Dingus()

        with patches({
            'composer.extension.PHPComposerStrategy.write_config': write_config_stub
        }):
            self.extension_module.ComposerExtension(ctx)
            cr = self.extension_module.ComposerCommandRunner(ctx, None)

            built_environment = cr._build_composer_environment()

        for key, val in built_environment.iteritems():
            assert type(val) == str, \
                "Expected [%s]:[%s] to be type `str`, but found type [%s]" % (
                    key, val, type(val))
Ejemplo n.º 22
0
    def test_run_sets_github_oauth_token_if_present(self):
        ctx = utils.FormattedDict({
            'DOWNLOAD_URL': 'http://server/bins',
            'CACHE_HASH_ALGORITHM': 'sha1',
            'BUILD_DIR': '/usr/awesome',
            'PHP_VM': 'php',
            'TMPDIR': tempfile.gettempdir(),
            'LIBDIR': 'lib',
            'CACHE_DIR': 'cache',
            'COMPOSER_GITHUB_OAUTH_TOKEN': 'MADE_UP_TOKEN_VALUE',
            'BP_DIR': ''
        })

        instance_stub = Dingus()
        instance_stub._set_return_value(
            """{"rate": {"limit": 60, "remaining": 60}}""")

        stream_output_stub = Dingus()

        rewrite_stub = Dingus()

        environ_stub = Dingus()
        environ_stub._set_return_value('MADE_UP_TOKEN_VALUE')

        with patches({
                'StringIO.StringIO.getvalue': instance_stub,
                'composer.extension.stream_output': stream_output_stub,
                'composer.extension.utils.rewrite_cfgs': rewrite_stub,
                'os.environ.get': environ_stub
        }):
            ct = self.extension_module.ComposerExtension(ctx)

            builder_stub = Dingus(_ctx=ctx)
            ct._builder = builder_stub
            ct.composer_runner = \
                self.extension_module.ComposerCommandRunner(ctx, builder_stub)

            github_oauth_token_is_valid_stub = Dingus(
                'test_run_sets_github_oauth_token_if_present:'
                'github_oauth_token_is_valid_stub')
            github_oauth_token_is_valid_stub._set_return_value(True)
            ct._github_oauth_token_is_valid = github_oauth_token_is_valid_stub

            ct.run()

            executed_command = stream_output_stub.calls()[0].args[1]

        assert executed_command.find('config') > 0, 'did not see "config"'
        assert executed_command.find('-g') > 0, 'did not see "-g"'
        assert executed_command.find('github-oauth.github.com') > 0, \
            'did not see "github-oauth.github.com"'
        assert executed_command.find('"MADE_UP_TOKEN_VALUE"') > 0, \
            'did not see "MADE_UP_TOKEN_VALUE"'
Ejemplo n.º 23
0
    def test_run_sets_github_oauth_token_if_present(self):
        ctx = utils.FormattedDict(
            {
                "BUILD_DIR": "/usr/awesome",
                "PHP_VM": "php",
                "TMPDIR": tempfile.gettempdir(),
                "LIBDIR": "lib",
                "CACHE_DIR": "cache",
                "COMPOSER_GITHUB_OAUTH_TOKEN": "MADE_UP_TOKEN_VALUE",
                "BP_DIR": "",
                "WEBDIR": "",
            }
        )

        instance_stub = Dingus()
        instance_stub._set_return_value("""{"rate": {"limit": 60, "remaining": 60}}""")

        stream_output_stub = Dingus()

        rewrite_stub = Dingus()

        environ_stub = Dingus()
        environ_stub._set_return_value("MADE_UP_TOKEN_VALUE")

        with patches(
            {
                "StringIO.StringIO.getvalue": instance_stub,
                "composer.extension.stream_output": stream_output_stub,
                "composer.extension.utils.rewrite_cfgs": rewrite_stub,
                "os.environ.get": environ_stub,
            }
        ):
            ct = self.extension_module.ComposerExtension(ctx)

            builder_stub = Dingus(_ctx=ctx)
            ct._builder = builder_stub
            ct.composer_runner = self.extension_module.ComposerCommandRunner(ctx, builder_stub)

            github_oauth_token_is_valid_stub = Dingus(
                "test_run_sets_github_oauth_token_if_present:" "github_oauth_token_is_valid_stub"
            )
            github_oauth_token_is_valid_stub._set_return_value(True)
            ct._github_oauth_token_is_valid = github_oauth_token_is_valid_stub

            ct.run()

            executed_command = stream_output_stub.calls()[0].args[1]

        assert executed_command.find("config") > 0, 'did not see "config"'
        assert executed_command.find("-g") > 0, 'did not see "-g"'
        assert executed_command.find("github-oauth.github.com") > 0, 'did not see "github-oauth.github.com"'
        assert executed_command.find('"MADE_UP_TOKEN_VALUE"') > 0, 'did not see "MADE_UP_TOKEN_VALUE"'
Ejemplo n.º 24
0
    def test_composer_tool_run_custom_composer_opts(self):
        ctx = utils.FormattedDict({
            'PHP_VM':
            'php',
            'DOWNLOAD_URL':
            'http://server/bins',
            'CACHE_HASH_ALGORITHM':
            'sha1',
            'BUILD_DIR':
            '/build/dir',
            'CACHE_DIR':
            '/cache/dir',
            'TMPDIR':
            tempfile.gettempdir(),
            'WEBDIR':
            'htdocs',
            'LIBDIR':
            'lib',
            'COMPOSER_INSTALL_OPTIONS': ['--optimize-autoloader'],
            'BP_DIR':
            ''
        })

        instance_stub = Dingus()
        instance_stub._set_return_value(
            """{"rate": {"limit": 60, "remaining": 60}}""")

        stream_output_stub = Dingus()

        rewrite_stub = Dingus()

        builder = Dingus(_ctx=ctx)

        with patches({
                'StringIO.StringIO.getvalue': instance_stub,
                'composer.extension.stream_output': stream_output_stub,
                'composer.extension.utils.rewrite_cfgs': rewrite_stub
        }):
            ct = self.extension_module.ComposerExtension(ctx)
            ct._builder = builder
            ct.composer_runner = \
                self.extension_module.ComposerCommandRunner(ctx, builder)
            ct.run()
            eq_(2, len(builder.move.calls()))
            eq_(1, len(builder.copy.calls()))
            assert rewrite_stub.calls().once()
            rewrite_args = rewrite_stub.calls()[0].args
            assert rewrite_args[0].endswith('php.ini')
            assert 'HOME' in rewrite_args[1]
            assert 'TMPDIR' in rewrite_args[1]
            instCmd = stream_output_stub.calls()[-1].args[1]
            assert instCmd.find('--optimize-autoloader') > 0
Ejemplo n.º 25
0
    def test_run_sets_github_oauth_token_if_present(self):
        ctx = utils.FormattedDict({
            'DOWNLOAD_URL': 'http://server/bins',
            'CACHE_HASH_ALGORITHM': 'sha1',
            'BUILD_DIR': '/usr/awesome',
            'PHP_VM': 'php',
            'TMPDIR': tempfile.gettempdir(),
            'LIBDIR': 'lib',
            'CACHE_DIR': 'cache',
            'COMPOSER_GITHUB_OAUTH_TOKEN': 'MADE_UP_TOKEN_VALUE',
            'BP_DIR': ''
        })

        instance_stub = Dingus()
        instance_stub._set_return_value("""{"rate": {"limit": 60, "remaining": 60}}""")

        stream_output_stub = Dingus()

        rewrite_stub = Dingus()

        environ_stub = Dingus()
        environ_stub._set_return_value('MADE_UP_TOKEN_VALUE')

        with patches({
            'StringIO.StringIO.getvalue': instance_stub,
            'composer.extension.stream_output': stream_output_stub,
            'composer.extension.utils.rewrite_cfgs': rewrite_stub,
            'os.environ.get': environ_stub
        }):
            ct = self.extension_module.ComposerExtension(ctx)

            builder_stub = Dingus(_ctx=ctx)
            ct._builder = builder_stub
            ct.composer_runner = \
                self.extension_module.ComposerCommandRunner(ctx, builder_stub)

            github_oauth_token_is_valid_stub = Dingus(
                'test_run_sets_github_oauth_token_if_present:'
                'github_oauth_token_is_valid_stub')
            github_oauth_token_is_valid_stub._set_return_value(True)
            ct._github_oauth_token_is_valid = github_oauth_token_is_valid_stub

            ct.run()

            executed_command = stream_output_stub.calls()[0].args[1]

        assert executed_command.find('config') > 0, 'did not see "config"'
        assert executed_command.find('-g') > 0, 'did not see "-g"'
        assert executed_command.find('github-oauth.github.com') > 0, \
            'did not see "github-oauth.github.com"'
        assert executed_command.find('"MADE_UP_TOKEN_VALUE"') > 0, \
            'did not see "MADE_UP_TOKEN_VALUE"'
Ejemplo n.º 26
0
    def test_composer_tool_run_sanity_checks(self):
        ctx = utils.FormattedDict({
            'PHP_VM': 'php',
            'DOWNLOAD_URL': 'http://server/bins',
            'CACHE_HASH_ALGORITHM': 'sha1',
            'BUILD_DIR': '/build/dir',
            'CACHE_DIR': '/cache/dir',
            'TMPDIR': tempfile.gettempdir(),
            'LIBDIR': 'lib',
            'BP_DIR': ''
        })

        instance_stub = Dingus()
        instance_stub._set_return_value(
            """{"rate": {"limit": 60, "remaining": 60}}""")

        stream_output_stub = Dingus()

        rewrite_stub = Dingus()

        builder = Dingus(_ctx=ctx)

        exists_stub = Dingus()

        with patches({
                'StringIO.StringIO.getvalue': instance_stub,
                'composer.extension.stream_output': stream_output_stub,
                'composer.extension.utils.rewrite_cfgs': rewrite_stub
        }):
            composer_extension = \
                self.extension_module.ComposerExtension(ctx)
            composer_extension._log = Dingus()
            composer_extension._builder = builder
            composer_extension.composer_runner = \
                self.extension_module.ComposerCommandRunner(ctx, builder)

            composer_extension.run()

            composer_extension_calls = composer_extension._log.warning.calls()
            assert len(composer_extension_calls) > 0
            assert composer_extension_calls[0].args[0].find('PROTIP:') == 0
            exists = Dingus(return_value=True)
            with patch('os.path.exists', exists_stub):
                composer_extension._log = Dingus()
                composer_extension.run()
            assert len(exists_stub.calls()) == 2
            assert len(composer_extension._log.warning.calls()) == 0
Ejemplo n.º 27
0
    def test_composer_tool_run_sanity_checks(self):
        ctx = utils.FormattedDict(
            {
                "PHP_VM": "php",
                "BUILD_DIR": "/build/dir",
                "CACHE_DIR": "/cache/dir",
                "WEBDIR": "",
                "TMPDIR": tempfile.gettempdir(),
                "LIBDIR": "lib",
                "BP_DIR": "",
            }
        )

        instance_stub = Dingus()
        instance_stub._set_return_value("""{"rate": {"limit": 60, "remaining": 60}}""")

        stream_output_stub = Dingus()

        rewrite_stub = Dingus()

        builder = Dingus(_ctx=ctx)

        exists_stub = Dingus()

        with patches(
            {
                "StringIO.StringIO.getvalue": instance_stub,
                "composer.extension.stream_output": stream_output_stub,
                "composer.extension.utils.rewrite_cfgs": rewrite_stub,
            }
        ):
            composer_extension = self.extension_module.ComposerExtension(ctx)
            composer_extension._log = Dingus()
            composer_extension._builder = builder
            composer_extension.composer_runner = self.extension_module.ComposerCommandRunner(ctx, builder)

            composer_extension.run()

            composer_extension_calls = composer_extension._log.warning.calls()
            assert len(composer_extension_calls) > 0
            assert composer_extension_calls[0].args[0].find("PROTIP:") == 0
            exists = Dingus(return_value=True)
            with patch("os.path.exists", exists_stub):
                composer_extension._log = Dingus()
                composer_extension.run()
            assert len(composer_extension._log.warning.calls()) == 0
Ejemplo n.º 28
0
    def test_composer_tool_run_sanity_checks(self):
        ctx = utils.FormattedDict({
            'PHP_VM': 'php',
            'DOWNLOAD_URL': 'http://server/bins',
            'CACHE_HASH_ALGORITHM': 'sha1',
            'BUILD_DIR': '/build/dir',
            'CACHE_DIR': '/cache/dir',
            'TMPDIR': tempfile.gettempdir(),
            'LIBDIR': 'lib',
            'BP_DIR': ''
        })

        instance_stub = Dingus()
        instance_stub._set_return_value("""{"rate": {"limit": 60, "remaining": 60}}""")

        stream_output_stub = Dingus()

        rewrite_stub = Dingus()

        builder = Dingus(_ctx=ctx)
        
        exists_stub = Dingus()

        with patches({
            'StringIO.StringIO.getvalue': instance_stub,
            'composer.extension.stream_output': stream_output_stub,
            'composer.extension.utils.rewrite_cfgs': rewrite_stub
        }):
            composer_extension = \
                self.extension_module.ComposerExtension(ctx)
            composer_extension._log = Dingus()
            composer_extension._builder = builder
            composer_extension.composer_runner = \
                self.extension_module.ComposerCommandRunner(ctx, builder)

            composer_extension.run()

            composer_extension_calls = composer_extension._log.warning.calls()
            assert len(composer_extension_calls) > 0
            assert composer_extension_calls[0].args[0].find('PROTIP:') == 0
            exists = Dingus(return_value=True)
            with patch('os.path.exists', exists_stub):
                composer_extension._log = Dingus()
                composer_extension.run()
            assert len(exists_stub.calls()) == 2
            assert len(composer_extension._log.warning.calls()) == 0
Ejemplo n.º 29
0
    def test_run_does_not_set_github_oauth_if_missing(self):
        ctx = utils.FormattedDict({
            'DOWNLOAD_URL': 'http://server/bins',
            'CACHE_HASH_ALGORITHM': 'sha1',
            'BUILD_DIR': '/usr/awesome',
            'PHP_VM': 'php',
            'TMPDIR': tempfile.gettempdir(),
            'LIBDIR': 'lib',
            'CACHE_DIR': 'cache',
            'BP_DIR': ''
        })
        instance_stub = Dingus()
        instance_stub._set_return_value(
            """{"rate": {"limit": 60, "remaining": 60}}""")

        stream_output_stub = Dingus()

        rewrite_stub = Dingus()

        builder = Dingus(_ctx=ctx)

        setup_composer_github_token_stub = Dingus()

        with patches({
                'StringIO.StringIO.getvalue':
                instance_stub,
                'composer.extension.stream_output':
                stream_output_stub,
                'composer.extension.utils.rewrite_cfgs':
                rewrite_stub,
                'composer.extension.ComposerExtension.setup_composer_github_token':
                setup_composer_github_token_stub
        }):
            ct = self.extension_module.ComposerExtension(ctx)

            ct._builder = builder
            ct.composer_runner = \
                self.extension_module.ComposerCommandRunner(ctx, builder)
            ct.run()

            setup_composer_github_token_calls = setup_composer_github_token_stub.calls(
            )

        assert 0 == len(setup_composer_github_token_calls), \
            'setup_composer_github_token() was called %s times, expected 0' % len(setup_composer_github_token_calls)
Ejemplo n.º 30
0
    def test_no_github_api_call_with_cached_buildpack(self):
        ctx = utils.FormattedDict({
            'BUILD_DIR': tempfile.gettempdir(),
            'PHP_VM': 'php',
            'TMPDIR': tempfile.gettempdir(),
            'LIBDIR': 'lib',
            'CACHE_DIR': 'cache',
            'BP_DIR': '',
            'WEBDIR': ''
        })

        builder = Dingus(_ctx=ctx)

        path_exists_stub = Dingus()
        path_exists_stub._set_return_value(True)

        setup_composer_github_token_stub = Dingus()
        check_github_rate_exceeded_stub = Dingus()

        rewrite_stub = Dingus()

        stream_output_stub = Dingus(
            'test_github_oauth_token_uses_curl : stream_output')
        with patches({
                'os.path.exists':
                path_exists_stub,
                'composer.extension.ComposerExtension.setup_composer_github_token':
                setup_composer_github_token_stub,
                'composer.extension.ComposerExtension.check_github_rate_exceeded':
                check_github_rate_exceeded_stub,
                'composer.extension.utils.rewrite_cfgs':
                rewrite_stub,
                'composer.extension.stream_output':
                stream_output_stub
        }):
            ct = self.extension_module.ComposerExtension(ctx)
            ct._builder = builder
            ct.composer_runner = \
                    self.extension_module.ComposerCommandRunner(ctx, builder)
            ct.run()

        assert 0 == len(setup_composer_github_token_stub.calls()), \
                'setup_composer_github_token was called, expected no calls'
        assert 0 == len(check_github_rate_exceeded_stub.calls()), \
                'check_github_rate_exceeded was called, expected no calls'
Ejemplo n.º 31
0
    def test_no_github_api_call_with_cached_buildpack(self):
        ctx = utils.FormattedDict(
            {
                "BUILD_DIR": tempfile.gettempdir(),
                "PHP_VM": "php",
                "TMPDIR": tempfile.gettempdir(),
                "LIBDIR": "lib",
                "CACHE_DIR": "cache",
                "BP_DIR": "",
                "WEBDIR": "",
            }
        )

        builder = Dingus(_ctx=ctx)

        path_exists_stub = Dingus()
        path_exists_stub._set_return_value(True)

        setup_composer_github_token_stub = Dingus()
        check_github_rate_exceeded_stub = Dingus()

        rewrite_stub = Dingus()

        stream_output_stub = Dingus("test_github_oauth_token_uses_curl : stream_output")
        with patches(
            {
                "os.path.exists": path_exists_stub,
                "composer.extension.ComposerExtension.setup_composer_github_token": setup_composer_github_token_stub,
                "composer.extension.ComposerExtension.check_github_rate_exceeded": check_github_rate_exceeded_stub,
                "composer.extension.utils.rewrite_cfgs": rewrite_stub,
                "composer.extension.stream_output": stream_output_stub,
            }
        ):
            ct = self.extension_module.ComposerExtension(ctx)
            ct._builder = builder
            ct.composer_runner = self.extension_module.ComposerCommandRunner(ctx, builder)
            ct.run()

        assert 0 == len(
            setup_composer_github_token_stub.calls()
        ), "setup_composer_github_token was called, expected no calls"
        assert 0 == len(
            check_github_rate_exceeded_stub.calls()
        ), "check_github_rate_exceeded was called, expected no calls"
Ejemplo n.º 32
0
    def test_composer_run_streams_debug_output(self):
        ctx = utils.FormattedDict({
            'PHP_VM': 'hhvm',  # PHP strategy does other stuff
            'DOWNLOAD_URL': 'http://server/bins',
            'CACHE_HASH_ALGORITHM': 'sha1',
            'BUILD_DIR': '/build/dir',
            'CACHE_DIR': '/cache/dir',
            'TMPDIR': tempfile.gettempdir(),
            'WEBDIR': 'htdocs',
            'LIBDIR': 'lib',
            'BP_DEBUG': 'True',
            'BP_DIR': ''
        })

        instance_stub = Dingus(
            return_value="""{"rate": {"limit": 60, "remaining": 60}}""")

        stream_output_stub = Dingus()

        builder = Dingus(_ctx=ctx)

        with patches({
                'StringIO.StringIO.getvalue': instance_stub,
                'composer.extension.stream_output': stream_output_stub
        }):
            ct = self.extension_module.ComposerExtension(ctx)
            ct._builder = builder
            ct.composer_runner = \
                self.extension_module.ComposerCommandRunner(ctx, builder)
            ct.run()
            stream_output_calls = stream_output_stub.calls()
            assert 3 == len(stream_output_calls), \
                "The number of stream_output calls returned %s, expected 3" % len(stream_output_stub.calls())
            # first is called `composer -V`
            verCmd = stream_output_calls[0].args[1]
            assert verCmd.find('composer.phar -V')
            # then composer install
            instCmd = stream_output_calls[-1].args[1]
            assert instCmd.find('/build/dir/php/bin/composer.phar') > 0
            assert instCmd.find('install') > 0
            assert instCmd.find('--no-progress') > 0
            assert instCmd.find('--no-interaction') > 0
            assert instCmd.find('--no-dev') > 0
Ejemplo n.º 33
0
    def test_composer_run_streams_debug_output(self):
        ctx = utils.FormattedDict({
            'PHP_VM': 'hhvm',  # PHP strategy does other stuff
            'DOWNLOAD_URL': 'http://server/bins',
            'CACHE_HASH_ALGORITHM': 'sha1',
            'BUILD_DIR': '/build/dir',
            'CACHE_DIR': '/cache/dir',
            'TMPDIR': tempfile.gettempdir(),
            'WEBDIR': 'htdocs',
            'LIBDIR': 'lib',
            'BP_DEBUG': 'True',
            'BP_DIR': ''
        })

        instance_stub = Dingus(return_value="""{"rate": {"limit": 60, "remaining": 60}}""")

        stream_output_stub = Dingus()

        builder = Dingus(_ctx=ctx)

        with patches({
            'StringIO.StringIO.getvalue': instance_stub,
            'composer.extension.stream_output': stream_output_stub
        }):
            ct = self.extension_module.ComposerExtension(ctx)
            ct._builder = builder
            ct.composer_runner = \
                self.extension_module.ComposerCommandRunner(ctx, builder)
            ct.run()
            stream_output_calls = stream_output_stub.calls()
            assert 3 == len(stream_output_calls), \
                "The number of stream_output calls returned %s, expected 3" % len(stream_output_stub.calls())
            # first is called `composer -V`
            verCmd = stream_output_calls[0].args[1]
            assert verCmd.find('composer.phar -V')
            # then composer install
            instCmd = stream_output_calls[-1].args[1]
            assert instCmd.find('/build/dir/php/bin/composer.phar') > 0
            assert instCmd.find('install') > 0
            assert instCmd.find('--no-progress') > 0
            assert instCmd.find('--no-interaction') > 0
            assert instCmd.find('--no-dev') > 0
Ejemplo n.º 34
0
    def test_composer_tool_run_custom_composer_opts(self):
        ctx = utils.FormattedDict({
            'PHP_VM': 'php',
            'DOWNLOAD_URL': 'http://server/bins',
            'CACHE_HASH_ALGORITHM': 'sha1',
            'BUILD_DIR': '/build/dir',
            'CACHE_DIR': '/cache/dir',
            'TMPDIR': tempfile.gettempdir(),
            'WEBDIR': 'htdocs',
            'LIBDIR': 'lib',
            'COMPOSER_INSTALL_OPTIONS': ['--optimize-autoloader'],
            'BP_DIR': ''
        })

        instance_stub = Dingus()
        instance_stub._set_return_value("""{"rate": {"limit": 60, "remaining": 60}}""")

        stream_output_stub = Dingus()

        rewrite_stub = Dingus()

        builder = Dingus(_ctx=ctx)

        with patches({
            'StringIO.StringIO.getvalue': instance_stub,
            'composer.extension.stream_output': stream_output_stub,
            'composer.extension.utils.rewrite_cfgs': rewrite_stub
        }):
            ct = self.extension_module.ComposerExtension(ctx)
            ct._builder = builder
            ct.composer_runner = \
                self.extension_module.ComposerCommandRunner(ctx, builder)
            ct.run()
            eq_(2, len(builder.move.calls()))
            eq_(1, len(builder.copy.calls()))
            assert rewrite_stub.calls().once()
            rewrite_args = rewrite_stub.calls()[0].args
            assert rewrite_args[0].endswith('php.ini')
            assert 'HOME' in rewrite_args[1]
            assert 'TMPDIR' in rewrite_args[1]
            instCmd = stream_output_stub.calls()[-1].args[1]
            assert instCmd.find('--optimize-autoloader') > 0
Ejemplo n.º 35
0
    def test_run_does_not_set_github_oauth_if_missing(self):
        ctx = utils.FormattedDict(
            {
                "BUILD_DIR": "/usr/awesome",
                "PHP_VM": "php",
                "TMPDIR": tempfile.gettempdir(),
                "LIBDIR": "lib",
                "CACHE_DIR": "cache",
                "BP_DIR": "",
                "WEBDIR": "",
            }
        )
        instance_stub = Dingus()
        instance_stub._set_return_value("""{"rate": {"limit": 60, "remaining": 60}}""")

        stream_output_stub = Dingus()

        rewrite_stub = Dingus()

        builder = Dingus(_ctx=ctx)

        setup_composer_github_token_stub = Dingus()

        with patches(
            {
                "StringIO.StringIO.getvalue": instance_stub,
                "composer.extension.stream_output": stream_output_stub,
                "composer.extension.utils.rewrite_cfgs": rewrite_stub,
                "composer.extension.ComposerExtension.setup_composer_github_token": setup_composer_github_token_stub,
            }
        ):
            ct = self.extension_module.ComposerExtension(ctx)

            ct._builder = builder
            ct.composer_runner = self.extension_module.ComposerCommandRunner(ctx, builder)
            ct.run()

            setup_composer_github_token_calls = setup_composer_github_token_stub.calls()

        assert 0 == len(
            setup_composer_github_token_calls
        ), "setup_composer_github_token() was called %s times, expected 0" % len(setup_composer_github_token_calls)
Ejemplo n.º 36
0
    def test_composer_tool_run_custom_composer_opts(self):
        ctx = utils.FormattedDict(
            {
                "PHP_VM": "php",
                "BUILD_DIR": "/build/dir",
                "CACHE_DIR": "/cache/dir",
                "TMPDIR": tempfile.gettempdir(),
                "WEBDIR": "htdocs",
                "LIBDIR": "lib",
                "COMPOSER_INSTALL_OPTIONS": ["--optimize-autoloader"],
                "BP_DIR": "",
            }
        )

        instance_stub = Dingus()
        instance_stub._set_return_value("""{"rate": {"limit": 60, "remaining": 60}}""")

        stream_output_stub = Dingus()

        rewrite_stub = Dingus()

        builder = Dingus(_ctx=ctx)

        with patches(
            {
                "StringIO.StringIO.getvalue": instance_stub,
                "composer.extension.stream_output": stream_output_stub,
                "composer.extension.utils.rewrite_cfgs": rewrite_stub,
            }
        ):
            ct = self.extension_module.ComposerExtension(ctx)
            ct._builder = builder
            ct.composer_runner = self.extension_module.ComposerCommandRunner(ctx, builder)
            ct.run()
            eq_(1, len(builder.copy.calls()))
            assert rewrite_stub.calls().once()
            rewrite_args = rewrite_stub.calls()[0].args
            assert rewrite_args[0].endswith("php.ini")
            assert "HOME" in rewrite_args[1]
            assert "TMPDIR" in rewrite_args[1]
            instCmd = stream_output_stub.calls()[-1].args[1]
            assert instCmd.find("--optimize-autoloader") > 0
Ejemplo n.º 37
0
    def test_composer_run_streams_debug_output(self):
        ctx = utils.FormattedDict(
            {
                "PHP_VM": "hhvm",  # PHP strategy does other stuff
                "BUILD_DIR": "/build/dir",
                "CACHE_DIR": "/cache/dir",
                "TMPDIR": tempfile.gettempdir(),
                "WEBDIR": "htdocs",
                "LIBDIR": "lib",
                "BP_DEBUG": "True",
                "BP_DIR": "",
            }
        )

        instance_stub = Dingus(return_value="""{"rate": {"limit": 60, "remaining": 60}}""")

        stream_output_stub = Dingus()

        builder = Dingus(_ctx=ctx)

        with patches(
            {"StringIO.StringIO.getvalue": instance_stub, "composer.extension.stream_output": stream_output_stub}
        ):
            ct = self.extension_module.ComposerExtension(ctx)
            ct._builder = builder
            ct.composer_runner = self.extension_module.ComposerCommandRunner(ctx, builder)
            ct.run()
            stream_output_calls = stream_output_stub.calls()
            assert 3 == len(stream_output_calls), "The number of stream_output calls returned %s, expected 3" % len(
                stream_output_stub.calls()
            )
            # first is called `composer -V`
            verCmd = stream_output_calls[0].args[1]
            assert verCmd.find("composer.phar -V")
            # then composer install
            instCmd = stream_output_calls[-1].args[1]
            assert instCmd.find("/build/dir/php/bin/composer.phar") > 0
            assert instCmd.find("install") > 0
            assert instCmd.find("--no-progress") > 0
            assert instCmd.find("--no-interaction") > 0
            assert instCmd.find("--no-dev") > 0
Ejemplo n.º 38
0
    def test_no_github_api_call_with_cached_buildpack(self):
        ctx = utils.FormattedDict({
            'BUILD_DIR': tempfile.gettempdir(),
            'PHP_VM': 'php',
            'TMPDIR': tempfile.gettempdir(),
            'LIBDIR': 'lib',
            'CACHE_DIR': 'cache',
            'BP_DIR': '',
            'WEBDIR': ''
        })

        builder = Dingus(_ctx=ctx)

        path_exists_stub = Dingus()
        path_exists_stub._set_return_value(True)

        setup_composer_github_token_stub = Dingus()
        check_github_rate_exceeded_stub = Dingus()

        rewrite_stub = Dingus()

        stream_output_stub = Dingus(
            'test_github_oauth_token_uses_curl : stream_output')
        with patches({
            'os.path.exists': path_exists_stub,
            'composer.extension.ComposerExtension.setup_composer_github_token': setup_composer_github_token_stub,
            'composer.extension.ComposerExtension.check_github_rate_exceeded': check_github_rate_exceeded_stub,
            'composer.extension.utils.rewrite_cfgs': rewrite_stub,
            'composer.extension.stream_output': stream_output_stub
        }):
            ct = self.extension_module.ComposerExtension(ctx)
            ct._builder = builder
            ct.composer_runner = \
                    self.extension_module.ComposerCommandRunner(ctx, builder)
            ct.run()

        assert 0 == len(setup_composer_github_token_stub.calls()), \
                'setup_composer_github_token was called, expected no calls'
        assert 0 == len(check_github_rate_exceeded_stub.calls()), \
                'check_github_rate_exceeded was called, expected no calls'
Ejemplo n.º 39
0
    def test_build_composer_environment_forbids_overwriting_key_vars(self):
        ctx = utils.FormattedDict({
            'BUILD_DIR': '/usr/awesome',
            'PHP_VM': 'php',
            'TMPDIR': 'tmp',
            'LIBDIR': 'lib',
            'CACHE_DIR': 'cache',
            'PHPRC': '/usr/awesome/phpini',
        })

        write_config_stub = Dingus()

        with patches({
            'composer.extension.PHPComposerStrategy.write_config': write_config_stub
        }):
            self.extension_module.ComposerExtension(ctx)
            cr = self.extension_module.ComposerCommandRunner(ctx, None)

            built_environment = cr._build_composer_environment()

        eq_(built_environment['LD_LIBRARY_PATH'], '/usr/awesome/php/lib')
        eq_(built_environment['PHPRC'], 'tmp')
Ejemplo n.º 40
0
    def test_run_does_not_set_github_oauth_if_missing(self):
        ctx = utils.FormattedDict({
            'DOWNLOAD_URL': 'http://server/bins',
            'CACHE_HASH_ALGORITHM': 'sha1',
            'BUILD_DIR': '/usr/awesome',
            'PHP_VM': 'php',
            'TMPDIR': tempfile.gettempdir(),
            'LIBDIR': 'lib',
            'CACHE_DIR': 'cache',
            'BP_DIR': ''
        })
        instance_stub = Dingus()
        instance_stub._set_return_value("""{"rate": {"limit": 60, "remaining": 60}}""")

        stream_output_stub = Dingus()

        rewrite_stub = Dingus()

        builder = Dingus(_ctx=ctx)

        setup_composer_github_token_stub = Dingus()

        with patches({
            'StringIO.StringIO.getvalue': instance_stub,
            'composer.extension.stream_output': stream_output_stub,
            'composer.extension.utils.rewrite_cfgs': rewrite_stub,
            'composer.extension.ComposerExtension.setup_composer_github_token': setup_composer_github_token_stub
        }):
            ct = self.extension_module.ComposerExtension(ctx)

            ct._builder = builder
            ct.composer_runner = \
                self.extension_module.ComposerCommandRunner(ctx, builder)
            ct.run()

            setup_composer_github_token_calls = setup_composer_github_token_stub.calls()

        assert 0 == len(setup_composer_github_token_calls), \
            'setup_composer_github_token() was called %s times, expected 0' % len(setup_composer_github_token_calls)
Ejemplo n.º 41
0
    def test_build_composer_environment_forbids_overwriting_key_vars(self):
        ctx = utils.FormattedDict(
            {
                "BUILD_DIR": "/usr/awesome",
                "WEBDIR": "",
                "PHP_VM": "php",
                "TMPDIR": "tmp",
                "LIBDIR": "lib",
                "CACHE_DIR": "cache",
                "PHPRC": "/usr/awesome/phpini",
            }
        )

        write_config_stub = Dingus()

        with patches({"composer.extension.PHPComposerStrategy.write_config": write_config_stub}):
            self.extension_module.ComposerExtension(ctx)
            cr = self.extension_module.ComposerCommandRunner(ctx, None)

            built_environment = cr._build_composer_environment()

        eq_(built_environment["LD_LIBRARY_PATH"], "/usr/awesome/php/lib")
        eq_(built_environment["PHPRC"], "tmp")
Ejemplo n.º 42
0
    def test_composer_run_streams_output(self):
        ctx = utils.FormattedDict({
            'PHP_VM': 'hhvm',  # PHP strategy does other stuff
            'BUILD_DIR': '/build/dir',
            'CACHE_DIR': '/cache/dir',
            'TMPDIR': tempfile.gettempdir(),
            'WEBDIR': 'htdocs',
            'LIBDIR': 'lib',
            'BP_DIR': ''
        })

        instance_stub = Dingus()
        instance_stub._set_return_value(
            """{"rate": {"limit": 60, "remaining": 60}}""")

        stream_output_stub = Dingus()

        builder = Dingus(_ctx=ctx)

        with patches({
                'StringIO.StringIO.getvalue': instance_stub,
                'composer.extension.stream_output': stream_output_stub
        }):
            ct = self.extension_module.ComposerExtension(ctx)
            ct._builder = builder
            ct.composer_runner = \
                    self.extension_module.ComposerCommandRunner(ctx, builder)
            ct.run()
            stream_output_calls = stream_output_stub.calls()
            assert 2 == len(stream_output_calls), \
                    "The number of stream_output calls returned %s, expected 2" % len(stream_output_stub.calls())
            instCmd = stream_output_calls[-1].args[1]
            assert instCmd.find('/build/dir/php/bin/composer.phar') > 0
            assert instCmd.find('install') > 0
            assert instCmd.find('--no-progress') > 0
            assert instCmd.find('--no-interaction') > 0
            assert instCmd.find('--no-dev') > 0
Ejemplo n.º 43
0
    def test_github_download_rate_is_exceeded(self):  # noqa
        ctx = utils.FormattedDict(
            {
                "BUILD_DIR": tempfile.gettempdir(),
                "PHP_VM": "php",
                "TMPDIR": tempfile.gettempdir(),
                "LIBDIR": "lib",
                "CACHE_DIR": "cache",
                "WEBDIR": "",
            }
        )

        instance_stub = Dingus()
        instance_stub._set_return_value("""{"rate": {"limit": 60, "remaining": 0}}""")

        stream_output_stub = Dingus("test_github_oauth_token_uses_curl : stream_output")

        with patches(
            {"StringIO.StringIO.getvalue": instance_stub, "composer.extension.stream_output": stream_output_stub}
        ):
            ct = self.extension_module.ComposerExtension(ctx)
            result = ct._github_rate_exceeded(False)

        assert result is True, "_github_oauth_token_is_valid returned %s, expected True" % result
Ejemplo n.º 44
0
    def test_github_oauth_token_is_valid_interprets_github_api_401_as_false(self):  # noqa
        ctx = utils.FormattedDict(
            {
                "BUILD_DIR": tempfile.gettempdir(),
                "PHP_VM": "php",
                "TMPDIR": tempfile.gettempdir(),
                "LIBDIR": "lib",
                "CACHE_DIR": "cache",
                "WEBDIR": "",
            }
        )

        instance_stub = Dingus()
        instance_stub._set_return_value("""{}""")

        stream_output_stub = Dingus("test_github_oauth_token_uses_curl : stream_output")

        with patches(
            {"StringIO.StringIO.getvalue": instance_stub, "composer.extension.stream_output": stream_output_stub}
        ):
            ct = self.extension_module.ComposerExtension(ctx)
            result = ct._github_oauth_token_is_valid("MADE_UP_TOKEN_VALUE")

        assert result is False, "_github_oauth_token_is_valid returned %s, expected False" % result
Ejemplo n.º 45
0
    def test_build_composer_environment_sets_composer_env_vars(self):
        ctx = utils.FormattedDict(
            {
                "BUILD_DIR": "/tmp/build",
                "WEBDIR": "",
                "CACHE_DIR": "/tmp/cache",
                "LIBDIR": "lib",
                "TMPDIR": "/tmp",
                "PHP_VM": "php",
            }
        )

        write_config_stub = Dingus()

        with patches({"composer.extension.PHPComposerStrategy.write_config": write_config_stub}):

            self.extension_module.ComposerExtension(ctx)
            cr = self.extension_module.ComposerCommandRunner(ctx, None)

            built_environment = cr._build_composer_environment()

        assert "COMPOSER_VENDOR_DIR" in built_environment, "Expect to find COMPOSER_VENDOR_DIR in built_environment"
        assert "COMPOSER_BIN_DIR" in built_environment, "Expect to find COMPOSER_BIN_DIR in built_environment"
        assert "COMPOSER_CACHE_DIR" in built_environment, "Expect to find COMPOSER_CACHE_DIR in built_environment"
Ejemplo n.º 46
0
    def test_build_composer_environment_converts_vars_to_str(self):
        ctx = utils.FormattedDict(
            {
                "BUILD_DIR": "/usr/awesome",
                "WEBDIR": "",
                "PHP_VM": "php",
                "TMPDIR": "tmp",
                "LIBDIR": "lib",
                "CACHE_DIR": "cache",
                "PHPRC": "/usr/awesome/phpini",
                "MY_DICTIONARY": {"KEY": "VALUE"},
            }
        )

        write_config_stub = Dingus()

        with patches({"composer.extension.PHPComposerStrategy.write_config": write_config_stub}):
            self.extension_module.ComposerExtension(ctx)
            cr = self.extension_module.ComposerCommandRunner(ctx, None)

            built_environment = cr._build_composer_environment()

        for key, val in built_environment.iteritems():
            assert type(val) == str, "Expected [%s]:[%s] to be type `str`, but found type [%s]" % (key, val, type(val))