def main(): defaults = backend.defaults('wight', 'log') defaults['log']['level'] = 'WARN' app = WightApp(config_defaults=defaults) app.register_controllers() bright_yellow = "%s%s" % (Fore.YELLOW, Style.BRIGHT) bright_magenta = "%s%s" % (Fore.MAGENTA, Style.BRIGHT) dim_red = "%s%s" % (Fore.RED, Style.DIM) dim_white = "%s%s" % (Fore.WHITE, Style.DIM) reset = "%s%s" % (Style.RESET_ALL, dim_white) try: app.setup() app.run() except UnauthenticatedError: print "\n%sYou need to be logged to use this command. Use '%swight login%s %s<user e-mail>%s%s' to login.%s\n" % ( dim_red, bright_yellow, reset, bright_magenta, reset, dim_red, reset) except TargetNotSetError: print "\n%sYou need to set the target to use wight. Use '%swight target-set%s %s<url of target>%s%s' to login.%s\n" % ( dim_red, bright_yellow, reset, bright_magenta, reset, dim_red, reset) finally: app.close()
def test_default_action_when_target_not_set(self, write_mock): self.expected = "" def assert_written(message): if message.strip() != "": self.expected = message write_mock.side_effect = assert_written wightApp = WightApp() ctrl = self.make_controller(AuthController, conf=self.fixture_for('test.conf'), app=wightApp) try: expect(ctrl.default()).to_be_false() assert False, "Should have called sys.exit(0)" except SystemExit: assert True expected = "You need to set the target to use wight. Use 'wight target-set <url of target>' to login." expect(self.expected).to_be_like(expected)
def setUp(self): super(TestWightApp, self).setUp() self.reset_backend() self.app = WightApp(argv=[], config_files=[])