示例#1
0
def main(args):
    initialize('mixerbot')
    if args['load']:
        return do_load(args)
    elif args['wipe']:
        return do_wipe(args)
    elif args['run']:
        return do_run(args)
def run_main():
    global global_args

    global_args = docopt(__doc__)

    # Parse stdin data if it exists and put it in args
    global_args['stdin'] = ''
    global_args['stdin_provided'] = not sys.stdin.isatty()
    if global_args['stdin_provided']:
        for line in sys.stdin:
            global_args['stdin'] += line
    global_args['stdin'] = global_args['stdin'].rstrip()

    # Enable full logging if user wants
    if global_args['--all-logs']:
        logging.basicConfig(stream=sys.stdout, level=1)

    # Connect to Zerp over the WAMP messagebus
    if global_args['--environment']:
        # Use the user defined environment
        if global_args['--debug']:
            print('Using env:', global_args['--environment'])
        initialize('izaber-wamp', environment=global_args['--environment'])
    else:
        # Use the default environment
        if global_args['--debug']:
            print('Using env: default')
        initialize('izaber-wamp')

    # Initialize the REPL
    repl = replPrompt()

    if global_args['call']:
        repl.do_call(''.join(global_args['<command>']))
        exit()

    if global_args['pub']:
        repl.do_pub(''.join(global_args['<command>']))
        exit()

    if global_args['sub']:
        repl.do_sub(''.join(global_args['<command>']))
        exit()

    # The cmdloop REPL freaks out for some reason when there is data provided in stdin
    # So we do not want to allow that
    if global_args['stdin_provided']:
        print('Cannot run REPL when stdin is provided')
        exit()

    try:
        # If there were no extra commands provided and there is no stdin then start the REPL
        repl.prompt = '> '
        repl.cmdloop('Starting WAMP CLI')
    except KeyboardInterrupt:
        print('Quitting')
        raise SystemExit
def test_connection():
    initialize('test', environment="live")

    zerp.hello(__file__,
               author="Aki",
               version="0.1a",
               description="testing errors in izaber-wamp-zerp")

    oo = zerp.get('product.product')
    assert oo

    search_results = oo.search([('active', '=', True)], limit=1)
    assert len(search_results) == 1

    data = oo.read(search_results, ['name', 'default_code'])
    assert data
#!/usr/bin/python

import unittest
import re

from izaber import config, initialize
from izaber.templates import parse
from izaber.email import mailer


class Test(unittest.TestCase):
    def test_email(self):
        parsed = mailer.template_parse('{{template_path}}/test.email')
        self.assertTrue(re.search('test email', parsed.as_string()))
        result = mailer.template_send('{{template_path}}/test.email')


if __name__ == '__main__':
    initialize(name='overlay_test', config='data/izaber.yaml')
    unittest.main()
示例#5
0
class Test(unittest.TestCase):
    def test_config(self):

        # Check that basic configuration options are being respected
        self.assertEqual(config.email.host, 'localhost')
        self.assertEqual(config.email.misc, '127.0.0.1')

        # Checks to see if the overlay is working
        self.assertEqual(config.email.explicit, 'done!')

        # Tests to see if the "config_amend" option is working
        self.assertEqual(config.test.this.thing, 'hi!')


config_amend = """
default:
    test:
        this:
            thing: 'hi!'
"""

if __name__ == '__main__':
    initialize(name='overlay_test',
               config={
                   'config_filename': 'data/izaber.yaml',
                   'config_amend': config_amend,
               },
               email={'explicit': 'done!'})
    unittest.main()
示例#6
0
#!/usr/bin/python

import unittest

from izaber import config, initialize
from izaber.templates import parse


def test_templates():
    match_str = u"Hello world!"
    result = parse("{{template_path}}/hello.html", test=match_str)
    assert result == match_str


initialize('test', config='data/izaber.yaml')
test_templates()
示例#7
0
#!/usr/bin/python

from izaber import initialize
from izaber.flask import app


@app.route('/')
def hello_world():
    return 'Hello, World!'


if __name__ == '__main__':
    initialize('example')
    print "Running"
    app.run()
示例#8
0
#!/usr/bin/python

from izaber import initialize
from izaber.paths import paths
from izaber.flask.wamp import IZaberFlask, wamp

app = IZaberFlask(__name__)

@app.route('/')
def hello_world():
    return 'Hello, World!'

@wamp.register('echo')
def echo(data):
    return data+" RESPONSE!"

@wamp.subscribe('hellos')
def hellos(data):
    print("Received subscribed message:", data.dump())

if __name__ == '__main__':
    initialize('example',environment='debug')
    print("Running")
    app.run()


示例#9
0
from izaber import initialize

# Note that we import module2 before module1, however, due to
# how the system allows initialization dependancies to be setup,
# module1's init will always be called before module2
import module2

from module1 import MYGLOBALVAR

# Now that all the initialization functions have been registered,
# this will initialize everything
initialize("example")

print("Initialization is done!")

# Let's see if we can use the global var
print(f"Found {len(MYGLOBALVAR.items())} items in module1")
示例#10
0
    authenticate_msg = AUTHENTICATE(
                            signature = 'password'
                        )
    authorized = ticket_auth.authenticate_challenge_response(
                                    mock_client,
                                    hello_msg,
                                    challenge_msg,
                                    authenticate_msg
                                )
    assert authorized.role == 'backend'

    # How about a bad password?
    bad_authenticate_msg = AUTHENTICATE(
                            signature = 'rumplestiltskin'
                        )
    authorized = ticket_auth.authenticate_challenge_response(
                                    mock_client,
                                    hello_msg,
                                    challenge_msg,
                                    bad_authenticate_msg
                                )
    assert authorized == None

    # Test cookies
    cookie_auth = CookieAuthenticator()

try:
    initialize('izaber-flask-wamp-test')
except Exception as ex:
    print("WEIRD STUF:", ex)