from . import util_accounts
from . import util

def test_no_content_submissions():
	client, user = util_accounts.create_test_client_and_user()

	title = '\u200e\u200e\u200e\u200e\u200e\u200e'
	body = util.generate_text()

	# test bad title against good content
	submit_post_response, _ = util.post_with_formkey(
		client, "/submit",
		data={
			"title": title,
			"body": body,
		}
	)

	assert submit_post_response.status_code == 400

	title, body = body, title
	# test good title against bad content
	submit_post_response, _ = util.post_with_formkey(
		client, "/submit",
		data={
			"title": title,
			"body": body,
		}
	)

	assert submit_post_response.status_code == 400

def test_no_content_comments():
	client, user = util_accounts.create_test_client_and_user()

	# make the post
	post_title = util.generate_text()
	post_body = util.generate_text()
	submit_post_response, _ = util.post_with_formkey(
		client, "/submit",
		data={
			"title": post_title,
			"body": post_body,
		}
	)

	assert submit_post_response.status_code == 200
	assert post_title in submit_post_response.text
	assert post_body in submit_post_response.text

	# verify it actually got posted
	root_response = client.get("/")
	assert root_response.status_code == 200
	assert post_title in root_response.text
	assert post_body in root_response.text

	# yank the ID out
	post = util.ItemData.from_html(submit_post_response.text)
	
	# post a comment child
	comment_body = '\ufeff\ufeff\ufeff\ufeff\ufeff'
	submit_comment_response, _ = util.post_with_formkey(
		client, "/comment",
		data={
			"parent_fullname": post.id_full,
			"parent_level": 1,
			"submission": post.id,
			"body": comment_body,
		}
	)
	assert submit_comment_response.status_code == 400
