def test_email_set(self): DBSession.add(self.user1) request = testing.DummyRequest(referrer="/", matchdict={"name": u"test-user1"}, POST={"email": "*****@*****.**"}) info = user_update(request) self.assertEqual(self.user1.email, "*****@*****.**")
def test_valid_send(self): DBSession.add(self.user0) request = self.mockRequest(user=self.user0, POST={"to": u"test-user1", "subject": u"message~", "message": u"here is some text :3"}) info = pm_create(request) info = pm_list(testing.DummyRequest(user=self.user1)) self.assertIn("message~", [pm.subject for pm in info["pms"]])
def test_email_blank(self): DBSession.add(self.user1) request = testing.DummyRequest(referrer="/", matchdict={"name": u"test-user1"}, POST={"email": ""}) info = user_update(request) self.assertEqual(self.user1.email, None)
def setUp(self): VotaboTest.setUp(self) DBSession.add(self.user0) p1 = Post() p1.fingerprint = "5" * 32 p1.tags.append(Tag.get_or_create(u"test-tag")) p1.comments.append(Comment(self.user0, "0.0.0.0", u"Comment X")) p1.comments.append(Comment(self.user1, "0.0.0.0", u"Comment Y")) p1.comments.append(Comment(self.user0, "0.0.0.0", u"Comment Z")) p2 = Post() p2.fingerprint = "6" * 32 p2.tags.append(Tag.get_or_create(u"test-tag")) p3 = Post() p3.fingerprint = "7" * 32 p3.tags.append(Tag.get_or_create(u"test-tag")) p3.comments.append(Comment(self.user0, "0.0.0.0", u"First comment")) p3.comments.append(Comment(self.user1, "0.0.0.0", u"Another comment")) p3.comments.append(Comment(self.user2, "0.0.0.0", u"Third comment")) self.user0.posts.append(p1) self.user0.posts.append(p2) self.user0.posts.append(p3)
def test_other_read(self): DBSession.add( self.user2 ) # somehow this ends up not in the session after setUp() o_O request = testing.DummyRequest(user=self.user2, matchdict={"id": self.pm1.id}) self.assertRaises(HTTPForbidden, pm_read, request)
def setUp(self): VotaboTest.setUp(self) self.pm1 = PrivateMessage(user_from=self.user0, user_to=self.user1, subject=u"Hello", message=u"hi there~", is_read=True) self.pm2 = PrivateMessage(user_from=self.user1, user_to=self.user0, subject=u"Re: Hello", message=u"ho ho ho", is_read=True) self.pm3 = PrivateMessage(user_from=self.user0, user_to=self.user1, subject=u"Re: Hello", message=u"har har") DBSession.add_all([self.pm1, self.pm2, self.pm3])
def setUp(self): VotaboTest.setUp(self) wp1 = WikiPage() wp1.user = self.user0 wp1.title = u"index" wp1.revision = 2 wp1.body = u"This is the default wiki index page, v2" DBSession.add(wp1)
def test(self): DBSession.add(self.user0) comment = Comment(self.user0, "0.0.0.0", u"First comment") self.user0.posts[0].comments.append(comment) DBSession.flush() info = comment_delete(self.mockRequest(matchdict={"id": comment.id})) self.assertIsInstance(info, HTTPFound)
def setUp(self): VotaboTest.setUp(self) self.pm1 = PrivateMessage(user_from=self.user0, user_to=self.user1, subject=u"Re: Hello", message=u"har har") DBSession.add_all([self.pm1]) DBSession.flush()
def test_self_pass_missing(self): DBSession.add(self.user1) request = testing.DummyRequest(referrer="/", user=self.user1, matchdict={"name": u"_self"}, POST={ "email": "*****@*****.**", }) self.assertRaises(UserSettingsException, user_update, request)
def test_password_mismatch(self): DBSession.add(self.user1) original_password = self.user1.password request = testing.DummyRequest(referrer="/", matchdict={"name": u"test-user1"}, POST={ "new_password_1": "asdf1234", "new_password_2": "asdf5678", }) self.assertRaises(PasswordChangeException, user_update, request)
def test_other_delete(self): DBSession.add( self.user2 ) # somehow this ends up not in the session after setUp() o_O self.assertIn(self.pm1, pm_list(testing.DummyRequest(user=self.user1))["pms"]) self.assertRaises( HTTPForbidden, pm_delete, self.mockRequest(user=self.user2, matchdict={"id": self.pm1.id})) self.assertIn(self.pm1, pm_list(testing.DummyRequest(user=self.user1))["pms"])
def test_self_pass_ok(self): DBSession.add(self.user1) request = testing.DummyRequest(referrer="/", user=self.user1, matchdict={"name": u"_self"}, POST={ "current_password": "******", "email": "*****@*****.**", }) info = user_update(request) self.assertEqual(self.user1.email, "*****@*****.**")
def test_valid_send(self): DBSession.add(self.user0) request = self.mockRequest(user=self.user0, POST={ "to": u"test-user1", "subject": u"message~", "message": u"here is some text :3" }) info = pm_create(request) info = pm_list(testing.DummyRequest(user=self.user1)) self.assertIn("message~", [pm.subject for pm in info["pms"]])
def test_password_ok_other(self): DBSession.add(self.user1) original_password = self.user1.password request = testing.DummyRequest(referrer="/", matchdict={"name": u"test-user1"}, POST={ "new_password_1": "asdf1234", "new_password_2": "asdf1234", }) info = user_update(request) self.assertNotEqual(self.user1.password, original_password)
def test_password_ok_self(self): DBSession.add(self.user1) DBSession.add(self.user2) original_password1 = self.user1.password original_password2 = self.user2.password request = testing.DummyRequest(referrer="/", user=self.user2, matchdict={"name": u"_self"}, POST={ "current_password": "******", "new_password_1": "asdf1234", "new_password_2": "asdf1234", }) info = user_update(request) self.assertEqual(self.user1.password, original_password1) self.assertNotEqual(self.user2.password, original_password2)
def main(global_config, **settings): """ This function returns a Pyramid WSGI application. """ engine = engine_from_config(settings, 'sqlalchemy.') DBSession.configure(bind=engine) Base.metadata.bind = engine config = Configurator(settings=settings, root_factory='votabo.lib.security.RootFactory') config.add_static_view(name='static', path='votabo:static', cache_max_age=3600) configure_routes(config) configure_templates(config) configure_locale(config, settings) configure_cache(config, settings) configure_auth(config) configure_user(config) from .lib.hmom import HttpMethodOverrideMiddleware app = config.make_wsgi_app() app = HttpMethodOverrideMiddleware(app) return app
def setUp(self): VotaboTest.setUp(self) DBSession.add( LogEvent(section=u"sect1", username=u"test-admin", address=u"1.2.3.4", priority=0, message=u"test message 1")) DBSession.add( LogEvent(section=u"sect1", username=u"test-client", address=u"0.0.0.0", priority=0, message=u"test message 2")) DBSession.add( LogEvent(section=u"sect1", username=u"test-client", address=u"0.0.0.0", priority=0, message=u"test message 3"))
def setUp(self): VotaboTest.setUp(self) DBSession.add(Tag.get_or_create(u"apple")) DBSession.add(Tag.get_or_create(u"bacon")) DBSession.add(Tag.get_or_create(u"cat")) DBSession.add(Tag.get_or_create(u"kitten")) DBSession.add(Tag.get_or_create(u"pie")) DBSession.add(Tag.get_or_create(u"!!!"))
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) DBSession.add(self.user0) self.post = self.user0.posts[0]
def test_other_read(self): DBSession.add(self.user2) # somehow this ends up not in the session after setUp() o_O request = testing.DummyRequest(user=self.user2, matchdict={"id": self.pm1.id}) self.assertRaises(HTTPForbidden, pm_read, request)
def setUp(self): VotaboTest.setUp(self) DBSession.add(LogEvent(section=u"sect1", username=u"test-admin", address=u"1.2.3.4", priority=0, message=u"test message 1")) DBSession.add(LogEvent(section=u"sect1", username=u"test-client", address=u"0.0.0.0", priority=0, message=u"test message 2")) DBSession.add(LogEvent(section=u"sect1", username=u"test-client", address=u"0.0.0.0", priority=0, message=u"test message 3"))
def tearDown(self): DBSession.remove() testing.tearDown() cache.slow = cache.make_region() cache.fast = cache.make_region()
def test_basic(self): DBSession.add(self.user0) request = testing.DummyRequest(matchdict={"id": self.user0.posts[0].id}) info = post_read(request)
def test_other_delete(self): DBSession.add(self.user2) # somehow this ends up not in the session after setUp() o_O self.assertIn(self.pm1, pm_list(testing.DummyRequest(user=self.user1))["pms"]) self.assertRaises(HTTPForbidden, pm_delete, self.mockRequest(user=self.user2, matchdict={"id": self.pm1.id})) self.assertIn(self.pm1, pm_list(testing.DummyRequest(user=self.user1))["pms"])