Exemple #1
0
    def tearDown(self):
        try:
            del os.environ['APP_SERVER_ENV']
        except KeyError:
            pass

        Context().reset()
Exemple #2
0
    def test_server_env_not_prod(self):
        os.environ['APP_SERVER_ENV'] = Context.LOCAL
        self.assertTrue(tinyAPI.env_not_prod())

        Context().reset()

        os.environ['APP_SERVER_ENV'] = Context.STAGING
        self.assertTrue(tinyAPI.env_not_prod())

        Context().reset()

        os.environ['APP_SERVER_ENV'] = Context.QA
        self.assertTrue(tinyAPI.env_not_prod())

        Context().reset()

        os.environ['APP_SERVER_ENV'] = Context.PRODUCTION
        self.assertFalse(tinyAPI.env_not_prod())
Exemple #3
0
    def test_context_exceptions(self):
        try:
            Context().get_server_env()

            this.fail('Was able to get server environment even though one was '
                      + 'not set.')
        except ContextException as e:
            self.assertEqual(
                'could not find environment variable called "APP_SERVER_ENV"',
                e.get_message())

        os.environ['APP_SERVER_ENV'] = 'invalid'

        try:
            Context().get_server_env()

            this.fail('Was able to get server environment even though the '
                      + 'value that was set was invalid.')
        except ContextException as e:
            self.assertEqual(
                'application server environment "invalid" is not valid',
                e.get_message())
Exemple #4
0
    def test_context_exceptions(self):
        try:
            Context().get_server_env()

            this.fail('Was able to get server environment even though one was '
                      + 'not set.')
        except ContextException as e:
            self.assertEqual(
                'could not find environment variable "APP_SERVER_ENV"',
                e.get_message())

        os.environ['APP_SERVER_ENV'] = 'invalid'

        try:
            Context().get_server_env()

            this.fail('Was able to get server environment even though the '
                      + 'value that was set was invalid.')
        except ContextException as e:
            self.assertEqual(
                'application server environment "invalid" is not valid',
                e.get_message())

        os.environ['APP_SERVER_ENV'] = 'staging'
        os.environ['APP_SERVER_DOMAIN'] = 'invalid'

        try:
            Context().get_server_domain()

            this.fail('Was able to get server environment even though the '
                      + 'domain provided was invalid.')
        except ContextException as e:
            self.assertEqual(
                'unrecognized server domain "invalid"',
                e.get_message()
            )
Exemple #5
0
def cli_main(function, args=None, stop_on_signal=True):
    '''Executes the "main" CLI function passing in the configured arguments.'''
    if stop_on_signal and os.path.isfile(CLI_STOP_SIGNAL_FILE):
        raise CLIException('CLI execution has been stopped')

    Context().set_cli()

    cli = CLI(args)
    if not stop_on_signal:
        cli.dont_stop_on_signal()

    try:
        function(cli)
    except Exception as e:
        _handle_cli_exception_logging(e)

        cli.set_status_error()
        tinyAPI.dsh().rollback(True)
        tinyAPI.dsh().close()

        raise
Exemple #6
0
                          str(self.__total_run_time))


class TransactionalDataStoreTestCase(unittest.TestCase):
    '''Provides a test case for transactional data stores that rolls back
       changes after each unit test.'''
    def setUp(self):
        default_schema = ConfigManager.value('default schema')
        default_connection = ConfigManager.value(
            'default unit test connection')
        if default_schema and default_connection:
            tinyAPI.dsh.select_db(default_connection, default_schema)

        self.maxDiff = None
        self.set_up()

    def set_up(self):
        pass

    def tearDown(self):
        self.tear_down()
        tinyAPI.dsh().rollback(True)

    def tear_down(self):
        pass


# ----- Instructions ----------------------------------------------------------

Context().set_unit_test()
Exemple #7
0
 def test_getting_server_domain(self):
     os.environ['APP_SERVER_DOMAIN'] = Context.DEMO
     self.assertEqual(Context.DEMO, Context().get_server_domain())
Exemple #8
0
 def test_getting_server_env(self):
     os.environ['APP_SERVER_ENV'] = Context.LOCAL
     self.assertEqual(Context.LOCAL, Context().get_server_env())
Exemple #9
0
 def test_unit_test(self):
     Context().set_unit_test()
     self.assertTrue(Context().is_unit_test())
Exemple #10
0
 def test_web(self):
     Context().set_web()
     self.assertTrue(Context().is_web())
Exemple #11
0
 def test_cli(self):
     Context().set_cli()
     self.assertTrue(Context().is_cli())