def test_asc(): result = posts.get_posts(['tech']) assert_that(result).is_length(4) for i in range(len(result) - 1): assert_that(result[i]['id']).is_less_than_or_equal_to(result[i + 1]['id']) print('ASCENDING SORT WORKS')
def test_desc(): result = posts.get_posts(['tech'], ascending=False) assert_that(result).is_length(4) for i in range(len(result) - 1): assert_that(result[i]['id']).is_greater_than_or_equal_to( result[i + 1]['id']) print('DESCENDING SORT WORKS')
def test_basic(): result = posts.get_posts(['sanity']) assert_that(result[0]).is_equal_to({ 'id': 100, 'tags': ['sanity'], 'reads': 100 }) print('BASIC PASSED - handler\'s being tested')
def get_posts(): requestdata, valid = validate_request(request) if not valid: return invalid_response(requestdata) theposts = posts.get_posts(tags=requestdata['tags'], sortfield=requestdata['sortfield'], ascending=(requestdata['direction'] == 'asc')) return post_response(theposts)
def test_sortfield(): sortfield = 'reads' result = posts.get_posts(['tech'], sortfield=sortfield) assert_that(result).is_length(4) for i in range(len(result) - 1): assert_that(result[i]['id']).is_less_than_or_equal_to( result[i + 1][sortfield]) print('SORTBY WORKS')
def channel(channel_name): list = posts.get_posts(channel_name) title = "/ch/" + channel_name if channels.is_channel(channel_name): return render_template("feed_layout.html", channel_name=channel_name, posts=list, title=title) else: flash("Kanavaa " + channel_name + " ei ole olemassa") return redirect("/")
def main(): if not is_logged_in(): return redirect(url_for('login')) the_posts = posts.get_posts(get_logged_in_user()) date_posts = posts.group_posts_by_date(the_posts) context = { 'dates': sorted(date_posts.keys(), reverse=True), 'date_posts': date_posts, 'empty': len(the_posts) == 0 } return render_template("main.html", **context)
def index(): return render_template("index.html", site_title="Lucas Blog - Softwareentwicklung", og={ "title": "Lucas Blog - Softwareentwicklung", "description": "Auf dem Blog von Lucas Hild findest Du Artikel über Softwareentwicklung mit Python, JavaScript und dem Raspberry Pi", "image": url_for("static", filename="img/header.jpg"), "url": "https://blog.lucas-hild.de", "type": "blog" }, seo_description="Auf dem Blog von Lucas Hild findest Du Artikel über Softwareentwicklung mit Python, JavaScript und dem Raspberry Pi", header_title="Lucas Blog", header_image=url_for("static", filename="img/header.jpg"), posts=posts.get_posts())
def atom_feed(): feed = AtomFeed("Lucas Blog", feed_url="https://blog.lucas-hild.de/feed") for post in posts.get_posts(): feed.add(title=post["title"], title_type="text", subtitle="Softwareentwicklung", content=post["content"], content_type="html", summary=post["description"], summary_type="text", url="https://blog.lucas-hild.de/" + post["permalink"], author="Lucas Hild", published=post["date_time"], updated=post["date_time"]) return feed.get_response()
def index(): if check_user(): if 'submitpost' in request.form: posts.make_post( request.form['title'], session['user'], request.form['content']) if 'submitcomment' in request.form: posts.make_comment( request.form['postid'], session['user'], request.form['content']) if 'deletepost' in request.form: posts.delete_post(request.form['postid']) return render_template( "home.html", posts = posts.get_posts(request.args.get('query')), user = session['user'], query = request.args.get('query'))
def post_view(permalink): post_details = posts.get_post(permalink) if post_details: return render_template("post.html", site_title=post_details["title"] + " | Lucas Blog", og={ "title": post_details["title"] + "| Lucas Blog", "description": post_details["description"], "image": "https://blog.lucas-hild.de" + post_details["image"], "url": "https://blog.lucas-hild.de" + "/" + permalink, "type": "article" }, seo_description="Auf dem Blog von Lucas Hild findest Du Artikel über Softwareentwicklung mit Python, JavaScript und dem Raspberry Pi", header_title=post_details["title"], header_text=post_details["date"], header_image=post_details["image"], title=post_details["title"], date=post_details["title"], image=post_details["image"], description=post_details["description"], content=post_details["content"]) else: return render_template("index.html", site_title="404 | Lucas Blog", og={ "title": "Lucas Blog - Softwareentwicklung", "description": "Auf dem Blog von Lucas Hild findest Du Artikel über Softwareentwicklung mit Python, JavaScript und dem Raspberry Pi", "image": url_for("static", filename="img/404.jpg"), "url": "https://blog.lucas-hild.de", "type": "blog" }, seo_description="Auf dem Blog von Lucas Hild findest Du Artikel über Softwareentwicklung mit Python, JavaScript und dem Raspberry Pi", header_title="Seite nicht gefunden", header_image=url_for("static", filename="img/404.jpg"), posts=posts.get_posts()), 404
def progress(request): commits = get_commits() posts = get_posts() return direct_to_template(request, 'progress/progress.html', {"posts":posts, "commits":commits})
def index(): list = posts.get_posts("") return render_template("feed_layout.html", posts=list, channel_name="main", title="Etusivu")
def index(): return render_template('index.html', posts=posts.get_posts(), tags=posts.header_tags())
'regex': re.compile(common_re.format('logos', '.*', 'logos'), re.DOTALL), 'replace': common_re.format('logos', '\n {} \n', 'logos') } pcts_re = { 'regex': re.compile(common_re.format('pcts', '.*', 'pcts'), re.DOTALL), 'replace': common_re.format('pcts', '\n {} \n', 'pcts') } REGEXES = [post_eng_re, post_ptbr_re, logos_re, pcts_re] if __name__ == "__main__": readme = root / "README.md" # Retrieve most recent posts for each language posts = get_posts(2) post_eng_re['replace'] = post_eng_re['replace'].format('\n\n '.join( posts['eng'])) post_ptbr_re['replace'] = post_ptbr_re['replace'].format('\n\n '.join( posts['pt-br'])) # Retrieve profile overview repositories = get_repos() languages = get_languages(repositories) percentages = calculate_languages(languages) html = languages_to_html(percentages, n=8) logos_re['replace'] = logos_re['replace'].format('\n'.join(html['logos'])) pcts_re['replace'] = pcts_re['replace'].format('\n'.join(html['pcts']))
def api_posts(): return jsonify(posts.get_posts())
active_user = None break elif active_user.role == 'admin': ANS2 = ['1', '2'] while ans not in ANS2 and ans != '2': print(f'possible actions:') ans = input('1. See user list \n2. Sign out\nplease choose :') if ans == '1': for el in population.keys(): user = population[el] print( f'\n{user.u_name} registration date is {user.reg_date}' ) if get_posts(el) == 'No posts yet': print(f'{user.u_name} have no posts yet') else: for post in user.posts: print( f'user {user.u_name} posted {post[0]} in {post[2]}' ) elif ans == '2': active_user = None break ans = None
def test_multipletags_uniqueness(): results = posts.get_posts(['tech', 'history']) ids = [post['id'] for post in results] # sets have no duplicate elements assert_that(ids).is_length(len(set(ids))) print('UNIQUENESS WORKS')
def test_multipletags_disjoint(): techresults = posts.get_posts(['tech']) disjointresults = posts.get_posts(['sanity']) bothresults = posts.get_posts(['tech', 'sanity']) assert_that(bothresults).is_length(len(techresults) + len(disjointresults)) print('MULTIPLE TAG RETRIEVAL IS SANE!')