def test_equvalency(self): test = '{"test": 2.2000000000000002}' res1 = json.loads(test) fin1 = json.dumps(res1) self.assertEquals(test,fin1) dt = datetime.datetime.now().replace(microsecond=0) test = {'test':dt} res2 = json.dumps(test) fin2 = json.loads(res2) self.assertEquals(test['test'],fin2['test'])
def test_update_json(self): response = self.app.put( url("formatted_setting", id="test", format="json"), content_type="application/json", extra_environ=self.extra_environ, body=json.dumps(dict(values={"t1": 1, "t2": "blah"})), )
def test_create_json(self): response = self.app.post( url("formatted_settings", format="json"), content_type="application/json", extra_environ=self.extra_environ, body=json.dumps(dict(module="test3", values={"t1": 1, "t2": "blah"})), )
def uniques_by_article(self): try: params = json.loads(request.body) except: abort(400, detail='400 Bad Request') start_time = datetime.strptime(params.get('start_time',zero_formatted),dtformat) end_time = datetime.strptime(params.get('end_time',datetime.utcnow().strftime(dtformat)),dtformat) hits = meta.Session.execute( sql.select([access_log_t.c.path_info, sql.func.count(access_log_t.c.remote_ip.distinct()).label('hits')]).\ where(access_log_t.c.stamp.between(start_time,end_time)).\ group_by(access_log_t.c.path_info).\ order_by(sql.text('hits DESC')) ).fetchall() response.content_type = 'application/json' return json.dumps([dict(x.items()) for x in hits])
def browse_ajax(self): "this action returns some thumbnails based on a sort param and offset" response.content_type = 'application/json' sort_type = request.params.get('sort',None) offset = int(request.params.get('offset','0')) limit = int(request.params.get('limit','20')) query = meta.Session.query(Upload).order_by(Upload.updated.desc()).offset(offset).limit(limit).all() json_temp = [] for item in query: json_temp.append({ 'filepath':'/'.join([config['static_web_path'],item.filepath]), 'date':item.updated.isoformat(), 'alt':item.title or '' }) return json.dumps(json_temp)
def referers(self): try: params = json.loads(request.body) except: abort(400, detail='400 Bad Request') start_time = datetime.strptime(params.get('start_time',zero_formatted),dtformat) end_time = datetime.strptime(params.get('end_time',datetime.utcnow().strftime(dtformat)),dtformat) referers_dict = defaultdict(int) for row in meta.Session.execute(access_log_t.select(access_log_t.c.stamp.between(start_time,end_time))).fetchall(): try: row_url = urlparse.urlparse(row.referer_uri).host except: row_url = '' referers_dict[row_url] += 1 referers = [{'referer':x,'hits':y} for x,y in referers_dict.items()] response.content_type = 'application/json' return json.dumps(referers)
def test_update_json(self): response = self.app.put( url("formatted_article", format="json", id=1), content_type="application/json", extra_environ=self.extra_environ, body=json.dumps( dict( page_id=1, title=u"test", content=u"", sticky=True, published=dt.strftime("%Y-%m-%dT%H:%M:%SZ"), can_comment=True, tags=u"tag4,tag2", ) ), )
def test_referers(self): response = self.app.post(url(controller='analytics', action='referers'), content_type='application/json', body=json.dumps({})) self.assertEqual(response.status_int,200)
def test_uniques_by_article(self): response = self.app.post(url(controller='analytics', action='uniques_by_article'), content_type='application/json', body=json.dumps({})) self.assertEqual(response.status_int,200)
def test_update_json(self): response = self.app.put(url('formatted_user', id=1, format='json'), extra_environ=self.extra_environ, content_type='application/json', body=json.dumps(dict( name=u'test_user', open_id=u'http://myfake.openid.com', fb_id='', twitter_id='', type=1, profile=u'http://www.example.com/32', ))) from columns.model import User tmp = User.get_from_id(1) print tmp.to_dict() assert tmp.name == u'test_user' assert tmp.open_id == u'http://myfake.openid.com' assert tmp.fb_id == None assert tmp.twitter_id == None assert tmp.type == 1 assert tmp.profile == u'http://www.example.com/32'
def test_update_json(self): response = self.app.put(url('formatted_page', format='json', id=1), extra_environ=self.extra_environ, content_type='application/json', body=json.dumps(dict( title=u'Main',slug=u'main',content=u'',template=u'/blog/stream', stream_comment_style=u'summary',story_comment_style=u'list', visible=False,can_post=True,in_main=True,#tweet=False, ))) from columns.model import Page tmp = Page.get_from_id(1) assert tmp.title == u'Main' assert tmp.slug == u'main' assert tmp.content == u'' assert tmp.template == u'/blog/stream' assert tmp.stream_comment_style == u'summary' assert tmp.story_comment_style == u'list' assert tmp.visible == False assert tmp.can_post == True assert tmp.in_main == True
def test_dumps(self): obj = {"test": 1} res = json.dumps(obj) self.assertEquals(res,'{"test": 1}')
def process_bind_param(self, value, dialect): return unicode(json.dumps(value)) if value is not None else None
def jsonify(value): from columns.lib import json return json.dumps(value)
def test_update_json(self): response = self.app.put(url('formatted_picture', id=1, format='json'), extra_environ=self.extra_environ, content_type='application/json', body=json.dumps(dict( title=u'blah', content=u'blah', ))) from columns.model import Upload tmp = Upload.get_from_id(1) assert tmp.title == u'blah' assert tmp.content == u'blah'
def test_update_json(self): response = self.app.put(url('formatted_comment', format='json', parent_id=1, id=1), extra_environ=self.extra_environ, content_type='application/json', body=json.dumps(dict( title=u'testcomment', content = u'this is a comment. lol', ))) from columns.model import Comment, meta tmp = meta.Session.query(Comment).filter(Comment.title == u'testcomment').one() assert tmp.content == u'this is a comment. lol' assert tmp.author['name'] == u'test_user' assert tmp.author_id == 1 assert tmp.article_id == 1
def test_create_json(self): response = self.app.post(url('formatted_comments', parent_id=1, format='json'), extra_environ=self.extra_environ, content_type='application/json', body=json.dumps(dict( title=u'bwahahaha', content = u'lol', ))) from columns.model import Comment, meta tmp = meta.Session.query(Comment).filter(Comment.title == u'bwahahaha').one() assert tmp.content == u'lol' assert tmp.author['name'] == u'test_user' assert tmp.author['uri'] == u'http://www.example.com' assert tmp.author_id == 1 assert tmp.article_id == 1
def test_dumps_datetime(self): dt = datetime.datetime.now() obj = {'test':dt} res = json.dumps(obj) self.assertEquals(res,'{"test": "%s"}'%dt.strftime('%Y-%m-%dT%H:%M:%SZ'))
def tag_cloud(self): response.content_type = 'application/json' maximum = request.params.get('max',None) maximum = int(maximum) if maximum is not None else None result = [{'id':tag.id,'name':tag.label,'count':count} for tag, count in get_tag_frequencies(limit=maximum)] return json.dumps(result)
def test_dumps_decimal(self): test = {'test':2.2000000000000002} res = json.dumps(test) self.assertEquals(res,'{"test": 2.2000000000000002}')
def test_create_json(self): response = self.app.post(url('formatted_pages', format='json'), extra_environ=self.extra_environ, content_type='application/json', body=json.dumps(dict( title=u'Test',content=u'',template=u'/blog/blank', stream_comment_style=u'summary',story_comment_style=u'list', visible=False,can_post=True,in_main=True,#tweet=False, ))) from columns.model import Page, meta tmp = meta.Session.query(Page).filter(Page.slug == u'test').one() assert tmp.title == u'Test' assert tmp.content == u'' assert tmp.template == u'/blog/blank' assert tmp.stream_comment_style == u'summary' assert tmp.story_comment_style == u'list' assert tmp.visible == False assert tmp.can_post == True assert tmp.in_main == True
def test_create_json(self): response = self.app.post(url('formatted_users', format='json'), extra_environ=self.extra_environ, content_type='application/json', body=json.dumps(dict( name=u'test_user12', open_id=u'http://myfake.openid.com', fb_id='', twitter_id='', type=1, profile=u'http://www.example.com', ))) from columns.model import User, meta tmp = meta.Session.query(User).filter(User.name == u'test_user12').one() assert tmp.name == u'test_user12' assert tmp.open_id == u'http://myfake.openid.com' assert tmp.fb_id == None assert tmp.twitter_id == None assert tmp.type == 1 assert tmp.profile == u'http://www.example.com'