示例#1
0
class HerokuReleaseTests(unittest.TestCase):

    def setUp(self):
        self.json_input = {'app': {'name': 'hulahoop'}}
        self.herokurelease = HerokuRelease(self.json_input)

    @patch("heroku_tools.heroku.call_api")
    @patch("heroku_tools.heroku.click.echo")
    @patch("heroku_tools.heroku.HerokuRelease")
    def test_get_latest_deployment(self, HerokuRelease, echo, call_api):
        """Test unpacking of Heroku API release JSON."""
        call_api.return_value = [{'description': 'Deploy'},
                                 {'description': 'Promote'}]
        self.herokurelease.get_latest_deployment('x')
        self.assertEqual(HerokuRelease.call_args,
                         call({'description': 'Deploy'}))

        #  If no Deploy or Promote description HerokuError will be raised
        from heroku_tools.heroku import HerokuError
        call_api.return_value = [{'description': 'Hulahoop'}]
        with self.assertRaises(HerokuError):
            self.herokurelease.get_latest_deployment('x')
            print echo.call_args

    @patch("requests.auth.HTTPBasicAuth")
    @patch("requests.get", side_effect=mock_get)
    def test_call_api(self, get, HTTPBasicAuth):

        """Test call_api function of heroku_tools"""

        HTTPBasicAuth.return_value = "authorized"
        from heroku_tools.heroku import call_api
        result = call_api('endpoint-%s', 'application', 'range_header')
        self.assertEqual(get.call_args, call('endpoint-application',
                                             auth='authorized',
                                             headers={'Range': 'range_header',
                                                      'Accept': 'application/vnd.heroku+json; version=3'}))
        self.assertEqual(result, [{u'created_at': u'2013-06-15T15:01:29Z',
                                   u'description': u'Initial release',
                                   u'app': {u'id': u'1b5d48f7-1863-4db4-a108-cc1f7928dacc',
                                            u'name': u'test_app'},
                                   u'updated_at': u'2013-06-15T15:01:29Z', u'slug': None,
                                   u'version': 1, u'user': {u'email': u'*****@*****.**',
                                                            u'id': u'f7ee12b5-4343-4bfc-aae4-195a392d913d'},
                                   u'id': u'c0d15ac3-4101-459d-8c68-ce02a662b068'},
                                  {u'created_at': u'2013-06-18T14:07:52Z', u'description': u'Deploy 99ed2b0',
                                   u'app': {u'id': u'1b5d48f7-1863-4db4-a108-cc1f7928dacc', u'name': u'test_app'},
                                   u'updated_at': u'2013-06-18T14:07:52Z', u'slug':
                                       {u'id': u'c15c01b2-6d41-443b-ba13-bf358fbc7821'}, u'version': 17,
                                   u'user': {u'email': u'*****@*****.**',
                                             u'id': u'f7ee12b5-4343-4bfc-aae4-195a392d913d'},
                                   u'id': u'2fa73c36-4b25-4797-b374-f1f3be994ff2'}])
示例#2
0
def configure_application(target_environment):
    """Configure Heroku application settings.

    Run a diff between local configuration and remote settings
    and apply any updates to the remote application:

    1. Load local configuration (from target_environment.conf)\n
    2. Fetch remote application config vars (via API)\n
    3. Compare the two\n
    4. Display the diff\n
    5. Prompt user for confirmation to apply updates\n
    6. Apply updates

    """
    app = AppConfiguration.load(
        os.path.join(SETTINGS['app_conf_dir'], '%s.conf' % target_environment)
    )
    app_name = app.app_name
    release = HerokuRelease.get_latest_deployment(app_name)
    diff = compare_settings(app.settings, release.get_config_vars())

    print u"\nLocal settings (diff shown by '!', '+' indicator):\n"
    print_diff(diff, statuses=['=', '+', '!'])

    print u"\nRemote-only settings (probably Heroku-specific and ignorable):\n"
    remote_only = [d[0] for d in diff if d[3] == '?']
    print u", ".join(remote_only)

    updates = [d for d in diff if d[3] in ['!', '+']]
    if len(updates) == 0:
        print u"\nAll settings are up-to-date. No action required."
        return

    print u"\nThe following settings will be applied to '%s':\n" % app_name
    for key, local, _, status in updates:
        print u"%s %s=%s" % (status, key, local)
    print u""

    print set_vars(app_name, updates)
示例#3
0
 def setUp(self):
     json_data = json.load(open('test_data/foo.json', 'r'))
     self.json_input = json_data[1]
     self.initial_release_json = json_data[0]
     self.herokurelease = HerokuRelease(self.json_input)
示例#4
0
class HerokuReleaseTests(unittest.TestCase):

    def setUp(self):
        json_data = json.load(open('test_data/foo.json', 'r'))
        self.json_input = json_data[1]
        self.initial_release_json = json_data[0]
        self.herokurelease = HerokuRelease(self.json_input)

    @patch("heroku_tools.heroku.call_api")
    @patch("heroku_tools.heroku.click.echo")
    @patch("heroku_tools.heroku.HerokuRelease")
    def test_get_latest_deployment(self, HerokuRelease, echo, call_api):
        """Test unpacking of Heroku API release JSON."""
        call_api.return_value = [{'description': 'Deploy'},
                                 {'description': 'Promote'}]
        self.herokurelease.get_latest_deployment('x')
        self.assertEqual(HerokuRelease.call_args,
                         call({'description': 'Deploy'}))

        #  If no Deploy or Promote description HerokuError will be raised
        from heroku_tools.heroku import HerokuError
        call_api.return_value = [{'description': 'Hulahoop'}]
        with self.assertRaises(HerokuError):
            self.herokurelease.get_latest_deployment('x')

    @patch("requests.auth.HTTPBasicAuth")
    @patch("requests.get", side_effect=mock_get)
    def test_call_api(self, get, HTTPBasicAuth):

        """Test call_api function of heroku_tools"""

        HTTPBasicAuth.return_value = "authorized"
        from heroku_tools.heroku import call_api
        result = call_api('endpoint-%s', 'application', 'range_header')
        self.assertEqual(get.call_args, call('endpoint-application',
                                             auth='authorized',
                                             headers={'Range': 'range_header',
                                                      'Accept': 'application/vnd.heroku+json; version=3'}))
        self.assertEqual(result, [{u'created_at': u'2013-06-15T15:01:29Z',
                                   u'description': u'Initial release',
                                   u'app': {u'id': u'1b5d48f7-1863-4db4-a108-cc1f7928dacc',
                                            u'name': u'test_app'},
                                   u'updated_at': u'2013-06-15T15:01:29Z', u'slug': None,
                                   u'version': 1, u'user': {u'email': u'*****@*****.**',
                                                            u'id': u'f7ee12b5-4343-4bfc-aae4-195a392d913d'},
                                   u'id': u'c0d15ac3-4101-459d-8c68-ce02a662b068'},
                                  {u'created_at': u'2013-06-18T14:07:52Z', u'description': u'Deploy 99ed2b0',
                                   u'app': {u'id': u'1b5d48f7-1863-4db4-a108-cc1f7928dacc', u'name': u'test_app'},
                                   u'updated_at': u'2013-06-18T14:07:52Z', u'slug':
                                       {u'id': u'c15c01b2-6d41-443b-ba13-bf358fbc7821'}, u'version': 17,
                                   u'user': {u'email': u'*****@*****.**',
                                             u'id': u'f7ee12b5-4343-4bfc-aae4-195a392d913d'},
                                   u'id': u'2fa73c36-4b25-4797-b374-f1f3be994ff2'}])

    @patch("heroku_tools.heroku.parser")
    def test_heroku_attributes(self, parser):
        for attribute in ('version', 'description'):
            self.assertEqual(getattr(self.herokurelease, attribute),
                             self.json_input[attribute])
        self.assertEqual(self.herokurelease.deployed_by,
                         self.json_input['user']['email'])
        parser.parse.return_value = '2013-06-18T14:07:52Z'
        self.assertEqual(self.json_input['updated_at'],
                         self.herokurelease.deployed_at)

    def test_commit(self):

        """Test for getting commit hash from description"""

        result = self.herokurelease.commit
        self.assertEqual(self.json_input['description'].split(' ')[1], result)
        initial_release = HerokuRelease(self.initial_release_json)
        self.assertEqual(initial_release.commit, 'invalid')
        deploy_json = self.json_input
        deploy_json["description"] = "Promote my-app v123 75c70c5"
        deploy = HerokuRelease(deploy_json)
        self.assertEqual(deploy.commit, '75c70c5')
示例#5
0
 def setUp(self):
     self.json_input = {'app': {'name': 'hulahoop'}}
     self.herokurelease = HerokuRelease(self.json_input)