14
14
# You should have received a copy of the GNU General Public License
15
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
18
"""Tests for finding and reading the bzr config file[s]."""
19
19
# import system imports here
425
428
locations = config.locations_config_filename()
426
429
config.ensure_config_dir_exists()
427
430
local_url = urlutils.local_path_to_url('branch')
428
open(locations, 'wb').write('[%s]\nnickname = foobar'
431
open(locations, 'wb').write('[%s]\nnickname = foobar'
430
433
self.assertEqual('foobar', branch.nick)
437
440
locations = config.locations_config_filename()
438
441
config.ensure_config_dir_exists()
439
open(locations, 'wb').write('[%s/branch]\nnickname = barry'
442
open(locations, 'wb').write('[%s/branch]\nnickname = barry'
440
443
% (osutils.getcwd().encode('utf8'),))
441
444
self.assertEqual('barry', branch.nick)
1427
1430
def test_set_credentials(self):
1428
1431
conf = config.AuthenticationConfig()
1429
1432
conf.set_credentials('name', 'host', 'user', 'scheme', 'password',
1430
99, path='/foo', verify_certificates=False)
1433
99, path='/foo', verify_certificates=False, realm='realm')
1431
1434
credentials = conf.get_credentials(host='host', scheme='scheme',
1432
port=99, path='/foo')
1435
port=99, path='/foo',
1433
1437
CREDENTIALS = {'name': 'name', 'user': 'user', 'password': 'password',
1434
'verify_certificates': False,}
1438
'verify_certificates': False, 'scheme': 'scheme',
1439
'host': 'host', 'port': 99, 'path': '/foo',
1435
1441
self.assertEqual(CREDENTIALS, credentials)
1436
1442
credentials_from_disk = config.AuthenticationConfig().get_credentials(
1437
host='host', scheme='scheme', port=99, path='/foo')
1443
host='host', scheme='scheme', port=99, path='/foo', realm='realm')
1438
1444
self.assertEqual(CREDENTIALS, credentials_from_disk)
1440
1446
def test_reset_credentials_different_name(self):
1444
1450
self.assertIs(None, conf._get_config().get('name'))
1445
1451
credentials = conf.get_credentials(host='host', scheme='scheme')
1446
1452
CREDENTIALS = {'name': 'name2', 'user': 'user2', 'password':
1447
'password', 'verify_certificates': True}
1453
'password', 'verify_certificates': True,
1454
'scheme': 'scheme', 'host': 'host', 'port': None,
1455
'path': None, 'realm': None}
1448
1456
self.assertEqual(CREDENTIALS, credentials)