Exemplo n.º 1
0
    def test_foreignKeySerializer(self):
        u = core.ForeignKeySerializer(
            'foo',
            other_serializer=core.StringSerializer('name')
            )

        with Mock() as fakeobj2:
            fakeobj2.__getattr__('name') >> 'bar'

        with Mock() as fakeobj:
            fakeobj.__getattr__('foo') >> fakeobj2

        self.assertEquals(u.serialize(fakeobj), 'bar')
Exemplo n.º 2
0
    def test_dateWidget(self):
        flt = widgets.DateWidget('foo')
        requestDict = {'foo': '2011-01-11'}
        with Mock() as querySet:
            querySet.filter(foo=date(2011, 1, 11))

        flt.filterQuerySet(querySet, requestDict)
Exemplo n.º 3
0
    def test_enabled(self):
        f = core.SimpleFilter('foo', 'contains')
        with Mock() as querySet:
            querySet.filter(foo__contains='bar')

        f.enabled(querySet, 'bar')
        querySet.validate()
Exemplo n.º 4
0
def fakeQuerySet():
    with Mock() as mock:
         for a in [1,2,3]:
             mock.__getattr__('foo') >> 123
             mock.__getattr__('pk') >> a

    return [mock, mock, mock]
Exemplo n.º 5
0
    def test_stringWidget_filterQuerySet(self):
        w = widgets.StringWidget('foo')
        requestDict = {'foo': 'omg'}
        with Mock() as querySet:
            querySet.filter(foo__contains='omg')

        w.filterQuerySet(querySet, requestDict)
Exemplo n.º 6
0
def mock_context(response):
    with Mock() as context:
        context.__len__() >> 1
        socket = context.socket(zmq.REQ)
        socket.connect('inproc://zrpc')
        socket.send(instance_of(str))
        socket.recv() >> BSON.encode(response)
    return context
Exemplo n.º 7
0
    def test_filterAndSort(self):
        with Mock() as querySet:
            querySet.filter(foo__contains='5')
            querySet.order_by('-foo')

        self.s.querySet = querySet
        self.s.filterAndSort(self.valueDict, (self.c, True))
        querySet.validate()
Exemplo n.º 8
0
    def test_filterAndSort(self):
        with Mock() as storage:
            storage.getColumns() >> []
            storage.filterAndSort(self.requestDict, None)

        self.t.storage = storage
        self.t.filterAndSort(self.fakeRequest)
        storage.validate()
Exemplo n.º 9
0
    def test_stringColumn(self):
        s = columns.StringColumn('foo')

        with Mock() as querySet:
            querySet.order_by('foo')
            querySet.order_by('-foo')

        s.sortQuerySet(querySet, False)
        s.sortQuerySet(querySet, True)
Exemplo n.º 10
0
    def test_urlSerializer(self):
        u = core.URLSerializer(field='foo', urlName='bar')

        with Mock() as resolver:
            resolver('bar', args=(1, )) >> True
        u.resolver = resolver

        self.assertEquals(u.serialize_value(None), None)
        self.assertEquals(u.serialize_value(1), True)
Exemplo n.º 11
0
 def test_parse_title_from_url(self):
     with Mock() as Http:
         from httplib2 import Http
         connection = Http()
         connection.request(self.url) >> ({'headers': ''}, self.html)
     html2data_instance = HTML2Data(url=self.url)
     title = html2data_instance.xpath('//head/title/text()')
     self.assertEqual([
         'Example Page',
     ], title)
Exemplo n.º 12
0
    def test_filterQuerySet_clean(self):
        f = core.SimpleFilter('foo')

        f.clean = lambda x: 5

        with Mock() as querySet:
            querySet.filter(foo=5)

        f.filterQuerySet(querySet, 'not 5')

        querySet.validate()
Exemplo n.º 13
0
    def test_serializeRow(self):
        class FakeModel:
            foo = '123'

        fm = FakeModel()

        with Mock() as column:
            column.name >> "foo"
            column.serialize(fm, output=0) >> 'bar'

        d = Table("name", 'querySet', [column])
        self.assertEquals(d.serializeRow(fm, output=0), {'foo': 'bar'})
Exemplo n.º 14
0
    def test_serializeData(self):
        class FakeModel:
            foo = '1'

        queryset = [FakeModel(), FakeModel()]

        d = Table("name", 'querySet', [('foo', 'label')])

        with Mock() as d.serializeRow:
            d.serializeRow(1, None)
            d.serializeRow(1, None)

        d.serializeData(queryset, output=None)
Exemplo n.º 15
0
    def test_serializeToXLS(self):
        class Foo:
            foo = 'bar'

        with Mock() as querySet:
            querySet.filter(foo__contains='5')
            querySet.order_by('-foo')
            querySet.__getitem__(0) >> Foo()
            querySet.__getitem__(1) >> StopIteration()

        self.s.querySet = querySet
        res = self.s.serializeToXLS(self.valueDict, (self.c, True))
        querySet.validate()
Exemplo n.º 16
0
    def test_request_good(self):
        requestDict = {'foo': '5'}

        self.assertEquals(self.w.existsIn(requestDict), True)

        self.assertEquals(self.w.exportDescription(requestDict), ['Foo', '5'])

        with Mock() as querySet:
            querySet.filter(foo='5')

        self.w.filterQuerySet(querySet, requestDict)

        querySet.validate()
Exemplo n.º 17
0
    def test_sortQuerySet(self):

        with Mock() as querySet:
            querySet.order_by('foo')
            querySet.order_by('bar')

        s = columns.StringColumn('foo')
        s.sortQuerySet(querySet, False)

        s = columns.StringColumn('foo', sortColumnName='bar')

        s.sortQuerySet(querySet, False)
        querySet.validate()
Exemplo n.º 18
0
    def test_hrefSerializer(self):
        u = core.HrefSerializer(
            format='%(foo)s',
            urlSerializer=core.URLSerializer(
                field='bar',
                urlName='quuz')
            )

        with Mock() as model:
            model.__getattr__('foo') >> 'baz'

            model.__getattr__('foo') >> 'baz'
            model.__getattr__('bar') >> 'quux'

        with Mock() as resolver:
            resolver('quuz', args=('quux', )) >> 'http://lol/'
        u.urlSerializer.resolver = resolver

        ret = u.serialize(model, output_format=formats.XLS)
        self.assertEquals(ret, 'baz')

        ret = u.serialize(model, output_format=formats.JSON)
        self.assertEquals(ret, 'http://lol/\nbaz')
Exemplo n.º 19
0
    def test_wholeDayFilter(self):
        f = extra_filters.WholeDayFilter('foo')

        with Mock() as querySet:
            querySet.filter(
                foo__gte=date(2011, 12, 31),
                foo__lt=date(2012, 1, 1))

            querySet.filter(
                foo__gte=date(2011, 12, 31),
                foo__lt=date(2012, 1, 1))

        f.filterQuerySet(querySet, date(2011, 12, 31))
        f.filterQuerySet(querySet, datetime(2011, 12, 31, 12, 32))
Exemplo n.º 20
0
    def test_handleRequest_filter(self):
        f = self.fakeRequest

        f.GET['table'] = "filter,xxx"
        self.assertRaises(Http404, self.t.handleRequest, f)

        with Mock() as other_storage:
            other_storage.__len__() >> True
            other_storage.serializeToJSON(dict(foo='5'), None) >> {'a': 'b'}

        self.w.storage = other_storage
        f.GET['table'] = "widget,foo"
        resp = self.t.handleRequest(f, 'GET')

        self.assertEquals(
            str(resp).split('\n')[-1], '{"a": "b", "success": true}')
Exemplo n.º 21
0
    def test_fieldSerializer(self):
        f = core.serializers.FieldSerializer('foo')
        with Mock() as mock:
            mock.__getattr__('foo') >> True
            mock.__getattr__('foo') >> True

        self.assertEquals(
            f.extract_value(mock), True)

        self.assertRaises(
            NotImplementedError,
            f.serialize, mock)

        self.assertRaises(
            NotImplementedError,
            f.serialize_value, 'foo')
Exemplo n.º 22
0
    def test_serializeToJSON(self):
        class Foo:
            pk = 1
            foo = 'bar'

        with Mock() as querySet:
            querySet.filter(foo__contains='5')
            querySet.order_by('-foo')
            querySet.count() >> 1
            querySet.__getitem__(slice(0, None, None)) >> [Foo()]

        self.s.querySet = querySet

        res = self.s.serializeToJSON(self.valueDict, (self.c, True))
        self.assertIn("'pk': 1", str(res))

        querySet.validate()
Exemplo n.º 23
0
    def runTest(self):

        from ludibrio import Mock

        with Mock() as smtplibMock:

            message = """\
From: %s
To: %s
Subject: %s

%s
""" % (_FROMADDR, _TOADDR, "hi", 'hello!')

            server = smtplibMock.SMTP(_SERVER)
            server.starttls()
            server.login(_USER, _PASSWORD)
            server.sendmail(_FROMADDR, _TOADDR, message)

        notif = Notifier(smtplibMock)

        notif.NotifyRaw('hi', 'hello!')

        smtplibMock.validate()
Exemplo n.º 24
0
 def test_dateWidget_lte(self):
     flt = widgets.DateWidget('foo', filterKwargs={'operation': 'lte'})
     requestDict = {'foo': '2011-01-11'}
     with Mock() as querySet:
         querySet.filter(foo__lte=date(2011, 1, 11))
     flt.filterQuerySet(querySet, requestDict)
Exemplo n.º 25
0
    def test_biggerThan(self):
        f = extra_filters.BiggerThan('foo', 5)

        with Mock() as querySet:
            querySet.filter(foo__gt=5)
        f.enabled(querySet, True)
Exemplo n.º 26
0
 def setUp(self):
     with Mock() as mock:
         mock.__getattr__('foo') >> self.firstValue
         mock.__getattr__('foo') >> None
     self.mock = mock