def run(repodir, *args): """Wrap CLI invocation to prevent os.exit() from breaking unit testing""" conf_fname = os.path.join(repodir, 'firelet_test.ini') cli_args = ["-c %s" % conf_fname, "-r %s" % repodir] cli_args.extend(args) deb("running cli with arguments: %r", cli_args) oldrepodir = repodir cli.say.reset_history() deb(show('cli.main started')) assert_raises(SystemExit, cli.main, cli_args), "Exited without 0 or 1" deb("Output: %r", cli.say.hist()) assert oldrepodir == repodir return cli.say.output_history
def test_user_management(self, repodir): deb(show("started")) out1 = self.run(repodir, "-q", "user", "list") assert out1 == [ u"Ada admin None", u"Eddy editor None", u"Rob readonly None", ], ("Incorrect user list: %s" % repr(out1) + cli.say.hist()) out = self.run(repodir, "-q", "user", "add", "Totoro", "admin", "*****@*****.**") out2 = self.run(repodir, "-q", "user", "list") assert out2 == [ u"Ada admin None", u"Eddy editor None", u"Rob readonly None", u"Totoro admin [email protected]", ], ("Incorrect user list" + cli.say.hist()) self.run(repodir, "-q", "user", "validatepwd", "Totoro") self.run(repodir, "-q", "user", "del", "Totoro") out3 = self.run(repodir, "-q", "user", "list") assert out3 == out1, "User not deleted" + cli.say.hist()
def test_user_management(self, repodir): deb(show('started')) out1 = self.run(repodir, '-q', 'user', 'list') assert out1 == [ u'Ada admin None', u'Eddy editor None', u'Rob readonly None'], \ "Incorrect user list: %s" % repr(out1) + cli.say.hist() out = self.run(repodir, '-q', 'user', 'add', 'Totoro', 'admin', '*****@*****.**') out2 = self.run(repodir, '-q', 'user', 'list') assert out2 == [ u'Ada admin None', u'Eddy editor None', u'Rob readonly None', u'Totoro admin [email protected]'], \ "Incorrect user list" + cli.say.hist() self.run(repodir, '-q', 'user', 'validatepwd', 'Totoro') self.run(repodir, '-q', 'user', 'del', 'Totoro') out3 = self.run(repodir, '-q', 'user', 'list') assert out3 == out1, "User not deleted" + cli.say.hist()
def test_user_management(self, repodir): deb(show('started')) out1 = self.run(repodir, '-q', 'user', 'list') assert out1 == [ u'Rob readonly None', u'Eddy editor None', u'Ada admin None'], \ "Incorrect user list: %s" % repr(out1) + cli.say.hist() out = self.run(repodir, '-q', 'user', 'add', 'Totoro', 'admin', '*****@*****.**') out2 = self.run(repodir, '-q', 'user', 'list') assert out2 == [ u'Rob readonly None', u'Ada admin None', u'Eddy editor None', u'Totoro admin [email protected]'], \ "Incorrect user list" + cli.say.hist() self.run(repodir, '-q', 'user', 'validatepwd', 'Totoro') self.run(repodir, '-q', 'user', 'del', 'Totoro') out3 = self.run(repodir, '-q', 'user', 'list') assert out3 == out1, "User not deleted" + cli.say.hist()
def demofireset(repodir): "Testing is performed against the Demo FireSet" deb(show("Using %s as repodir" % repodir)) return DemoGitFireSet(repodir=repodir)
def test_versioning(self, repodir): deb(show('started')) self.run(repodir, 'save_needed', '-q') assert cli.say.output_history == [ 'No' ], "No save needed here" + cli.say.hist() self.run(repodir, 'version', 'list', '-q') # no versions assert cli.say.output_history == [], "No versions expected" + cli.say.hist( ) self.run(repodir, 'rule', 'disable', '2', '-q') assert cli.say.output_history == ['Rule 2 disabled.'] self.run(repodir, 'save_needed', '-q') assert cli.say.last == 'Yes', "Save needed" self.run(repodir, 'save', 'test1', '-q') # save 1 assert cli.say.output_history == [ 'Configuration saved. Message: "test1"' ] self.run(repodir, 'version', 'list', '-q') assert cli.say.last.endswith('| test1 |'), cli.say.hist() self.run(repodir, 'rule', 'enable', '2', '-q') assert cli.say.last == 'Rule 2 enabled.' self.run(repodir, 'save', 'test2', '-q') # save 2 assert cli.say.last == 'Configuration saved. Message: "test2"' self.run(repodir, 'version', 'list', '-q') assert len(cli.say.output_history) == 2 assert cli.say.output_history[0].endswith('| test2 |'), cli.say.hist() assert cli.say.output_history[1].endswith('| test1 |'), cli.say.hist() self.run(repodir, 'rule', 'disable', '2', '-q') assert cli.say.last == 'Rule 2 disabled.' self.run(repodir, 'save', 'test3', '-q') # save 1 assert cli.say.last == 'Configuration saved. Message: "test3"' self.run(repodir, 'version', 'list', '-q') assert len(cli.say.output_history) == 3 assert cli.say.output_history[0].endswith('| test3 |'), cli.say.hist() # rollback by number self.run(repodir, 'version', 'rollback', '1', '-q') self.run(repodir, 'version', 'list', '-q') assert len(cli.say.output_history) == 2 assert cli.say.output_history[0].endswith('| test2 |'), cli.say.hist() assert cli.say.output_history[1].endswith('| test1 |'), cli.say.hist() # rollback by ID - to a version where rule 2 was disabled commit_id = cli.say.output_history[1].split()[0] self.run(repodir, 'version', 'rollback', commit_id, '-q') self.run(repodir, 'version', 'list', '-q') assert cli.say.last.endswith( '| test1 |'), "Incorrect rollback" + cli.say.hist() # reset self.run(repodir, 'rule', 'enable', '2', '-q') assert cli.say.last == 'Rule 2 enabled.' self.run(repodir, 'save_needed', '-q') assert cli.say.last == 'Yes', "Save needed" self.run(repodir, 'reset', '-q') self.run(repodir, 'save_needed', '-q') assert cli.say.last == 'No', "Save not needed"
def test_versioning(self, repodir): deb(show('started')) self.run(repodir, 'save_needed', '-q') assert cli.say.output_history == ['No'], "No save needed here" + cli.say.hist() self.run(repodir, 'version', 'list', '-q') # no versions assert cli.say.output_history == [], "No versions expected" + cli.say.hist() self.run(repodir, 'rule', 'disable', '2', '-q') assert cli.say.output_history == ['Rule 2 disabled.'] self.run(repodir, 'save_needed', '-q') assert cli.say.last == 'Yes', "Save needed" self.run(repodir, 'save', 'test1', '-q') # save 1 assert cli.say.output_history == ['Configuration saved. Message: "test1"'] self.run(repodir, 'version', 'list', '-q') assert cli.say.last.endswith('| test1 |'), cli.say.hist() self.run(repodir, 'rule', 'enable', '2', '-q') assert cli.say.last == 'Rule 2 enabled.' self.run(repodir, 'save', 'test2', '-q') # save 2 assert cli.say.last == 'Configuration saved. Message: "test2"' self.run(repodir, 'version', 'list', '-q') assert len(cli.say.output_history) == 2 assert cli.say.output_history[0].endswith('| test2 |'), cli.say.hist() assert cli.say.output_history[1].endswith('| test1 |'), cli.say.hist() self.run(repodir, 'rule', 'disable', '2', '-q') assert cli.say.last == 'Rule 2 disabled.' self.run(repodir, 'save', 'test3', '-q') # save 1 assert cli.say.last == 'Configuration saved. Message: "test3"' self.run(repodir, 'version', 'list', '-q') assert len(cli.say.output_history) == 3 assert cli.say.output_history[0].endswith('| test3 |'), cli.say.hist() # rollback by number self.run(repodir, 'version', 'rollback', '1', '-q') self.run(repodir, 'version', 'list', '-q') assert len(cli.say.output_history) == 2 assert cli.say.output_history[0].endswith('| test2 |'), cli.say.hist() assert cli.say.output_history[1].endswith('| test1 |'), cli.say.hist() # rollback by ID - to a version where rule 2 was disabled commit_id = cli.say.output_history[1].split()[0] self.run(repodir, 'version', 'rollback', commit_id, '-q') self.run(repodir, 'version', 'list', '-q') assert cli.say.last.endswith('| test1 |'), "Incorrect rollback" + cli.say.hist() # reset self.run(repodir, 'rule', 'enable', '2', '-q') assert cli.say.last == 'Rule 2 enabled.' self.run(repodir, 'save_needed', '-q') assert cli.say.last == 'Yes', "Save needed" self.run(repodir, 'reset', '-q') self.run(repodir, 'save_needed', '-q') assert cli.say.last == 'No', "Save not needed"
def test_versioning(self, repodir): deb(show("started")) self.run(repodir, "save_needed", "-q") assert cli.say.output_history == ["No"], "No save needed here" + cli.say.hist() self.run(repodir, "version", "list", "-q") # no versions assert cli.say.output_history == [], "No versions expected" + cli.say.hist() self.run(repodir, "rule", "disable", "2", "-q") assert cli.say.output_history == ["Rule 2 disabled."] self.run(repodir, "save_needed", "-q") assert cli.say.last == "Yes", "Save needed" self.run(repodir, "save", "test1", "-q") # save 1 assert cli.say.output_history == ['Configuration saved. Message: "test1"'] self.run(repodir, "version", "list", "-q") assert cli.say.last.endswith("| test1 |"), cli.say.hist() self.run(repodir, "rule", "enable", "2", "-q") assert cli.say.last == "Rule 2 enabled." self.run(repodir, "save", "test2", "-q") # save 2 assert cli.say.last == 'Configuration saved. Message: "test2"' self.run(repodir, "version", "list", "-q") assert len(cli.say.output_history) == 2 assert cli.say.output_history[0].endswith("| test2 |"), cli.say.hist() assert cli.say.output_history[1].endswith("| test1 |"), cli.say.hist() self.run(repodir, "rule", "disable", "2", "-q") assert cli.say.last == "Rule 2 disabled." self.run(repodir, "save", "test3", "-q") # save 1 assert cli.say.last == 'Configuration saved. Message: "test3"' self.run(repodir, "version", "list", "-q") assert len(cli.say.output_history) == 3 assert cli.say.output_history[0].endswith("| test3 |"), cli.say.hist() # rollback by number self.run(repodir, "version", "rollback", "1", "-q") self.run(repodir, "version", "list", "-q") assert len(cli.say.output_history) == 2 assert cli.say.output_history[0].endswith("| test2 |"), cli.say.hist() assert cli.say.output_history[1].endswith("| test1 |"), cli.say.hist() # rollback by ID - to a version where rule 2 was disabled commit_id = cli.say.output_history[1].split()[0] self.run(repodir, "version", "rollback", commit_id, "-q") self.run(repodir, "version", "list", "-q") assert cli.say.last.endswith("| test1 |"), "Incorrect rollback" + cli.say.hist() # reset self.run(repodir, "rule", "enable", "2", "-q") assert cli.say.last == "Rule 2 enabled." self.run(repodir, "save_needed", "-q") assert cli.say.last == "Yes", "Save needed" self.run(repodir, "reset", "-q") self.run(repodir, "save_needed", "-q") assert cli.say.last == "No", "Save not needed"