def setUp(self): from columns.model import User tmp = User.from_dict(dict( id=1, name=u'test_user', open_id=u'http://tester.example.com', fb_id=None, twitter_id=None, type=9, profile=u'http://www.example.com', )) try: tmp.save() except: pass tmp2 = User.from_dict(dict( id=2, name=u'test_user2', open_id=u'http://tester2.example.com', fb_id=None, twitter_id=None, type=9, profile=u'http://www.example.com', )) try: tmp2.save() except: pass
def setUp(self): from columns.model import Upload, User tmp = User.from_dict(dict( id=1, name=u'test_user', open_id=None, fb_id=None, twitter_id=None, type=1, profile=None, )) try: tmp.save() except: pass tmp = Upload(**dict( id=1, title=u'test', content=u'', filepath=u'', updated=datetime.datetime.utcnow(), published=datetime.datetime.utcnow(), author={'name':u'test_user'} )) try: tmp.save() except Exception, ex: print ex
def test_set_name_true(self): response = self.app.post(url("set_name_accounts"), extra_environ=self.extra_environ, params={'name':'qwertyuiop'}) sess = response.environ['beaker.session'] from columns.model import User tmp = User.get_from_id(1) self.assertEquals(tmp.name,u"qwertyuiop") self.assertEquals(sess[u'user_name'],u"qwertyuiop")
def test_set_name_error(self): response = self.app.post(url("set_name_accounts"), extra_environ=self.extra_environ) sess = response.environ['beaker.session'] from columns.model import User tmp = User.get_from_id(1) self.assertEquals(tmp.name,u"test_user") self.assertEquals(sess[u'user_name'],u"test_user")
def set_name(self): try: user_name = request.POST.getone("name") if User.is_unique(user_name): user = meta.Session.query(User).get(int(session['user_id'])) user.name = session['user_name'] = user_name user.save() session.save() except Exception, ex: log.error(traceback.format_exc())
def check_unique_name(self): try: user_name = request.params.getone("name") if User.is_unique(user_name): return "Not Taken" else: return "Already Taken" except Exception, ex: log.error(traceback.format_exc()) return "Error"
def setUp(self): tmp = User.from_dict(dict( id=1, name=u'test_user', open_id=None, fb_id=None, twitter_id=None, type=1, profile=None, )) tmp.save()
def setUp(self): from columns.model import Page, User, Article, Upload ptmp = Page.from_dict(dict( id=1, title=u'Main',slug=u'main',content=u'',template=u'/blog/stream', stream_comment_style=u'summary',story_comment_style=u'list', visible=True,can_post=True,in_main=True,in_menu=False, )) ptmp.save() utmp = User.from_dict(dict( id=1, name=u'test_user', open_id=None, fb_id=None, twitter_id=None, type=1, profile=None, )) utmp.save() atmp = Article(**dict( id=1, created=dt, updated=dt, atom_id=u'-'.join([dt.strftime("%Y-%m-%d"),u'test']), title=u'test', content=u'', summary=u'', published=dt, links=[], author_id=utmp.id, author={ 'name':u'test_user', }, contributors=[], metatags={}, metacontent=u'', permalink=u'-'.join([dt.strftime("%Y-%m-%d"),u'test']), sticky=False, can_comment=True, page_id=ptmp.id, )) atmp.save() tmp = Upload(**dict( id=1, title=u'test', content=u'', filepath=u'', updated=datetime.datetime.utcnow(), published=datetime.datetime.utcnow(), author={'name':u'test_user'} )) tmp.save()
def _create(self, format, parent_id=None): if format == 'json': params = self._validate(json.loads(request.body), CreateUser, 'new') #elif format == 'atom': # from lxml import etree # params = User.parse_xml(etree.fromstring(request.body)) elif format == 'html': params = self._validate(request.POST.mixed(), CreateUser, 'new') else: raise UnacceptedFormat(format) item = User.from_dict(params) item.save() return item
def create_user(session): from columns.model import User from columns.config.authorization import INV_PERMISSIONS item = User() item.type = INV_PERMISSIONS['subscriber'] if session.get('auth_type',None) == 'facebook': item.fb_id = session['auth_oid'] elif session.get('auth_type',None) == 'twitter': item.twitter_id = session['auth_oid'] else: #session.get('auth_type',None) == 'openid': item.open_id = session['auth_oid'] item.save() return item
def create(self): """POST /accounts: Create a new item""" # url('accounts') from columns.config.authorization import INV_PERMISSIONS item = User() item.name = request.POST.get('name',None) item.profile = request.POST.get('profile',None) item.type = INV_PERMISSIONS['subscriber'] if session.get('auth_type',None) == 'facebook': item.fb_id = session['oid'] elif session.get('auth_type',None) == 'twitter': item.twitter_id = session['oid'] elif session.get('auth_type',None) == 'openid': item.open_id = session['oid'] session['user_name'] = item.name session['user_type'] = item.type session['user_profile'] = item.profile session.save() item.save(session, app_globals) redirect(url("main"))
def setUp(self): from columns.model import User tmp = User.from_dict(dict( id=1, name=u'test_user', open_id=None, fb_id=None, twitter_id=None, type=1, profile=None, )) try: tmp.save() except: pass
def setUp(self): from columns.model import Page, User, Article ptmp = Page.from_dict( dict( id=1, title=u"Main", slug=u"main", content=u"", template=u"/blog/stream", stream_comment_style=u"summary", story_comment_style=u"list", visible=True, can_post=True, in_main=True, in_menu=False, ) ) ptmp.save() utmp = User.from_dict( dict(id=1, name=u"test_user", open_id=None, fb_id=None, twitter_id=None, type=1, profile=None) ) utmp.save() atmp = Article( **dict( id=1, created=dt, updated=dt, atom_id=u"-".join([dt.strftime("%Y-%m-%d"), u"test"]), title=u"test", content=u"", summary=u"", published=None, # dt, links=[], author_id=utmp.id, author={"name": u"test_user"}, contributors=[], metatags={}, metacontent=u"", permalink=u"-".join([dt.strftime("%Y-%m-%d"), u"test"]), sticky=False, can_comment=True, page_id=ptmp.id, ) ) atmp.save()
def test_delete_browser_fakeout(self): tmp_environ = {'test.session':{ 'user_id':1, 'user_name':u'test_user', 'user_type':9, 'user_profile':u'http://www.example.com', 'user_openid':u'http://tester.example.com', 'user_fbid':None, 'user_twitterid':None, 'auth_type':u'twitter', 'oid':u'1234567890' },'columns.authorize.disabled':True} response = self.app.post(url('accounts'), extra_environ=tmp_environ, params=dict(_method='delete')) sess = response.environ['beaker.session'] from columns.model import User tmp = User.get_from_id(1) self.assertEquals(tmp,None) self.assertEquals(sess.get('user_id',None),None)
def test_update(self): response = self.app.put(url('user', id=1), extra_environ=self.extra_environ, params=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_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_store_user(self): from columns.model import User tmp = User.from_dict(dict( id=1, name=u'test_user', open_id=None, fb_id=None, twitter_id=None, type=1, profile=None, )) store_user(session,tmp) self.assertEquals(session['user_id'], tmp.id) self.assertEquals(session['user_name'], tmp.name) self.assertEquals(session['user_type'], tmp.type) self.assertEquals(session['user_profile'], tmp.profile) self.assertEquals(session['user_openid'], tmp.open_id) self.assertEquals(session['user_fbid'], tmp.fb_id) self.assertEquals(session['user_twitterid'], tmp.twitter_id)
def test_update_2(self): tmp_environ = {'test.session':{ 'user_id':1, 'user_name':u'test_user', 'user_type':9, 'user_profile':u'http://www.example.com', 'user_openid':u'http://tester.example.com', 'user_fbid':None, 'user_twitterid':None, 'auth_type':u'openid', 'oid':u'1234567890' },'columns.authorize.disabled':True} response = self.app.put(url('accounts'), extra_environ=tmp_environ, params={'profile':'http://test.com'}) sess = response.environ['beaker.session'] from columns.model import User tmp = User.get_from_id(1) self.assertEquals(tmp.profile,u'http://test.com') self.assertEquals(sess['user_profile'],u'http://test.com') self.assertEquals(tmp.open_id,u'1234567890')
def test_retrieve_user(self): from columns.model import User res = retrieve_user(session) self.assertEquals(res,None) tmp = User.from_dict(dict( id=1, name=u'test_user', open_id=None, fb_id=None, twitter_id=None, type=1, profile=None, )) store_user(session,tmp) res = retrieve_user(session) self.assertEquals(res['id'], tmp.id) self.assertEquals(res['name'], tmp.name) self.assertEquals(res['type'], tmp.type) self.assertEquals(res['profile'], tmp.profile) self.assertEquals(res['open_id'], tmp.open_id) self.assertEquals(res['fb_id'], tmp.fb_id) self.assertEquals(res['twitter_id'], tmp.twitter_id)
def create(self, parent_id=None, format='html'): """POST /``REST_Collection``: Create a new item""" if session['user_name'] is None: name = unicode(request.POST.get('name',u'').strip()) if name != u'' and User.is_unique(name): user = meta.Session.query(User).get(int(session['user_id'])) user.name = session['user_name'] = name user.save() session.save() try: item = self._create(format, parent_id) except UnacceptedFormat: abort(415, detail='415 Unsupported Media Type') #except InvalidForm, ex: # return ex.value if self.FORMAT_NEEDS_REDIRECT[format] is True: redirect(self._py_object.url('story',permalink=item.article.permalink)) else: #if parent_id is None: # abort(201, detail='201 Created', headers={'Location': self._py_object.url(self.SINGLE, id=item.id)}) #else: abort(201, detail='201 Created', headers={'Location': self._py_object.url(self.SINGLE, parent_id=parent_id, id=item.id)})
def test_delete_browser_fakeout(self): response = self.app.post(url('user', id=1), extra_environ=self.extra_environ, params=dict(_method='delete')) from columns.model import User tmp = User.get_from_id(1) assert tmp == None
def _new(self, parent_id=None, with_defaults=True): item = User() if with_defaults is True: item.set_defaults() return item
def test_delete(self): response = self.app.delete(url('user', id=1), extra_environ=self.extra_environ) from columns.model import User tmp = User.get_from_id(1) assert tmp == None