def test_edit_title_fail(self): r = YayAPIClient.register(self.opts, 'testsettitle1', '*****@*****.**', 'a', 'a') r = YayAPIClient.edit_title(self.opts, r.cookies, "") j = json.loads(r.content) self.assertEqual(r.status_code, 412) self.assertTrue('error' in j)
def test_view_user(self): u = YayAPIClient.register(self.opts, 'testviewuser1', '*****@*****.**', 'a', 'a') r = YayAPIClient.get_user(self.opts, 'testviewuser1') j = json.loads(r.content) self.assertEqual(r.status_code, 200) self.assertTrue('id' in j) self.assertEqual('testviewuser1', j['username'])
def test_create_thread(self): r = YayAPIClient.register(self.opts, 'testcreatethread1', '*****@*****.**', 'a', 'a') for i in xrange(1, 5): r = YayAPIClient.post_thread(self.opts, r.cookies, i, 'testcreatethread1 ' + str(i), 'testcreatethread1 ' + str(i) + ' body') j = json.loads(r.content) self.assertEqual(r.status_code, 201) self.assertTrue('thread_id' in j)
def test_edit_title(self): r = YayAPIClient.register(self.opts, 'testsettitle1', '*****@*****.**', 'a', 'a') r = YayAPIClient.edit_title(self.opts, r.cookies, "foo") j = json.loads(r.content) self.assertEqual(r.status_code, 200) self.assertFalse('error' in j) self.assertTrue('ok' in j) self.assertTrue('title' in j)
def test_forgot_password(self): YayAPIClient.register(self.opts, 'testforgotpassword1', '*****@*****.**', 'a', 'a') r = YayAPIClient.forgot_password(self.opts, '*****@*****.**') j = json.loads(r.content) self.assertEqual(r.status_code, 200) self.assertFalse('error' in j) self.assertTrue('ok' in j)
def test_login(self): YayAPIClient.register(self.opts, 'testlogin1', '*****@*****.**', 'a', 'a') r = YayAPIClient.login(self.opts, 'testlogin1', 'a') j = json.loads(r.content) self.assertEqual(r.status_code, 200) self.assertFalse('error' in j) self.assertTrue('ok' in j) self.assertTrue('user_id' in j) self.assertEqual(j['username'], 'testlogin1')
def test_view_thread(self): r = YayAPIClient.register(self.opts, 'testviewthread1', '*****@*****.**', 'a', 'a') r = YayAPIClient.post_thread(self.opts, r.cookies, 1, 'testviewthread1 1', 'testviewthread1 1 body') j = json.loads(r.content) r = YayAPIClient.get_thread(self.opts, j['thread_id']) j = json.loads(r.content) self.assertEqual(r.status_code, 200) self.assertTrue('comments' in j) self.assertEqual(j['pagination']['row_count'], 1)
def test_logout(self): r = YayAPIClient.register(self.opts, 'testlogout1', '*****@*****.**', 'a', 'a') self.assertTrue(YayAPIClient.is_logged_in(self.opts, r.cookies)) r = YayAPIClient.logout(self.opts, r.cookies) j = json.loads(r.content) self.assertEqual(r.status_code, 200) self.assertFalse('error' in j) self.assertTrue('ok' in j) self.assertFalse(YayAPIClient.is_logged_in(self.opts, r.cookies))
def test_list_messages_outbox(self): self.reset() u1 = YayAPIClient.register(self.opts, 'testlistmessagesoutbox1', '*****@*****.**', 'a', 'a') u2 = YayAPIClient.register(self.opts, 'testlistmessagesoutbox2', '*****@*****.**', 'a', 'a') r = YayAPIClient.send_message(self.opts, u2.cookies, 'testlistmessagesoutbox1', 'subject', 'body') r = YayAPIClient.get_outbox(self.opts, u2.cookies) j = json.loads(r.content) self.assertEqual(r.status_code, 200) self.assertTrue('messages' in j) self.assertEqual(len(j['messages']), 1)
def test_edit_comment(self): r = YayAPIClient.register(self.opts, 'testeditcomment1', '*****@*****.**', 'a', 'a') r = YayAPIClient.post_thread(self.opts, r.cookies, 1, 'testeditcomment1 1', 'testeditcomment1 1 body') j = json.loads(r.content) r = YayAPIClient.post_comment(self.opts, r.cookies, j['thread_id'], 'testeditcomment1 1 reply') j = json.loads(r.content) r = YayAPIClient.edit_comment(self.opts, r.cookies, j['comment_id'], 'testeditcomment1 1 reply edit') j = json.loads(r.content) self.assertEqual(r.status_code, 201) self.assertTrue('comment_id' in j) self.assertTrue('thread_id' in j)
def test_create_thread(self): r = YayAPIClient.register(self.opts, 'testcreatethread1', '*****@*****.**', 'a', 'a') for i in xrange(1, 5): r = YayAPIClient.post_thread( self.opts, r.cookies, i, 'testcreatethread1 ' + str(i), 'testcreatethread1 ' + str(i) + ' body') j = json.loads(r.content) self.assertEqual(r.status_code, 201) self.assertTrue('thread_id' in j)
def test_forgot_password_fail(self): YayAPIClient.register(self.opts, 'testforgotpasswordfail1', '*****@*****.**', 'a', 'a') r = YayAPIClient.forgot_password(self.opts, '*****@*****.**') j = json.loads(r.content) self.assertEqual(r.status_code, 412) self.assertTrue('error' in j) r = YayAPIClient.forgot_password(self.opts, '*****@*****.**', 'xxx') j = json.loads(r.content) self.assertEqual(r.status_code, 412) self.assertTrue('error' in j)
def test_create_message(self): self.reset() u1 = YayAPIClient.register(self.opts, 'testcreatemessage1', '*****@*****.**', 'a', 'a') u2 = YayAPIClient.register(self.opts, 'testcreatemessage2', '*****@*****.**', 'a', 'a') r = YayAPIClient.get_inbox(self.opts, u1.cookies) j = json.loads(r.content) self.assertEqual(r.status_code, 200) self.assertTrue('messages' in j) self.assertEqual(len(j['messages']), 0) r = YayAPIClient.send_message(self.opts, u2.cookies, 'testcreatemessage1', 'subject', 'body') j = json.loads(r.content) self.assertEqual(r.status_code, 201) self.assertTrue('message_id' in j)
def test_forgot_password_fail(self): YayAPIClient.register(self.opts, 'testforgotpasswordfail1', '*****@*****.**', 'a', 'a') r = YayAPIClient.forgot_password(self.opts, '*****@*****.**') j = json.loads(r.content) self.assertEqual(r.status_code, 412) self.assertTrue('error' in j) r = YayAPIClient.forgot_password( self.opts, '*****@*****.**', 'xxx') j = json.loads(r.content) self.assertEqual(r.status_code, 412) self.assertTrue('error' in j)
def test_register_fail(self): r = YayAPIClient.register(self.opts, ' ', '*****@*****.**', 'a', 'a') j = json.loads(r.content) self.assertTrue('errors' in j) self.assertTrue('username' in j['errors']) r = YayAPIClient.register(self.opts, 'my\'name', '*****@*****.**', 'a', 'a') j = json.loads(r.content) self.assertTrue('errors' in j) self.assertTrue('username' in j['errors']) r = YayAPIClient.register(self.opts, 'a b', '*****@*****.**', 'a', 'a') j = json.loads(r.content) self.assertTrue('errors' in j) self.assertTrue('username' in j['errors']) r = YayAPIClient.register(self.opts, 'a_b', '*****@*****.**', 'a', 'a') j = json.loads(r.content) self.assertTrue('errors' in j) self.assertTrue('username' in j['errors']) r = YayAPIClient.register(self.opts, 'a-b', '*****@*****.**', 'a', 'a') j = json.loads(r.content) self.assertTrue('errors' in j) self.assertTrue('username' in j['errors']) r = YayAPIClient.register(self.opts, 'abb', 'facom', 'a', 'a') j = json.loads(r.content) self.assertTrue('errors' in j) self.assertTrue('email' in j['errors']) r = YayAPIClient.register(self.opts, 'abc', '*****@*****.**', 'a', 'b') j = json.loads(r.content) self.assertTrue('errors' in j) self.assertTrue('confirm-password' in j['errors'])
def test_list_threads(self): self.reset() r = YayAPIClient.register(self.opts, 'testlistthreads1', '*****@*****.**', 'a', 'a') r = YayAPIClient.post_thread(self.opts, r.cookies, 1, 'testlistthreads1 1', 'testlistthreads1 1 body') r = YayAPIClient.post_thread(self.opts, r.cookies, 1, 'testlistthreads1 2', 'testlistthreads1 2 body') r = YayAPIClient.post_thread(self.opts, r.cookies, 1, 'testlistthreads1 3', 'testlistthreads1 3 body') r = YayAPIClient.post_thread(self.opts, r.cookies, 1, 'testlistthreads1 4', 'testlistthreads1 4 body') r = YayAPIClient.list_threads(self.opts) j = json.loads(r.content) self.assertEqual(r.status_code, 200) self.assertTrue('threads' in j) self.assertEqual(j['pagination']['row_count'], 4)
def test_list_threads_in_category(self): self.reset() r = YayAPIClient.register(self.opts, 'testlistthreadsincategory1', '*****@*****.**', 'a', 'a') r = YayAPIClient.post_thread(self.opts, r.cookies, 1, 'testlistthreadsincategory1 1', 'testlistthreadsincategory1 1 body') r = YayAPIClient.post_thread(self.opts, r.cookies, 2, 'testlistthreadsincategory1 2', 'testlistthreadsincategory1 2 body') r = YayAPIClient.post_thread(self.opts, r.cookies, 3, 'testlistthreadsincategory1 3', 'testlistthreadsincategory1 3 body') r = YayAPIClient.post_thread(self.opts, r.cookies, 4, 'testlistthreadsincategory1 4', 'testlistthreadsincategory1 4 body') r = YayAPIClient.list_threads(self.opts, None, 'discussions') j = json.loads(r.content) self.assertEqual(r.status_code, 200) self.assertTrue('threads' in j) self.assertEqual(j['pagination']['row_count'], 1)
def test_paginate_threads_in_search(self): self.reset() r = YayAPIClient.register(self.opts, 'testpaginatethreadsinsearch1', '*****@*****.**', 'a', 'a') r = YayAPIClient.post_thread(self.opts, r.cookies, 1, 'testpaginatethreadsinsearch1 1', 'testpaginatethreadsinsearch1 1 body') r = YayAPIClient.post_thread(self.opts, r.cookies, 2, 'testpaginatethreadsinsearch1 2', 'testpaginatethreadsinsearch1 2 body') r = YayAPIClient.post_thread(self.opts, r.cookies, 3, 'testpaginatethreadsinsearch1 3', 'testpaginatethreadsinsearch1 3 body') r = YayAPIClient.post_thread(self.opts, r.cookies, 4, 'testpaginatethreadsinsearch1 4', 'testpaginatethreadsinsearch1 4 body') r = YayAPIClient.search(self.opts, 'foo', 100) j = json.loads(r.content) self.assertEqual(r.status_code, 200) self.assertTrue('threads' in j) self.assertEqual(j['pagination']['current_page'], 2)
def test_paginate_threads(self): self.reset() r = YayAPIClient.register(self.opts, 'testpaginatethreads1', '*****@*****.**', 'a', 'a') r = YayAPIClient.post_thread(self.opts, r.cookies, 1, 'testpaginatethreads1 1', 'testpaginatethreads1 1 body') r = YayAPIClient.post_thread(self.opts, r.cookies, 2, 'testpaginatethreads1 2', 'testpaginatethreads1 2 body') r = YayAPIClient.post_thread(self.opts, r.cookies, 3, 'testpaginatethreads1 3', 'testpaginatethreads1 3 body') r = YayAPIClient.post_thread(self.opts, r.cookies, 4, 'testpaginatethreads1 4', 'testpaginatethreads1 4 body') r = YayAPIClient.list_threads(self.opts, 100) j = json.loads(r.content) self.assertEqual(r.status_code, 200) self.assertTrue('threads' in j) self.assertEqual(j['pagination']['current_page'], 2)
def test_list_threads_in_search(self): self.reset() r = YayAPIClient.register(self.opts, 'testlistthreadsinsearch1', '*****@*****.**', 'a', 'a') r = YayAPIClient.post_thread(self.opts, r.cookies, 1, 'testlistthreadsinsearch1 1', 'testlistthreadsinsearch1 1 body') r = YayAPIClient.post_thread(self.opts, r.cookies, 2, 'teXstlistthreadsinsearch1 2', 'testlistthreadsinsearch1 2 body') r = YayAPIClient.post_thread(self.opts, r.cookies, 3, 'testlistthreadsinsearch1 3', 'testlistthreadsinsearch1 3 body') r = YayAPIClient.post_thread(self.opts, r.cookies, 4, 'teXstlistthreadsinsearch1 4', 'testlistthreadsinsearch1 4 body') r = YayAPIClient.search(self.opts, 'teXst') j = json.loads(r.content) self.assertEqual(r.status_code, 200) self.assertTrue('threads' in j) self.assertEqual(j['pagination']['row_count'], 2)
def test_login_fail(self): r = YayAPIClient.login(self.opts, 'madeupname', 'madeuppass') j = json.loads(r.content) self.assertEqual(r.status_code, 401) self.assertTrue('error' in j)
def test_forgot_password_key(self): r = YayAPIClient.forgot_password_key(self.opts) j = json.loads(r.content) self.assertEqual(r.status_code, 200) self.assertTrue('key' in j)