def test_files_form_post(self):
     """Check we can send data through both channels."""
     msg = TurboBeeMsg(value=u'\u6789'.encode('utf8'))
     msg2 = TurboBeeMsg(value=u'\u6789'.encode('utf8'))
     r = self.client.post(url_for('turbobee_app.store'),
                          content_type='multipart/form-data',
                          data={
                              'foo':
                              base64.encodestring(msg.dump()[1]),
                              'bar': (StringIO(msg2.dump()[1]),
                                      'turbobee_msg.proto'),
                          })
     assert len(r.json['created']) == 2
     msgs = list(self.app.get_pages(r.json['created']))
     for m in msgs:
         m['content'].decode('utf8') == u'\u6789'
    def test_store_post(self):
        msg = TurboBeeMsg()
        now = dt.datetime.utcnow()
        msg.created = msg.get_timestamp(now)
        msg.updated = msg.get_timestamp(now)
        msg.expires = msg.get_timestamp(now)
        msg.eol = msg.get_timestamp(now)
        msg.set_value('hello world')
        msg.ctype = msg.ContentType.html
        msg.target = 'https:///some.com'
        msg.owner = 234
        my_data = {
            'file_field': (StringIO(msg.dump()[1]), 'turbobee_msg.proto')
        }

        r = self.client.post(url_for('turbobee_app.store', qid='asdf'),
                             content_type='multipart/form-data',
                             data=my_data)

        self.assertEqual(r.status_code, 200)
        assert len(r.json['created']) == 1

        msg2 = msg.loads(*msg.dump())
        msg.qid = r.json['created'][0]
        r = self.client.post(url_for('turbobee_app.store'),
                             content_type='multipart/form-data',
                             data={
                                 'foo': (StringIO(msg.dump()[1]),
                                         'turbobee_msg.proto'),
                                 'bar': (StringIO(msg2.dump()[1]),
                                         'turbobee_msg.proto'),
                             })
        self.assertEqual(r.status_code, 200)
        assert len(r.json['created']) == 1
        assert len(r.json['updated']) == 1

        r = self.client.get(url_for('turbobee_app.store_get', qid=msg.qid))
        self.assertEqual(r.status_code, 200)
        r = self.client.head(url_for('turbobee_app.store_get', qid=msg.qid))
        self.assertEqual(r.status_code, 200)

        r = self.client.get(url_for('turbobee_app.store_get', qid='foo'))
        self.assertEqual(r.status_code, 404)
        r = self.client.head(url_for('turbobee_app.store_get', qid='foo'))
        self.assertEqual(r.status_code, 404)
Пример #3
0
    def test_serializer(self):
        # check we are not movng dates (by loosing nanosec precision)
        rec = TurboBeeMsg()
        now = datetime.utcnow()
        rec.created = rec.get_timestamp(now)

        for i in xrange(10050):
            rec = rec.loads(*rec.dump())
            self.assertEqual(rec.get_datetime(rec.created), now)
    def test_proto_empty(self):
        msg = TurboBeeMsg()
        my_data = {
            'file_field': (StringIO(msg.dump()[1]), 'turbobee_msg.proto')
        }

        r = self.client.post(url_for('turbobee_app.store', qid='asdf'),
                             content_type='multipart/form-data',
                             data=my_data)

        self.assertEqual(r.status_code, 200)

        with self.app.session_scope() as session:
            assert len(session.query(Pages).all()) == 1
Пример #5
0
 def test_set_get_pages(self):
     msg = TurboBeeMsg()
     now = datetime.utcnow()
     
     msg.created = msg.get_timestamp(now)
     msg.updated = msg.get_timestamp(now)
     msg.expires = msg.get_timestamp(now)
     msg.eol = msg.get_timestamp(now)
     msg.set_value('hello world')
     msg.ctype = msg.ContentType.html
     msg.target = 'https:///some.com'
     msg.owner = 234
     
     r = self.app.set_pages([msg])
     assert 'created' in r
     assert len(r['created']) ==1
     
     pages = list(self.app.get_pages(r['created']))
     expected = {
         'id': 1,
         'target': u'https:///some.com', 
         'content_type': u'application/html', 
         'content': 'hello world', 
         'created': get_date(now).isoformat(), 
         'updated': get_date(now).isoformat(), 
         'expires': get_date(now).isoformat(), 
         'lifetime': get_date(now).isoformat(),
         'owner': 234,
         'qid': pages[0]['qid']
         }
     assert pages[0] == expected
     
     msg.qid = pages[0]['qid']
     r = self.app.set_pages([msg])
     assert 'updated' in r
     assert len(r['updated']) ==1
     assert r['updated'][0] == expected['qid']
     
     msg.status = Status.deleted
     r = self.app.set_pages([msg])
     assert 'deleted' in r
     assert r['deleted'][0] == expected['qid']
     
     r = self.app.set_pages([msg])
     assert r['ignored-deleted'][0] == expected['qid']
     assert len(list(self.app.get_pages(expected['qid']))) == 0
     
     # insert it again
     msg.status = Status.active
     r = self.app.set_pages([msg])
     assert r['created'][0]
     assert r['created'][0] != expected['qid']
     
     l = list(self.app.get_pages(r['created'], fields=['foo', 'qid', 'content', 'created']))
     assert l[0]['qid'] == r['created'][0]
     assert l[0]['created'] == expected['created']
     assert l[0]['content'] == 'hello world'
     assert 'updated' not in l[0]
     assert 'foo' not in l[0]
     
     
     # set multiple objects at once
     msg.qid = r['created'][0]
     msg2 = msg.loads(*msg.dump())
     msg2.qid = ''
     r = self.app.set_pages([msg, msg2])
     assert r['created'][0] 
     assert r['updated'][0] == msg.qid
     
     # update one by one
     msg2.qid = r['created'][0]
     r = self.app.set_pages([msg, msg2], one_by_one=True)
     assert msg.qid in r['updated']
     assert msg2.qid in r['updated']
     
     
     r = self.app.set_pages([msg, msg2, msg, msg, msg], one_by_one=True)
     assert set(r['updated']) == set([msg.qid, msg2.qid])