def user(request): un = authenticated_userid(request) u = User.by_name(un) if not u: u = User.by_name("Anonymous") if not u: raise Exception("Anonymous is missing") u.ip = "127.0.0.9" # request.headers["REMOTE_ADDR"] return u
def test_Create_dupe(self): user = User.by_name(u"test-admin") info = ipban_create(testing.DummyRequest(POST=_ban, user=user)) self.assertIsInstance(info, HTTPFound) user = User.by_name(u"test-admin") self.assertRaises(IPBanExistsException, ipban_create, testing.DummyRequest(POST=_ban, user=user)) info = ipban_list(testing.DummyRequest()) banned_ips = [ipban.ip for ipban in info["ipbans"]] self.assertListEqual(["1.2.3.4"], banned_ips)
def test_create_dupe(self): user = User.by_name(u"test-admin") info = untag_create(testing.DummyRequest(POST=_ban, user=user)) self.assertIsInstance(info, HTTPFound) user = User.by_name(u"test-admin") self.assertRaises(UnTagExistsException, untag_create, testing.DummyRequest(POST=_ban, user=user)) info = untag_list(testing.DummyRequest()) banned_tags = [untag.tag for untag in info["untags"]] self.assertListEqual(["test_untag"], banned_tags)
def authenticated_userid(self, request): u = User.by_session( request, request.cookies.get("shm_user"), request.cookies.get("shm_session") ) if u: return u.username else: return None
def test_basic(self): user = User.by_name(u"test-admin") info = ipban_create(testing.DummyRequest(POST=_ban, user=user)) self.assertIsInstance(info, HTTPFound) ban_id = info.headers["X-VTB-Ban-ID"] logger.info("Got ban ID: %r" % ban_id) info = ipban_delete(testing.DummyRequest(matchdict={"id": ban_id}, referrer="/")) self.assertIsInstance(info, HTTPFound) info = ipban_list(testing.DummyRequest()) banned_ips = [ipban.ip for ipban in info["ipbans"]] self.assertListEqual([], banned_ips)
def test_basic(self): user = User.by_name(u"test-admin") info = untag_create(testing.DummyRequest(POST=_ban, user=user)) self.assertIsInstance(info, HTTPFound) info = untag_list(testing.DummyRequest()) banned_tags = [untag.tag for untag in info["untags"]] self.assertListEqual(["test_untag"], banned_tags) info = untag_delete(testing.DummyRequest(matchdict={"tag": u"test_untag"}, referrer="/")) self.assertIsInstance(info, HTTPFound) info = untag_list(testing.DummyRequest()) banned_tags = [untag.tag for untag in info["untags"]] self.assertListEqual([], banned_tags)
def test_basic(self): user = User.by_name(u"test-admin") info = ipban_create(testing.DummyRequest(POST=_ban, user=user)) self.assertIsInstance(info, HTTPFound) ban_id = info.headers["X-VTB-Ban-ID"] logger.info("Got ban ID: %r" % ban_id) info = ipban_delete( testing.DummyRequest(matchdict={"id": ban_id}, referrer="/")) self.assertIsInstance(info, HTTPFound) info = ipban_list(testing.DummyRequest()) banned_ips = [ipban.ip for ipban in info["ipbans"]] self.assertListEqual([], banned_ips)
def test_basic(self): user = User.by_name(u"test-admin") info = untag_create(testing.DummyRequest(POST=_ban, user=user)) self.assertIsInstance(info, HTTPFound) info = untag_list(testing.DummyRequest()) banned_tags = [untag.tag for untag in info["untags"]] self.assertListEqual(["test_untag"], banned_tags) info = untag_delete( testing.DummyRequest(matchdict={"tag": u"test_untag"}, referrer="/")) self.assertIsInstance(info, HTTPFound) info = untag_list(testing.DummyRequest()) banned_tags = [untag.tag for untag in info["untags"]] self.assertListEqual([], banned_tags)
def setUp(self): VotaboTest.setUp(self) user = User.by_name(u"test-admin") untag_create( testing.DummyRequest(POST={ "tag": u"untag_test1", "redirect": u"/wiki/TestX" }, user=user)) untag_create( testing.DummyRequest(POST={ "tag": u"untag_test2", "redirect": u"/wiki/TestY" }, user=user)) untag_create( testing.DummyRequest(POST={ "tag": u"untag_test3", "redirect": u"/wiki/TestY" }, user=user))
def setUp(self): VotaboTest.setUp(self) user = User.by_name(u"test-admin") ipban_create( testing.DummyRequest(POST={ "ip": u"1.2.3.4", "reason": u"TestX BanX", "until": u"+3 weeks" }, user=user)) ipban_create( testing.DummyRequest(POST={ "ip": u"1.2.3.5", "reason": u"TestY BanX", "until": u"+3 weeks" }, user=user)) ipban_create( testing.DummyRequest(POST={ "ip": u"6.2.3.4", "reason": u"TestY BanY", "until": u"+3 weeks" }, user=user))
def setUp(self): self.config = testing.setUp() self.settings = {} configure_routes(self.config) configure_templates(self.config) configure_locale(self.config, self.settings) configure_user(self.config) # configure_auth(self.config) cache.fast.configure("dogpile.cache.memory") cache.slow.configure("dogpile.cache.memory") from sqlalchemy import create_engine engine = create_engine('sqlite://') DBSession.configure(bind=engine) Base.metadata.create_all(engine) with transaction.manager: # admin self.user0 = User() self.user0.username = u"test-admin" self.user0.category = "admin" self.user0.email = "*****@*****.**" self.user0.password = md5(self.user0.username + "password").hexdigest() p1 = Post() p1.fingerprint = "0"*32 p1.tags.append(Tag.get_or_create(u"test-tag")) p1.tags.append(Tag.get_or_create(u"cat")) p1.score = 1 self.user0.posts.append(p1) DBSession.add(self.user0) # user self.user1 = User() self.user1.username = u"test-user1" self.user1.category = "user" self.user1.email = "*****@*****.**" self.user1.set_password("password") p2 = Post() p2.fingerprint = "1"*32 p2.tags.append(Tag.get_or_create(u"test-tag")) p2.tags.append(Tag.get_or_create(u"bacon")) p2.score = 0 self.user1.posts.append(p2) DBSession.add(self.user1) # a different user self.user2 = User() self.user2.username = u"test-user2" self.user2.category = "user" self.user2.email = "*****@*****.**" self.user2.set_password("password") DBSession.add(self.user2) wp1 = WikiPage() wp1.user = self.user0 wp1.title = u"index" wp1.body = u"This is the default wiki index page" DBSession.add(wp1) wp2 = WikiPage() wp2.user = self.user0 wp2.title = u"wiki:template" wp2.body = u"This is the default wiki template page" DBSession.add(wp2)
def setUp(self): VotaboTest.setUp(self) user = User.by_name(u"test-admin") untag_create(testing.DummyRequest(POST={"tag": u"untag_test1", "redirect": u"/wiki/TestX"}, user=user)) untag_create(testing.DummyRequest(POST={"tag": u"untag_test2", "redirect": u"/wiki/TestY"}, user=user)) untag_create(testing.DummyRequest(POST={"tag": u"untag_test3", "redirect": u"/wiki/TestY"}, user=user))
def test_basic(self): request = testing.DummyRequest() info = user_list(request) self.assertIn(User.by_name(u"test-user1"), info["users"]) self.assertIn(User.by_name(u"test-admin"), info["users"])
def test_category(self): request = testing.DummyRequest(GET={"category": u"admin"}) info = user_list(request) self.assertIn(User.by_name(u"test-admin"), info["users"]) self.assertNotIn(User.by_name(u"test-user1"), info["users"])
def test_comments_num(self): request = testing.DummyRequest(GET={"comments": "0"}) info = user_list(request) self.assertIn(User.by_name(u"test-user1"), info["users"]) self.assertIn(User.by_name(u"test-admin"), info["users"])
def test_posts_on(self): request = testing.DummyRequest(GET={"posts": "on"}) info = user_list(request) self.assertNotIn(User.by_name(u"test-user1"), info["users"]) self.assertNotIn(User.by_name(u"test-admin"), info["users"])
def test_username_prefix(self): request = testing.DummyRequest(GET={"username": u"test"}) info = user_list(request) self.assertIn(User.by_name(u"test-admin"), info["users"]) self.assertIn(User.by_name(u"test-user1"), info["users"])
def test_id(self): request = testing.DummyRequest( GET={"id": User.by_name(u"test-admin").id}) info = user_list(request) self.assertIn(User.by_name(u"test-admin"), info["users"]) self.assertNotIn(User.by_name(u"test-user1"), info["users"])
def authenticated_userid(self, request): u = User.by_session(request, request.cookies.get("shm_user"), request.cookies.get("shm_session")) if u: return u.username else: return None
def setUp(self): VotaboTest.setUp(self) user = User.by_name(u"test-admin") ipban_create(testing.DummyRequest(POST={"ip": u"1.2.3.4", "reason": u"TestX BanX", "until": u"+3 weeks"}, user=user)) ipban_create(testing.DummyRequest(POST={"ip": u"1.2.3.5", "reason": u"TestY BanX", "until": u"+3 weeks"}, user=user)) ipban_create(testing.DummyRequest(POST={"ip": u"6.2.3.4", "reason": u"TestY BanY", "until": u"+3 weeks"}, user=user))