def test_fail_register(self): r = YayClient.register(self.opts, ' ', '*****@*****.**', 'a', 'a') j = simplejson.loads(r.content) self.assertEqual(r.status_code, 401) r = YayClient.register(self.opts, 'my\'name', '*****@*****.**', 'a', 'a') j = simplejson.loads(r.content) self.assertEqual(r.status_code, 401)
def test_fail_register(self): r = YayClient.register(self.opts, ' ', '*****@*****.**', 'a', 'a') self.assertFalse(YayClient.is_logged_in(self.opts, r.cookies)) r = YayClient.register(self.opts, 'my\'name', '*****@*****.**', 'a', 'a') self.assertFalse(YayClient.is_logged_in(self.opts, r.cookies)) r = YayClient.register(self.opts, 'a b', '*****@*****.**', 'a', 'a') self.assertFalse(YayClient.is_logged_in(self.opts, r.cookies)) r = YayClient.register(self.opts, 'a_b', '*****@*****.**', 'a', 'a') self.assertFalse(YayClient.is_logged_in(self.opts, r.cookies)) r = YayClient.register(self.opts, 'a-b', '*****@*****.**', 'a', 'a') self.assertFalse(YayClient.is_logged_in(self.opts, r.cookies))
def setUpClass(cls): cls.opts = dict( url = 'http://yayhooray.dev/' ) user = YayClient.register(cls.opts, 'yay2tester', '*****@*****.**', 'a', 'a') thread = YayClient.post_thread(cls.opts, user.cookies, 2, "Test", "Test") cls.cookies = user.cookies cls.thread = urlparse(thread.url).path[1:]
def setUpClass(cls): cfg = SafeConfigParser() cfg.read(['../yay.ini', 'tests/yay.ini']) cls.opts = dict( url = cfg.get('site', 'url') ) DbClient.reset_database(cfg.get('db', 'host'), cfg.get('db', 'database'), cfg.get('db', 'username'), cfg.get('db', 'password')) user = YayClient.register(cls.opts, 'yay2tester', '*****@*****.**', 'a', 'a') thread = YayClient.post_thread(cls.opts, user.cookies, 2, "Test", "Test") cls.cookies = user.cookies cls.thread = urlparse(thread.url).path[1:]
def create_threads(opts, users, num): threads = [] for i in range(num): user = random.choice(users) thread = YayClient.post_thread(opts, user.cookies, random.randint(0, 4) + 1, thread_title_generator(), reply_generator()) threads.append(thread) return threads
def create_threads(opts, users, num): threads = [] for i in range(num): user = random.choice(users) thread = YayClient.post_thread(opts, user.cookies, 2, thread_title_generator(), reply_generator()) threads.append(thread) return threads
def test_yay_register(self): # register existing yay username r = YayClient.register(self.opts, 'dh', '*****@*****.**', 'a', 'a') j = simplejson.loads(r.content) self.assertEqual(j['method'], 'yaypm') self.assertEqual(r.status_code, 201) self.assertFalse(YayClient.is_logged_in(self.opts, r.cookies)) # attempt to login, should fail because not activated failed_login = YayClient.login(self.opts, 'dh', 'a') self.assertEqual(failed_login.status_code, 401) self.assertFalse(YayClient.is_logged_in(self.opts, failed_login.cookies)) # perform activation activate_url = OldYayClient.read_last_pm_link('yayname', 'yaypass') activate = requests.get(activate_url) self.assertEqual(activate.status_code, 200) # Yay, should now be able to login login = YayClient.login(self.opts, 'dh', 'a') self.assertEqual(login.status_code, 200) self.assertTrue(YayClient.is_logged_in(self.opts, login.cookies))
def create_users(opts, num): return [ YayClient.register(opts, user['name'], user['email'], user['password'], user['password']) for user in users_generator(num) ]
def test_forgot_password_wrong_username(self): r = YayClient.forgot_password(self.opts, '*****@*****.**') self.assertEqual(r.status_code, 412)
def test_forgot_password(self): YayClient.register(self.opts, 'emailtest', '*****@*****.**', 'a', 'a') r = YayClient.forgot_password(self.opts, '*****@*****.**') j = simplejson.loads(r.content) self.assertTrue(j['ok']) self.assertEqual(r.status_code, 200)
def test_failed_login(self): r = YayClient.login(self.opts, 'madeupname', 'madeuppass') self.assertEqual(r.status_code, 401) self.assertFalse(YayClient.is_logged_in(self.opts, r.cookies))
def test_new_register(self): r = YayClient.register(self.opts, 'neudjcshfo', '*****@*****.**', 'a', 'a') j = simplejson.loads(r.content) self.assertEqual(j['method'], 'plain') self.assertEqual(r.status_code, 201) self.assertTrue(YayClient.is_logged_in(self.opts, r.cookies))
def test_basic(self): r = YayClient.post_reply(self.opts, self.cookies, self.thread, "new post") self.assertEqual(r.status_code, 200)
def test_new_register(self): r = YayClient.register(self.opts, 'neudjcshfo', '*****@*****.**', 'a', 'a') self.assertTrue(YayClient.is_logged_in(self.opts, r.cookies)) r = YayClient.register(self.opts, 'a b', '*****@*****.**', 'a', 'a') self.assertTrue(YayClient.is_logged_in(self.opts, r.cookies))
def create_replies(opts, users, threads, num): for i in range(num): user = random.choice(users) thread = urlparse(random.choice(threads).url).path[1:] YayClient.post_reply(opts, user.cookies, thread, reply_generator())
def post_reply(self, content): r = YayClient.post_reply(self.opts, self.cookies, self.thread, content) tree = lxml.html.fromstring(r.content) return tree.cssselect(".comment")[-1].cssselect(".content")[0]