Ejemplo n.º 1
0
    def setUp(self):
        self.universal_config = UniversalConfig()
        self.project_config = BaseProjectConfig(
            self.universal_config, config={"noyaml": True}
        )
        self.project_config.config["services"] = {
            "connected_app": {"attributes": {"test": {"required": True}}},
            "github": {"attributes": {"git": {"required": True}, "password": {}}},
            "not_configured": {"attributes": {"foo": {"required": True}}},
        }
        self.project_config.project__name = "TestProject"
        self.project_name = "TestProject"
        self.org_config = OrgConfig({"foo": "bar"}, "test")
        self.scratch_org_config = ScratchOrgConfig(
            {"foo": "bar", "scratch": True}, "test_scratch"
        )
        self.services = {
            "connected_app": ServiceConfig({"test": "value"}),
            "github": ServiceConfig({"git": "hub"}),
        }
        self.key = "0123456789123456"

        self._mk_temp_home()
        self._home_patch = mock.patch(
            "pathlib.Path.home", return_value=Path(self.tempdir_home)
        )
        self._home_patch.__enter__()
        self._mk_temp_project()
        os.chdir(self.tempdir_project)
Ejemplo n.º 2
0
    def setUp(self):
        self.global_config = BaseGlobalConfig()
        self.project_config = BaseProjectConfig(self.global_config)
        self.project_config.config["services"] = {
            "connected_app": {
                "attributes": {
                    "test": {
                        "required": True
                    }
                }
            },
            "github": {
                "attributes": {
                    "git": {
                        "required": True
                    },
                    "password": {}
                }
            },
            "mrbelvedere": {
                "attributes": {
                    "mr": {
                        "required": True
                    }
                }
            },
            "not_configured": {
                "attributes": {
                    "foo": {
                        "required": True
                    }
                }
            },
        }
        self.project_config.project__name = "TestProject"
        self.project_name = "TestProject"
        self.org_config = OrgConfig({"foo": "bar"}, "test")
        self.scratch_org_config = ScratchOrgConfig(
            {
                "foo": "bar",
                "scratch": True
            }, "test_scratch")
        self.services = {
            "connected_app": ServiceConfig({"test": "value"}),
            "github": ServiceConfig({"git": "hub"}),
            "mrbelvedere": ServiceConfig({"mr": "belvedere"}),
        }
        self.key = "0123456789123456"

        self._mk_temp_home()
        self._expanduser_patch = mock.patch("os.path.expanduser",
                                            return_value=self.tempdir_home)
        self._expanduser_patch.__enter__()
        self._mk_temp_project()
        os.chdir(self.tempdir_project)
Ejemplo n.º 3
0
 def setUp(self):
     self.global_config = BaseGlobalConfig()
     self.project_config = BaseProjectConfig(self.global_config)
     self.connected_app_config = ConnectedAppOAuthConfig({'test': 'value'})
     self.services = {
         'github': ServiceConfig({'git': 'hub'}),
         'mrbelvedere': ServiceConfig({'mr': 'belvedere'}),
         'apextestsdb': ServiceConfig({'apex': 'testsdb'}),
     }
     self.org_config = OrgConfig({'foo': 'bar'})
     self.key = '0123456789123456'
Ejemplo n.º 4
0
 def setUp(self):
     self.global_config = BaseGlobalConfig()
     self.project_config = BaseProjectConfig(self.global_config,
                                             config={"no_yaml": True})
     self.project_config.config["services"] = {
         "connected_app": {
             "attributes": {
                 "test": {
                     "required": True
                 }
             }
         },
         "github": {
             "attributes": {
                 "name": {
                     "required": True
                 },
                 "password": {}
             }
         },
         "mrbelvedere": {
             "attributes": {
                 "mr": {
                     "required": True
                 }
             }
         },
         "not_configured": {
             "attributes": {
                 "foo": {
                     "required": True
                 }
             }
         },
     }
     self.project_config.project__name = "TestProject"
     self.services = {
         "connected_app": ServiceConfig({"test": "value"}),
         "github": ServiceConfig({"name": "hub"}),
         "mrbelvedere": ServiceConfig({"mr": "belvedere"}),
     }
     self.org_config = OrgConfig({"foo": "bar"}, "test")
     self.scratch_org_config = ScratchOrgConfig(
         {
             "foo": "bar",
             "scratch": True
         }, "test_scratch")
     self.key = "0123456789123456"
Ejemplo n.º 5
0
 def setUp(self):
     self.global_config = BaseGlobalConfig()
     self.project_config = BaseProjectConfig(self.global_config)
     self.project_config.config['services'] = {
         'connected_app': {
             'attributes': {
                 'test': {
                     'required': True
                 }
             }
         },
         'github': {
             'attributes': {
                 'git': {
                     'required': True
                 },
                 'password': {}
             }
         },
         'mrbelvedere': {
             'attributes': {
                 'mr': {
                     'required': True
                 }
             }
         },
         'not_configured': {
             'attributes': {
                 'foo': {
                     'required': True
                 }
             }
         },
     }
     self.project_config.project__name = 'TestProject'
     self.project_name = 'TestProject'
     self.org_config = OrgConfig({'foo': 'bar'}, 'test')
     self.scratch_org_config = ScratchOrgConfig(
         {
             'foo': 'bar',
             'scratch': True
         }, 'test_scratch')
     self.services = {
         'connected_app': ServiceConfig({'test': 'value'}),
         'github': ServiceConfig({'git': 'hub'}),
         'mrbelvedere': ServiceConfig({'mr': 'belvedere'}),
     }
     self.key = '0123456789123456'
Ejemplo n.º 6
0
 def test_init_task__named_plan(self):
     project_config = create_project_config()
     project_config.config["project"]["git"]["repo_url"] = "EXISTING_REPO"
     expected_plans = {
         "install": {
             "title": "Test Install",
             "slug": "install",
             "tier": "primary",
             "steps": {
                 1: {
                     "flow": "install_prod"
                 }
             },
         }
     }
     project_config.config["plans"] = expected_plans
     project_config.keychain.set_service(
         "metadeploy",
         ServiceConfig({
             "url": "https://metadeploy",
             "token": "TOKEN"
         }))
     task_config = TaskConfig(
         {"options": {
             "tag": "release/1.0",
             "plan": "install"
         }})
     task = Publish(project_config, task_config)
     task._init_task()
     self.assertEqual(expected_plans, task.plan_configs)
Ejemplo n.º 7
0
    def test_call_api__collect_pages(self):
        responses.add(
            "GET",
            "https://metadeploy/rest",
            json={
                "data": [1],
                "links": {
                    "next": "https://metadeploy/rest?page=2"
                }
            },
        )
        responses.add(
            "GET",
            "https://metadeploy/rest",
            json={
                "data": [2],
                "links": {
                    "next": None
                }
            },
        )

        project_config = create_project_config()
        project_config.keychain.set_service(
            "metadeploy",
            ServiceConfig({
                "url": "https://metadeploy",
                "token": "TOKEN"
            }))
        task_config = TaskConfig()
        task = BaseMetaDeployTask(project_config, task_config)
        task._init_task()
        results = task._call_api("GET", "/rest", collect_pages=True)
        self.assertEqual([1, 2], results)
Ejemplo n.º 8
0
    def test_find_or_create_version__already_exists(self):
        responses.add(
            "GET",
            "https://metadeploy/versions?product=abcdef&label=1.0",
            json={"data": [{
                "url": "http://EXISTING_VERSION"
            }]},
        )

        project_config = create_project_config()
        project_config.keychain.set_service(
            "metadeploy",
            ServiceConfig({
                "url": "https://metadeploy",
                "token": "TOKEN"
            }))
        task_config = TaskConfig({
            "options": {
                "flow": "install_prod",
                "product_id": "abcdef",
                "tag": "release/1.0",
                "title": "Test Product",
                "slug": "test",
                "tier": "primary",
            }
        })
        task = Publish(project_config, task_config)
        task._init_task()
        version = task._find_or_create_version()
        self.assertEqual("http://EXISTING_VERSION", version["url"])
Ejemplo n.º 9
0
    def test_choose_devhub(self, Command):
        mock_keychain = mock.Mock()
        mock_keychain.get_service.return_value = ServiceConfig(
            {"username": "******"})
        config = ScratchOrgConfig({}, "test", mock_keychain)

        assert config._choose_devhub() == "*****@*****.**"
Ejemplo n.º 10
0
 def _load_keychain_services(self):
     for key, value in settings.__dict__["_wrapped"].__dict__.items():
         if key.startswith("CUMULUSCI_SERVICE_"):
             print("%%% DEBUG %%%: {}".format(
                 key[len("CUMULUSCI_SERVICE_"):]))
             self.services[key[len("CUMULUSCI_SERVICE_"):]] = ServiceConfig(
                 json.loads(value))
Ejemplo n.º 11
0
 def get_service(self, service_name):
     try:
         service = Service.objects.get(name=service_name)
         service_config = json.loads(service.json)
         return ServiceConfig(service_config)
     except Service.DoesNotExist:
         raise ServiceNotConfigured(service_name)
Ejemplo n.º 12
0
        def callback(*args, **kwargs):
            if config.is_global_keychain:
                project = False
            else:
                project = kwargs.pop("project", False)
            serv_conf = dict((k, v) for k, v in list(kwargs.items())
                             if v is not None)  # remove None values

            # A service can define a callable to validate the service config
            validator_path = service_config.get("validator")
            if validator_path:
                validator = import_global(validator_path)
                try:
                    validator(serv_conf)
                except Exception as e:
                    raise click.UsageError(str(e))

            config.keychain.set_service(name, ServiceConfig(serv_conf),
                                        project)
            if project:
                click.echo(
                    "{0} is now configured for this project.".format(name))
            else:
                click.echo(
                    "{0} is now configured for all CumulusCI projects.".format(
                        name))
Ejemplo n.º 13
0
    def test_run_task__commit_not_found(self):
        self.init_github()
        responses.add(
            method=responses.GET,
            url=self.repo_api_url,
            json=self._get_expected_repo("TestOwner", "TestRepo"),
        )
        responses.add(method=responses.GET,
                      url=f"{self.repo_api_url}/commits/abcdef",
                      status=404)

        project_config = create_project_config(repo_commit="abcdef")
        project_config.keychain.set_service(
            "github",
            ServiceConfig({
                "username": "******",
                "token": "TestPass",
                "email": "*****@*****.**",
            }),
        )
        task_config = TaskConfig({"options": {"context": "2gp"}})
        org_config = OrgConfig(
            {
                "instance_url": "https://salesforce",
                "access_token": "TOKEN"
            }, "test")
        task = GetPackageDataFromCommitStatus(project_config, task_config,
                                              org_config)
        task._init_task()
        with pytest.raises(DependencyLookupError,
                           match="Could not find commit abcdef on github"):
            task._run_task()
Ejemplo n.º 14
0
    def test_get_dependencies__version_not_found(self):
        responses.add(
            "GET",
            "https://salesforce/services/data/v50.0/tooling/query/",
            json={"records": []},
        )

        project_config = create_project_config(repo_commit="abcdef")
        project_config.keychain.set_service(
            "github",
            ServiceConfig({
                "username": "******",
                "token": "TestPass",
                "email": "*****@*****.**",
            }),
        )
        task_config = TaskConfig({"options": {"context": "2gp"}})
        org_config = OrgConfig(
            {
                "instance_url": "https://salesforce",
                "access_token": "TOKEN"
            }, "test")
        task = GetPackageDataFromCommitStatus(project_config, task_config,
                                              org_config)
        task._init_task()
        with pytest.raises(DependencyLookupError,
                           match="Could not look up dependencies of 04t"):
            task._get_dependencies("04t")
Ejemplo n.º 15
0
    def test_find_or_create_version__commit(self):
        responses.add(
            "GET",
            "https://metadeploy/versions?product=abcdef&label=abcdef",
            json={"data": [{"url": "http://EXISTING_VERSION"}]},
        )

        project_config = create_project_config()
        project_config.config["project"]["git"]["repo_url"] = "EXISTING_REPO"
        project_config.config["plans"] = {
            "install": {
                "title": "Test Install",
                "slug": "install",
                "tier": "primary",
                "steps": {1: {"flow": "install_prod"}},
            }
        }
        project_config.keychain.set_service(
            "metadeploy", ServiceConfig({"url": "https://metadeploy", "token": "TOKEN"})
        )
        task_config = TaskConfig({"options": {"commit": "abcdef"}})
        task = Publish(project_config, task_config)
        task._init_task()
        version = task._find_or_create_version(
            {"url": "http://EXISTING_PRODUCT", "id": "abcdef"}
        )
        self.assertEqual("http://EXISTING_VERSION", version["url"])
Ejemplo n.º 16
0
 def setUp(self):
     global_config = BaseGlobalConfig()
     self.project_config = BaseProjectConfig(global_config,
                                             config=global_config.config)
     self.project_config.config["project"]["package"]["namespace"] = "npsp"
     self.project_config.config["project"]["dependencies"] = [
         {
             "namespace": "nochangedep",
             "version": "1.0"
         },
         {
             "namespace": "changedep",
             "version": "1.1"
         },
     ]
     keychain = BaseProjectKeychain(self.project_config, "")
     keychain.set_service(
         "mrbelvedere",
         ServiceConfig({
             "base_url": "http://mrbelvedere",
             "api_key": "1234"
         }),
     )
     self.project_config.set_keychain(keychain)
     self.task_config = TaskConfig({"options": {"tag": "beta/1.0-Beta_2"}})
Ejemplo n.º 17
0
def site_connect(config, app_name):
    verify_overwrite(config)

    if not app_name:
        click.echo()
        click.echo(click.style('# Heroku App?', bold=True, fg='blue'))
        click.echo('Are you connecting to an instance of MetaCI running on Heroku?')
        if click.confirm('Heroku App?', default=True):
            app_name = click.prompt('Heroku App Name')

    default_url = None
    if app_name:
        default_url = 'https://{}.herokuapp.com'.format(app_name)
    url = click.prompt('Site Base URL', default=default_url)

    click.echo('Contact your MetaCI administrator to get an API Token.  Tokens can be created by administrators in the admin panel under Auth Tokens -> Tokensi.')
    click.echo(click.style(
        'NOTE: For security purposes, your input will be hidden.  Paste your API Token and hit Enter to continue.',
        fg='yellow',
    ))
    token = click.prompt('API Token', hide_input=True)
    service = ServiceConfig({
        'app_name': app_name,
        'url': url,
        'token': token,
    })
    config.keychain.set_service('metaci', service)
Ejemplo n.º 18
0
 def callback(ctx,project=False,*args, **kwargs):
     check_keychain(config)
     serv_conf = dict((k, v) for k, v in kwargs.iteritems() if v!=None) # remove None values
     config.keychain.set_service(name, ServiceConfig(serv_conf), project)
     if project:
         click.echo('{0} is now configured for this project'.format(name))
     else:
         click.echo('{0} is now configured for global use'.format(name))
Ejemplo n.º 19
0
 def setUp(self):
     self.global_config = BaseGlobalConfig()
     self.project_config = BaseProjectConfig(self.global_config)
     self.project_config.config['services'] = {
         'github':{'attributes':{'name':{'required':True}, 'password':{}}},
         'mrbelvedere':{'attributes':{'mr':{'required':True}}},
         'apextestsdb':{'attributes':{'apex':{'required':True}}},
     }
     self.project_config.project__name = 'TestProject'
     self.connected_app_config = ConnectedAppOAuthConfig({'test': 'value'})
     self.services = {
         'github': ServiceConfig({'name': 'hub'}),
         'mrbelvedere': ServiceConfig({'mr': 'belvedere'}),
         'apextestsdb': ServiceConfig({'apex': 'testsdb'}),
     }
     self.org_config = OrgConfig({'foo': 'bar'})
     self.key = '0123456789123456'
Ejemplo n.º 20
0
    def test_connected_app_client_name(self):
        self.project_config.keychain.set_service(
            "connectedapp", ServiceConfig({"client_id": "test123"}))

        task = BaseSalesforceApiTask(self.project_config, self.task_config,
                                     self.org_config)
        self.assertIn("Sforce-Call-Options", task.sf.headers)
        self.assertNotIn("CumulusCI/", task.sf.headers["Sforce-Call-Options"])
        self.assertIn("test123", task.sf.headers["Sforce-Call-Options"])
Ejemplo n.º 21
0
 def _connect_service(self):
     self.project_config.keychain.set_service(
         "connected_app",
         ServiceConfig({
             "client_id": self.client_id,
             "client_secret": self.client_secret,
             "callback_url": "http://localhost:8080/callback",
         }),
     )
Ejemplo n.º 22
0
 def test_init_task__no_tag_or_commit(self):
     project_config = create_project_config()
     project_config.keychain.set_service(
         "metadeploy", ServiceConfig({"url": "https://metadeploy", "token": "TOKEN"})
     )
     task_config = TaskConfig({"options": {}})
     task = Publish(project_config, task_config)
     with self.assertRaises(TaskOptionsError):
         task._init_task()
Ejemplo n.º 23
0
 def callback(project=False, *args, **kwargs):
     serv_conf = dict((k, v) for k, v in list(kwargs.items())
                      if v != None)  # remove None values
     config.keychain.set_service(name, ServiceConfig(serv_conf),
                                 project)
     if project:
         click.echo(
             "{0} is now configured for this project".format(name))
     else:
         click.echo("{0} is now configured for global use".format(name))
Ejemplo n.º 24
0
def project_connect_saucelabs(config, username, api_key, project):
    check_keychain(config)
    config.keychain.set_service('saucelabs', ServiceConfig({
        'username': username,
        'api_key': api_key,
    }), project)
    if project:
        click.echo('Saucelabs is now configured for this project')
    else:
        click.echo('Saucelabs is now configured for global use')
Ejemplo n.º 25
0
def project_connect_mrbelvedere(config, base_url, api_key, project):
    check_keychain(config)
    config.keychain.set_service('mrbelvedere', ServiceConfig({
        'base_url': base_url,
        'api_key': api_key,
    }), project)
    if project:
        click.echo('MrBelvedere is now configured for this project')
    else:
        click.echo('MrBelvedere is now configured for global use')
Ejemplo n.º 26
0
def project_connect_github(config, username, password, email, project):
    check_keychain(config)
    config.keychain.set_service('github', ServiceConfig({
        'username': username,
        'password': password,
        'email': email,
    }), project)
    if project:
        click.echo('Github is now configured for this project')
    else:
        click.echo('Github is now configured for global use')
Ejemplo n.º 27
0
 def project_config(self):
     project_config = create_project_config()
     project_config.keychain.set_service(
         "github",
         ServiceConfig({
             "username": "******",
             "password": "******",
             "email": "*****@*****.**",
         }),
     )
     return project_config
Ejemplo n.º 28
0
def project_connect_apextestsdb(config, base_url, user_id, token, project):
    check_keychain(config)
    config.keychain.set_service('apextestsdb', ServiceConfig({
        'base_url': base_url,
        'user_id': user_id,
        'token': token,
    }), project)
    if project:
        click.echo('ApexTestsDB is now configured for this project')
    else:
        click.echo('ApexTestsDB is now configured for global use')
Ejemplo n.º 29
0
 def test_init_options_email_default(self):
     """ email option defaults to email from github service """
     del self.task_config.config["options"]["email"]
     self.project_config.config["services"] = {
         "github": {"attributes": {"email": {}}}
     }
     self.project_config.keychain.set_service(
         "github", ServiceConfig({"email": self.email}), True
     )
     task = CreateConnectedApp(self.project_config, self.task_config)
     self.assertEqual(task.options["email"], self.email)
Ejemplo n.º 30
0
    def test_call_api__400(self):
        responses.add("GET", "https://metadeploy/rest", status=400, body=b"message")

        project_config = create_project_config()
        project_config.keychain.set_service(
            "metadeploy", ServiceConfig({"url": "https://metadeploy", "token": "TOKEN"})
        )
        task_config = TaskConfig()
        task = BaseMetaDeployTask(project_config, task_config)
        task._init_task()
        with self.assertRaises(requests.exceptions.HTTPError):
            task._call_api("GET", "/rest")