def test_searchresults(self): category_key = self.categories.add("category") existing_tags = ["a new tag", "a new new tag"] existing_tag_keys = self.tags.add(existing_tags) self.posts.add("about", "body text", category_key, existing_tag_keys, "this is a summary") passed_days, remaining_days = calculate_work_date_stats() site_updated = self.posts.site_last_updated() flash(MSG) rendered_template = render_template("posts.html", user_status=users.is_current_user_admin(), siteupdated=site_updated, \ daysleft=remaining_days, dayspassed=passed_days, posts=self.posts.to_json(), codeversion=CODEVERSION, form=self.form) response = self.client.get(url_for('searchresults', q="body")) self.assertEqualHTML( response.data.decode('utf8'),rendered_template.decode('utf8'))
def test_view_filtered_posts_by_category(self): category_key = self.categories.add("a category") existing_tags = ["a new tag", "a new new tag"] existing_tag_keys = self.tags.add(existing_tags) self.posts.add("about", "body text", category_key, existing_tag_keys) second_tags = ["a new second tag", "a new new second tag"] second_tag_keys = self.tags.add(second_tags) self.posts.add("about second post", "body secod text", category_key, second_tag_keys) self.posts.filter_by_category('a category') passed_days, remaining_days = calculate_work_date_stats() site_updated = self.posts.site_last_updated() flash(MSG) rendered_template = render_template("posts.html", user_status=users.is_current_user_admin(), siteupdated=site_updated, \ daysleft=remaining_days, dayspassed=passed_days, tags=self.tags, categories=self.categories, posts=self.posts.to_json(), codeversion=CODEVERSION, form=self.form) response = self.client.get(path='/categories/a category') return self.assertEqualHTML(rendered_template.decode('utf8'), response.data.decode('utf8'))
def test_about_page(self): category_key = self.categories.add("category") existing_tags = ["a new tag", "a new new tag"] existing_tag_keys = self.tags.add(existing_tags) self.posts.add("about", "body text", category_key, existing_tag_keys, "this is a summary") requested_post = self.posts.get_by_title('about') response = self.client.get(url_for('aboutpage')) passed_days, remaining_days = calculate_work_date_stats() site_updated = self.posts.site_last_updated() flash(MSG) rendered_template = render_template('about.html',user_status=users.is_current_user_admin(), siteupdated=site_updated,\ daysleft=remaining_days,dayspassed=passed_days,Post=requested_post, codeversion=CODEVERSION) self.assertEqualHTML(rendered_template.decode('utf8'), response.data.decode('utf8'))
def test_about_page(self): category_key = self.categories.add("category") existing_tags = ["a new tag", "a new new tag"] existing_tag_keys = self.tags.add(existing_tags) self.posts.add("about", "body text", category_key, existing_tag_keys, "this is a summary") requested_post = self.posts.get_by_title('about') response = self.client.get(url_for('aboutpage')) passed_days, remaining_days = calculate_work_date_stats() site_updated = self.posts.site_last_updated() flash(MSG) rendered_template = render_template('about.html',user_status=users.is_current_user_admin(), siteupdated=site_updated,\ daysleft=remaining_days,dayspassed=passed_days,Post=requested_post, codeversion=CODEVERSION) self.assertEqualHTML(rendered_template.decode('utf8'), response.data.decode('utf8'))
def test_searchresults(self): category_key = self.categories.add("category") existing_tags = ["a new tag", "a new new tag"] existing_tag_keys = self.tags.add(existing_tags) self.posts.add("about", "body text", category_key, existing_tag_keys, "this is a summary") passed_days, remaining_days = calculate_work_date_stats() site_updated = self.posts.site_last_updated() flash(MSG) rendered_template = render_template("posts.html", user_status=users.is_current_user_admin(), siteupdated=site_updated, \ daysleft=remaining_days, dayspassed=passed_days, posts=self.posts.to_json(), codeversion=CODEVERSION, form=self.form, uploadform=self.uploadform) response = self.client.get(url_for('searchresults', q="body")) self.assertEqualHTML( response.data.decode('utf8'),rendered_template.decode('utf8'))
def test_view_filtered_posts_by_category(self): category_key = self.categories.add("a category") existing_tags = ["a new tag", "a new new tag"] existing_tag_keys = self.tags.add(existing_tags) self.posts.add("about", "body text", category_key, existing_tag_keys) second_tags = ["a new second tag", "a new new second tag"] second_tag_keys = self.tags.add(second_tags) self.posts.add("about second post", "body secod text", category_key, second_tag_keys) self.posts.filter_by_category('a category') passed_days, remaining_days = calculate_work_date_stats() site_updated = self.posts.site_last_updated() flash(MSG) rendered_template = render_template("posts.html", user_status=users.is_current_user_admin(), siteupdated=site_updated, \ daysleft=remaining_days, dayspassed=passed_days, tags=self.tags, categories=self.categories, posts=self.posts.to_json(), codeversion=CODEVERSION, form=self.form, uploadform=self.uploadform) response = self.client.get(path='/categories/a category') return self.assertEqualHTML(rendered_template.decode('utf8'), response.data.decode('utf8'))
def test_questions_view(self): category_key = self.categories.add("reconstructing a test") test_tags = ["a new tag", "a new new tag"] new_tag_keys = self.tags.add(test_tags) self.posts.add("a title", "body text", category_key, new_tag_keys, "this is a summary", [{"p_answer": "ans1", "is_correct": True}, {"p_answer": "ans2", "is_correct": False}]) category_key = self.categories.add("reconstructing a test") test_tags = ["a tag"] new_tag_keys = self.tags.add(test_tags) self.posts.add("a title here", "body to test the question text", category_key, new_tag_keys, "this is a summary", [{"p_answer": "a test answ correct", "is_correct": True}, {"p_answer": "a wrong tet answer", "is_correct": False}]) response = self.client.get(path="/questions/reconstructing a test") self.posts.filter_by_category("reconstructing a test") flash(MSG) passed_days, remaining_days = calculate_work_date_stats() site_updated = self.posts.site_last_updated() self.posts.to_answers_form() rendered_template = render_template("questions.html", user_status=users.is_current_user_admin(), siteupdated=site_updated, \ daysleft=remaining_days, dayspassed=passed_days, tags=self.tags, categories=self.categories, posts=self.posts, codeversion=CODEVERSION) return self.assertEqualHTML(rendered_template.decode('utf8'), response.data.decode('utf8'))
def test_archives_url_content_is_ok(self): category_key = self.categories.add("category") test_tags = ["a new tag", "a new new tag"] new_tag_keys = self.tags.add(test_tags) self.posts.add("a title", "body text", category_key, new_tag_keys, "this is a summary") passed_days, remaining_days = calculate_work_date_stats() flash(MSG) response = self.client.get((url_for('archives'))) post_tag_names = self.tags.to_json() site_updated = self.posts.site_last_updated() posts_json = self.posts.to_json() rendered_template = render_template('archives.html', user_status=users.is_current_user_admin(), siteupdated=site_updated, \ daysleft=remaining_days, dayspassed=passed_days, tags=self.tags, categories=self.categories, posts=posts_json, codeversion=CODEVERSION, form=self.form, posts_tags_names=post_tag_names) self.assertEqualHTML(rendered_template, response.data.decode('utf-8'))
def test_archives_url_content_is_ok(self): category_key = self.categories.add("category") test_tags = ["a new tag", "a new new tag"] new_tag_keys = self.tags.add(test_tags) self.posts.add("a title", "body text", category_key, new_tag_keys, "this is a summary") passed_days, remaining_days = calculate_work_date_stats() flash(MSG) response = self.client.get((url_for('archives'))) post_tag_names = self.tags.to_json() site_updated = self.posts.site_last_updated() posts_json = self.posts.to_json() rendered_template = render_template('archives.html', user_status=users.is_current_user_admin(), siteupdated=site_updated, \ daysleft=remaining_days, dayspassed=passed_days, tags=self.tags, categories=self.categories, posts=posts_json, codeversion=CODEVERSION, form=self.form, uploadform=self.uploadform, posts_tags_names=post_tag_names) self.assertEqualHTML(rendered_template, response.data.decode('utf-8'))
def test_questions_view(self): category_key = self.categories.add("reconstructing a test") test_tags = ["a new tag", "a new new tag"] new_tag_keys = self.tags.add(test_tags) self.posts.add("a title", "body text", category_key, new_tag_keys, "this is a summary", [{"p_answer": "ans1", "is_correct": True}, {"p_answer": "ans2", "is_correct": False}]) category_key = self.categories.add("reconstructing a test") test_tags = ["a tag"] new_tag_keys = self.tags.add(test_tags) self.posts.add("a title here", "body to test the question text", category_key, new_tag_keys, "this is a summary", [{"p_answer": "a test answ correct", "is_correct": True}, {"p_answer": "a wrong tet answer", "is_correct": False}]) response = self.client.get(path="/questions/reconstructing a test") self.posts.filter_by_category("reconstructing a test") flash(MSG) passed_days, remaining_days = calculate_work_date_stats() site_updated = self.posts.site_last_updated() self.posts.to_answers_form() rendered_template = render_template("questions.html", user_status=users.is_current_user_admin(), siteupdated=site_updated, \ daysleft=remaining_days, dayspassed=passed_days, tags=self.tags, categories=self.categories, posts=self.posts, codeversion=CODEVERSION) self.assertEqualHTML(rendered_template.decode('utf8'), response.data.decode('utf8'))
def test_tag_pag_returns_correct_html(self): passed_days, remaining_days = calculate_work_date_stats() response = self.client.get((url_for('index'))) # create a request object site_updated = self.posts.site_last_updated() flash(MSG) rendered_template = render_template("posts.html", user_status=users.is_current_user_admin(), siteupdated=site_updated, \ daysleft=remaining_days, dayspassed=passed_days, tags=self.tags, categories=self.categories, posts=self.posts.to_json(), codeversion=CODEVERSION, form=self.form) self.assertEqualHTML(rendered_template, response.data.decode('utf-8'))
def test_categories_view(self): passed_days, remaining_days = calculate_work_date_stats() response = self.client.get((url_for('view_all_categories'))) site_updated = self.posts.site_last_updated() flash(MSG) rendered_template = render_template('categories.html', user_status=users.is_current_user_admin(),siteupdated=site_updated,\ daysleft=remaining_days,dayspassed=passed_days,tags=self.tags.to_json(), codeversion=CODEVERSION) self.assertEqualHTML(rendered_template, response.data.decode('utf-8'))
def test_tag_pag_returns_correct_html(self): passed_days, remaining_days = calculate_work_date_stats() response = self.client.get((url_for('index'))) # create a request object site_updated = self.posts.site_last_updated() flash(MSG) rendered_template = render_template("posts.html", user_status=users.is_current_user_admin(), siteupdated=site_updated, \ daysleft=remaining_days, dayspassed=passed_days, tags=self.tags, categories=self.categories, posts=self.posts.to_json(), codeversion=CODEVERSION, form=self.form, uploadform=self.uploadform) self.assertEqualHTML(rendered_template, response.data.decode('utf-8'))
def test_categories_view(self): passed_days, remaining_days = calculate_work_date_stats() response = self.client.get((url_for('view_all_categories'))) site_updated = self.posts.site_last_updated() flash(MSG) rendered_template = render_template('categories.html', user_status=users.is_current_user_admin(),siteupdated=site_updated,\ daysleft=remaining_days,dayspassed=passed_days,tags=self.tags.to_json(), codeversion=CODEVERSION) self.assertEqualHTML(rendered_template, response.data.decode('utf-8'))
def test_selected_post_page_returns_correct_html(self): passed_days, remaining_days = calculate_work_date_stats() category_key = self.categories.add("category") test_tags = ["a new tag", "a new new tag"] new_tag_keys = self.tags.add(test_tags) self.posts.add("a title", "body text", category_key, new_tag_keys, "this is a summary") current_post = self.posts.get_by_title("a title") post_tag_names = current_post.get_tag_names() other_posts_tags = self.posts.get_other_tags(current_post.key.id()) related_posts = [] with open(os.path.join(TEST_IMAGE)) as f: self.assertTrue(current_post.add_blob(f.read(), TEST_IMAGE, 'image/jpeg')) response = self.client.get(url_for('view_a_post', category="category", year=current_post.timestamp.year, month=current_post.timestamp.month, title="a title")) for post in self.posts: if post.key != current_post.key: for tag in post.tags: if tag in other_posts_tags: related_posts.append(post) category = post.category.get().category site_updated = self.posts.site_last_updated() flash(MSG) answers_form = AnswerRadioForm() answers_form.r_answers.choices = [("t", answer.p_answer) for answer in current_post.answers] rendered_template = render_template('singlepost.html', user_status=users.is_current_user_admin(), siteupdated=site_updated, \ daysleft=remaining_days, dayspassed=passed_days, RelatedPosts=related_posts, \ Post=current_post.to_json(), posttagnames=post_tag_names, category=category, answers_field=answers_form) self.assertEqual(rendered_template.encode("utf-8"), response.data)
def test_selected_post_page_returns_correct_html(self): passed_days, remaining_days = calculate_work_date_stats() category_key = self.categories.add("category") test_tags = ["a new tag", "a new new tag"] new_tag_keys = self.tags.add(test_tags) self.posts.add("a title", "body text", category_key, new_tag_keys, "this is a summary") current_post = self.posts.get_by_title("a title") post_tag_names = current_post.get_tag_names() other_posts_tags = self.posts.get_other_tags(current_post.key.id()) related_posts = [] response = self.client.get(url_for('view_a_post', category="category", year=current_post.timestamp.year, month=current_post.timestamp.month, title="a title")) for post in self.posts: if post.key != current_post.key: for tag in post.tags: if tag in other_posts_tags: related_posts.append(post) category = post.category.get().category site_updated = self.posts.site_last_updated() flash(MSG) answers_form = AnswerRadioForm() answers_form.r_answers.choices = [("t", answer.p_answer) for answer in current_post.answers] rendered_template = render_template('singlepost.html', user_status=users.is_current_user_admin(), siteupdated=site_updated, \ daysleft=remaining_days, dayspassed=passed_days, RelatedPosts=related_posts, \ Post=current_post.to_json(), posttagnames=post_tag_names, category=category, answers_field = answers_form) self.assertEqual(rendered_template.encode("utf-8"), response.data)
def test_index_page_with_content_is_ok(self): category_key = self.categories.add("category") test_tags = ["a new tag", "a new new tag"] new_tag_keys = self.tags.add(test_tags) self.posts.add("a title", "body text", category_key, new_tag_keys, "this is a summary") passed_days, remaining_days = calculate_work_date_stats() response = self.client.get((url_for('index'))) # create a request object site_updated = self.posts.site_last_updated() flash(MSG) rendered_template = render_template("posts.html", user_status=users.is_current_user_admin(), siteupdated=site_updated, daysleft=remaining_days, dayspassed=passed_days, tags=self.tags, categories=self.categories, posts=self.posts.to_json(), codeversion=CODEVERSION, form=self.form) self.assertEqualHTML(rendered_template.decode('utf-8'), response.data.decode('utf-8'))
def test_select_post_with_related_posts_returns_correct_html(self): passed_days, remaining_days = calculate_work_date_stats() category_key = self.categories.add("category") test_tags = ["a new tag", "a new new tag"] new_tag_keys = self.tags.add(test_tags) self.posts.add("a title", "body text", category_key, new_tag_keys, "this is a summary") test_tags_related = ["a new tag", "a different tag"] new_rel_tag_keys = self.tags.add(test_tags_related) self.posts.add("a better title", "body without text", category_key, new_rel_tag_keys, "this is new a summary") current_post = self.posts.get_by_title("a title") post_tag_names = current_post.get_tag_names() other_posts_tags = self.posts.get_other_tags(current_post.key.id()) response = self.client.get(url_for('view_a_post', category="category", year=current_post.timestamp.year, month=current_post.timestamp.month, title="a title")) related_posts = self.posts.get_related_posts(current_post.id) category = current_post.category.get().category site_updated = self.posts.site_last_updated() flash(MSG) answers_form = AnswerRadioForm() answers_form.r_answers.choices = [("t", answer.p_answer) for answer in current_post.answers] rendered_template = render_template('singlepost.html', user_status=users.is_current_user_admin(), siteupdated=site_updated, \ daysleft=remaining_days, dayspassed=passed_days, RelatedPosts=related_posts, \ Post=current_post.to_json(), posttagnames=post_tag_names, category=category, answers_field=answers_form) self.assertEqual(rendered_template.encode("utf-8"), response.data)
def test_archives_url_resolves_to_archive_page(self): passed_days, remaining_days = calculate_work_date_stats() flash(MSG) response = self.client.get((url_for('archives'))) post_tag_names = self.tags.to_json() site_updated = self.posts.site_last_updated() posts_json = self.posts.to_json() rendered_template = render_template('archives.html', user_status=users.is_current_user_admin(), siteupdated=site_updated, \ daysleft=remaining_days, dayspassed=passed_days, tags=self.tags, categories=self.categories, posts=posts_json, codeversion=CODEVERSION, form=self.form, posts_tags_names=post_tag_names) self.assertEqualHTML(rendered_template, response.data.decode('utf-8'))
def test_archives_url_resolves_to_archive_page(self): passed_days, remaining_days = calculate_work_date_stats() flash(MSG) response = self.client.get((url_for('archives'))) post_tag_names = self.tags.to_json() site_updated = self.posts.site_last_updated() posts_json = self.posts.to_json() rendered_template = render_template('archives.html', user_status=users.is_current_user_admin(), siteupdated=site_updated, \ daysleft=remaining_days, dayspassed=passed_days, tags=self.tags, categories=self.categories, posts=posts_json, codeversion=CODEVERSION, form=self.form, uploadform=self.uploadform, posts_tags_names=post_tag_names) self.assertEqualHTML(rendered_template, response.data.decode('utf-8'))
def test_edit_a_post_view(self): category_key = self.categories.add("category") existing_tags = ["a new tag", "a new new tag"] existing_tag_keys = self.tags.add(existing_tags) post_key = self.posts.add("a title", "body text", category_key, existing_tag_keys, "this is a summary") response = self.client.get(url_for('edit_a_post_view', postkey=post_key)) flash(MSG) site_updated = self.posts.site_last_updated() passed_days, remaining_days = calculate_work_date_stats() rendered_template = render_template('posts.html', user_status=users.is_current_user_admin(), siteupdated=site_updated, \ daysleft=remaining_days, dayspassed=passed_days, codeversion=CODEVERSION, form=self.form) self.assertEqualHTML(rendered_template.decode('utf8'), response.data.decode('utf8'))
def test_edit_a_post_view(self): category_key = self.categories.add("category") existing_tags = ["a new tag", "a new new tag"] existing_tag_keys = self.tags.add(existing_tags) post_key = self.posts.add("a title", "body text", category_key, existing_tag_keys, "this is a summary") response = self.client.get(url_for('edit_a_post_view', postkey=post_key)) flash(MSG) site_updated = self.posts.site_last_updated() passed_days, remaining_days = calculate_work_date_stats() rendered_template = render_template('posts.html', user_status=users.is_current_user_admin(), siteupdated=site_updated, \ daysleft=remaining_days, dayspassed=passed_days, codeversion=CODEVERSION, form=self.form, uploadform=self.uploadform) self.assertEqualHTML(rendered_template.decode('utf8'), response.data.decode('utf8'))