Ejemplo n.º 1
0
 def test_save_account_specified_provider_invalid(self):
     """Test saving an account without specifying all the hub/group/project fields."""
     invalid_hgps_to_save = [HubGroupProject('', 'default_group', ''),
                             HubGroupProject('default_hub', None, 'default_project')]
     for invalid_hgp in invalid_hgps_to_save:
         with self.subTest(invalid_hgp=invalid_hgp), custom_qiskitrc():
             with self.assertRaises(IBMQAccountValueError) as context_manager:
                 self.factory.save_account(token=self.token, url=AUTH_URL,
                                           hub=invalid_hgp.hub,
                                           group=invalid_hgp.group,
                                           project=invalid_hgp.project)
             self.assertIn('The hub, group, and project parameters must all be specified',
                           str(context_manager.exception))
Ejemplo n.º 2
0
    def test_save_account_specified_provider(self):
        """Test saving an account with a specified provider."""
        default_hgp_to_save = 'default_hub/default_group/default_project'

        with custom_qiskitrc() as custom_qiskitrc_cm:
            hgp = HubGroupProject.from_stored_format(default_hgp_to_save)
            self.factory.save_account(token=self.token,
                                      url=AUTH_URL,
                                      hub=hgp.hub,
                                      group=hgp.group,
                                      project=hgp.project)

            # Ensure the `default_provider` name was written to the config file.
            config_parser = ConfigParser()
            try:
                config_parser.read(custom_qiskitrc_cm.tmp_file.name)
            except ParsingError as ex:
                self.log.warning(
                    'There was an issue parsing the custom_qiskitrc file: %s',
                    str(ex))

            for name in config_parser.sections():
                single_credentials = dict(config_parser.items(name))
                self.assertIn('default_provider', single_credentials)
                self.assertEqual(single_credentials['default_provider'],
                                 default_hgp_to_save)
Ejemplo n.º 3
0
    def test_load_account_saved_provider_invalid_hgp(self, qe_token, qe_url):
        """Test loading an account that contains a saved provider that does not exist."""
        if qe_url != QX_AUTH_URL:
            # .save_account() expects an auth production URL.
            self.skipTest('Test requires production auth URL')

        # Hub, group, project in correct format but does not exists.
        invalid_hgp_to_store = 'invalid_hub/invalid_group/invalid_project'
        with custom_qiskitrc(), no_envs(CREDENTIAL_ENV_VARS):
            hgp = HubGroupProject.from_stored_format(invalid_hgp_to_store)
            self.factory.save_account(token=qe_token, url=qe_url,
                                      hub=hgp.hub, group=hgp.group, project=hgp.project)
            with self.assertRaises(IBMQAccountError) as context_manager:
                self.factory.load_account()
            self.assertIn('(hub/group/project) stored on disk could not be found',
                          str(context_manager.exception))