Skip to content

Commit 28b00ac

Browse files
committed
Merge pull request #70 from ohumbel/credentials
enable RTC credentials on the command line
2 parents 8f7d017 + f5e74c8 commit 28b00ac

6 files changed

Lines changed: 60 additions & 7 deletions

File tree

configuration.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
config = None
1010
configfile = None
11+
user = None
12+
password = None
1113

1214

1315
def read(configname=None):
@@ -19,8 +21,12 @@ def read(configname=None):
1921
generalsection = parsedconfig['General']
2022
migrationsection = parsedconfig['Migration']
2123
miscsectionname = 'Miscellaneous'
22-
user = generalsection['User']
23-
password = generalsection['Password']
24+
global user
25+
if not user:
26+
user = generalsection['User']
27+
global password
28+
if not password:
29+
password = generalsection['Password']
2430
repositoryurl = generalsection['Repo']
2531
scmcommand = generalsection.get('ScmCommand', "lscm")
2632
shell.logcommands = parsedconfig.get(miscsectionname, 'LogShellCommands', fallback="False") == "True"
@@ -68,6 +74,16 @@ def setconfigfile(newconfigfile):
6874
configfile = newconfigfile
6975

7076

77+
def setUser(newuser):
78+
global user
79+
user = newuser
80+
81+
82+
def setPassword(newpassword):
83+
global password
84+
password = newpassword
85+
86+
7187
def getinitialcomponentbaselines(definedbaselines):
7288
initialcomponentbaselines = []
7389
if definedbaselines:

migration.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,12 @@ def parsecommandline():
112112
configfilehelp = 'name of the config file, or full path to the config file; defaults to ' + configfiledefault
113113
parser.add_argument('-c', '--configfile', metavar='file', dest='configfile', help=configfilehelp,
114114
default=configfiledefault)
115+
parser.add_argument('-u', '--user', metavar='user', dest='user', help='RTC user', default=None)
116+
parser.add_argument('-p', '--password', metavar='password', dest='password', help='RTC password', default=None)
115117
arguments = parser.parse_args()
116118
configuration.setconfigfile(arguments.configfile)
119+
configuration.setUser(arguments.user)
120+
configuration.setPassword(arguments.password)
117121

118122

119123
def validate():

tests/test_configuration.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ def setUp(self):
1414
# reset global shell variables
1515
shell.logcommands = False
1616
shell.encoding = None
17+
configuration.setconfigfile(None)
18+
configuration.setUser(None)
19+
configuration.setPassword(None)
1720

1821
def test_DeletionOfFolder(self):
1922
config = Builder().setworkdirectory(self.workdirectory).build()
@@ -66,6 +69,12 @@ def test_fileExtensionsToBeIgnored_MultipleExtensions(self):
6669
def test_read_passedin_configfile(self):
6770
self._assertTestConfig(configuration.read(testhelper.getrelativefilename('resources/test_config.ini')))
6871

72+
def test_read_passedin_configfile_expect_override_user_password(self):
73+
configuration.setUser('newUser')
74+
configuration.setPassword('newPassword')
75+
self._assertTestConfig(configuration.read(testhelper.getrelativefilename('resources/test_config.ini')),
76+
user='newUser', password='newPassword')
77+
6978
def test_read_configfile_from_configuration(self):
7079
configuration.setconfigfile(testhelper.getrelativefilename('resources/test_config.ini'))
7180
self._assertTestConfig(configuration.read())
@@ -74,11 +83,17 @@ def test_read_minimumconfigfile_shouldrelyonfallbackvalues(self):
7483
configuration.setconfigfile(testhelper.getrelativefilename('resources/test_minimum_config.ini'))
7584
self._assertDefaultConfig(configuration.read())
7685

77-
def _assertTestConfig(self, config):
86+
def _assertTestConfig(self, config, user=None, password=None):
7887
# [General]
7988
self.assertEqual('https://rtc.supercompany.com/ccm/', config.repo)
80-
self.assertEqual('superuser', config.user)
81-
self.assertEqual('supersecret', config.password)
89+
if not user:
90+
self.assertEqual('superuser', config.user)
91+
else:
92+
self.assertEqual(user, config.user)
93+
if not password:
94+
self.assertEqual('supersecret', config.password)
95+
else:
96+
self.assertEqual(password, config.password)
8297
self.assertEqual('super.git', config.gitRepoName)
8398
self.assertEqual('Superworkspace', config.workspace)
8499
self.assertEqual('/tmp/migration', config.workDirectory)

tests/test_gitFunctions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def test_ExistingFileStartsWithLowerCase_RenameToUpperCase_ExpectGitRename(self)
3030
def assertGitStatusShowsIsRenamed(self):
3131
statusoutput = shell.getoutput("git status -z")
3232
modifier = statusoutput[0][0]
33-
self.assertEquals("R", modifier)
33+
self.assertEqual("R", modifier)
3434

3535
def test_ExistingFileStartsWithUpperCase_RenameToLowerCase_ExpectGitRename(self):
3636
with testhelper.createrepo(folderprefix="gitfunctionstestcase_"):

tests/test_migration.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,21 @@ def testParseCommandLine_expect_default_configfile(self):
5454
sys.argv = ['migration.py']
5555
migration.parsecommandline()
5656
self.assertEqual('config.ini', configuration.configfile)
57+
58+
def testParseCommandLine_expect_specified_user_password_shortoptions(self):
59+
sys.argv = ['migration.py', '-u', 'anyUser', '-p', 'anyPassword' ]
60+
migration.parsecommandline()
61+
self.assertEqual('anyUser', configuration.user)
62+
self.assertEqual('anyPassword', configuration.password)
63+
64+
def testParseCommandLine_expect_specified_user_password_longoptions(self):
65+
sys.argv = ['migration.py', '--user', 'anyUser', '--password', 'anyPassword' ]
66+
migration.parsecommandline()
67+
self.assertEqual('anyUser', configuration.user)
68+
self.assertEqual('anyPassword', configuration.password)
69+
70+
def testParseCommandLine_expect_no_user_password(self):
71+
sys.argv = ['migration.py']
72+
migration.parsecommandline()
73+
self.assertIsNone(configuration.user)
74+
self.assertIsNone(configuration.password)

tests/test_rtcFunctions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ def test_getnextchangeset_fromsamecomponent_expectsamecomponent(self):
360360
self.assertIsNotNone(nextentry)
361361
self.assertFalse(nextentry.isAccepted())
362362
self.assertEqual(component2, nextentry.component)
363-
self.assertEquals("2.3", nextentry.revision)
363+
self.assertEqual("2.3", nextentry.revision)
364364

365365
def test_getnextchangeset_fromsamecomponent_expectnonefound(self):
366366
component1 = "uuid_1"

0 commit comments

Comments
 (0)