Пример #1
0
 def test_ignore_cls(self):
     """
     If first argument is nammed 'cls', ignore that argument (to allow
     classmethods)
     """
     def test(cls, a, b, c="what"): pass
     program = Program(model=[test], view=BasicView())
     ret = program.get_model_args_kwargs()
     self.assertEquals((['a', 'b'], {'c': "what"}), ret)
Пример #2
0
 def setUp(self):
     initialize()
     self.manifest = Manifest({
         '':
         Program(model=[none], view=BasicView()),
         'named':
         Program(model=[defaults], view=BasicView()),
         "another": {
             '': Program(name='another root'),
             'name': Program(name='another name', view=BasicView())
         }
     })
Пример #3
0
    def test_only_args(self):
        def model(var1, var2):
            return None

        args, kwargs = Program(model=[model]).get_model_args_kwargs()
        self.assertEquals(args, ['var1', 'var2'])
        self.assertEquals(kwargs, {})
Пример #4
0
    def test_both(self):
        def model(var0, var1=3, var2=9):
            return None

        args, kwargs = Program(model=[model]).get_model_args_kwargs()
        self.assertEquals(args, ['var0'])
        self.assertEquals(kwargs, {'var1': 3, 'var2': 9})
Пример #5
0
    def test_cls_arg(self):
        """
        cls var gets ignored when getting args for a model callable
        """
        class Model(object):
            @classmethod
            def model(cls, var0, var1=3, var2=9):
                return None

        args, kwargs = Program(model=[Model.model]).get_model_args_kwargs()
        self.assertEquals(args, ['var0'])
        self.assertEquals(kwargs, {'var1': 3, 'var2': 9})
Пример #6
0
    def setUp(self):
        self.manifest = Manifest({
            '':
            Manifest({
                '':
                Manifest({
                    '': Program(name='root'),
                    'deep': Program(name="deep")
                }),
            }),
            'sub': {
                'prog': Program(name="prog"),
                'another': {
                    '':
                    blank,
                    'prog2':
                    Program(name='prog2'),
                    'prog3':
                    Program(name='prog3'),
                    'http_only':
                    Program(name='http_only', controllers=['http-get']),
                    'irc_only':
                    Program(name='irc_only', controllers=['irc']),
                    'both':
                    both
                },
                'double': [double_get, double_post]
            },
            'string_redirect':
            '/redirect',
            'redirect':
            Program(name='redirect'),
        })

        self.all_urls = set([
            '/', '/deep', '/sub/another/irc_only', '/sub/another/http_only',
            '/sub/another/both', '/sub/prog', '/sub/another',
            '/sub/another/prog2', '/sub/another/prog3', '/redirect',
            '/string_redirect', '/sub/double'
        ])

        self.irc_only_urls = set(['/sub/another/irc_only'])
        self.http_only_urls = set(['/sub/another/http_only', '/sub/double'])
Пример #7
0
 def setUp(self):
     initialize()
     self.manifest = Manifest({
         'no_defaults':
         Program(model=[no_defaults], view=BasicView()),
         'defaults':
         Program(model=[defaults], view=BasicView()),
         'primitives':
         Program(model=[primitive], view=BasicView()),
         'raw':
         Program(model=[raw], view=BasicView()),
         'none':
         Program(model=[none], view=BasicView),
         'order':
         Program(model=[order], view=BasicView)
     })
Пример #8
0
 def test_preserve_order(self):
     def test(a=1, b=2, c=3, d=4): pass
     program = Program(model=[test], view=BasicView())
     a, kw = program.get_model_args_kwargs()
     self.assertEquals(list(kw.keys()), ['a', 'b', 'c', 'd'])
Пример #9
0
 def test_no_model(self):
     program = Program(view=BasicView())
     ret = program.get_model_args_kwargs()
     self.assertEquals(([], {}), ret)
Пример #10
0
from giotto.programs import Program, Manifest
from giotto.programs.shell import shell
from giotto.programs.tables import syncdb, flush
from giotto.views import BasicView

management_manifest = Manifest({
    'syncdb':
    Program(name="Make Tables",
            controllers=['cmd'],
            model=[syncdb],
            view=BasicView()),
    'flush':
    Program(
        name="Blast Tables",
        controllers=['cmd'],
        model=[flush],
        view=BasicView(),
    ),
    'shell':
    Program(
        name="Giotto Shell",
        controllers=['cmd'],
        model=[shell],
        view=BasicView(),
    ),
})
Пример #11
0
 def test_empty(self):
     def test(): pass
     program = Program(model=[test], view=BasicView())
     ret = program.get_model_args_kwargs()
     self.assertEquals(([], {}), ret)
Пример #12
0
 def test_get_args_kwargs(self):
     def test(a, b, c="what"): pass
     program = Program(model=[test], view=BasicView())
     ret = program.get_model_args_kwargs()
     self.assertEquals((['a', 'b'], {'c': "what"}), ret)
Пример #13
0
 def test_mock_found(self):
     gp = Program(model=[simple, {'mock': True}])
     self.assertEquals({'mock': True}, gp.get_model_mock())
Пример #14
0
 def test_no_mock_needed(self):
     gp = Program(model=[])
     self.assertEquals({}, gp.get_model_mock())
Пример #15
0
 def test_no_mock_found(self):
     """
     The program raises MockNotFound when the program has no mock defined
     """
     gp = Program(model=[simple])
     self.assertRaises(MockNotFound, lambda: gp.get_model_mock())
Пример #16
0
from giotto.programs import Program, Manifest
from giotto.programs.management import management_manifest
from giotto.views import BasicView

manifest = Manifest({
    '': Program(
        model=[lambda: "Welcome to Giotto!"],
        view=BasicView
    ),
    'mgt': management_manifest,
})
Пример #17
0
from giotto.contrib.static.programs import StaticServe
from giotto.programs import Program, Manifest
from giotto.programs.management import management_manifest
from giotto.views import BasicView, jinja_template
from models import show_listings, CrawlResult, stats

manifest = Manifest({
    '':
    '/stats',
    'stats':
    Program(model=[stats],
            view=BasicView(html=jinja_template('landing.html'))),
    'api_docs':
    Program(view=BasicView(html=jinja_template('api.html'))),
    'listings':
    Program(model=[show_listings],
            view=BasicView(html=jinja_template("show_listings.html"))),
    'crawl':
    Program(
        controllers=['cmd'],
        model=[CrawlResult.do_crawl],
    ),
    'static':
    StaticServe('/static'),
    'mgt':
    management_manifest,
})
Пример #18
0
import unittest

from giotto.programs import Manifest, Program
from giotto.exceptions import ProgramNotFound

both = Program(name='both', controllers=['irc', 'http-get'])
blank = Program(name='optional_blank')
double_get = Program(name="getter", controllers=['http-get'])
double_post = Program(name="poster", controllers=['http-post'])


class StackedRootTest(unittest.TestCase):
    def setUp(self):
        self.manifest = Manifest({
            '':
            Manifest({
                '':
                Manifest({
                    '': Program(name='root'),
                    'deep': Program(name="deep")
                }),
            }),
            'sub': {
                'prog': Program(name="prog"),
                'another': {
                    '':
                    blank,
                    'prog2':
                    Program(name='prog2'),
                    'prog3':
                    Program(name='prog3'),