8000 Added section10 final code to the repository. · adewealthgit/testing-python-apps@41b4c71 · GitHub
[go: up one dir, main page]

Skip to content

Commit 41b4c71

Browse files
committed
Added section10 final code to the repository.
1 parent 7a97523 commit 41b4c71

28 files changed

+385
-9
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
*.key
2+
*.screenflow
3+
*.png
14
starter_code.zip
25
.idea/
36
.DS_Store

section10/code/app.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
from flask import Flask, render_template, request, redirect, url_for
2+
3+
app = Flask(__name__)
4+
5+
posts = []
6+
7+
8+
@app.route('/')
9+
def homepage():
10+
return render_template('home.html')
11+
12+
13+
@app.route('/blog')
14+
def blog_page():
15+
return render_template('blog.html', posts=posts)
16+
17+
18+
@app.route('/post', methods=['GET', 'POST'])
19+
def add_post():
20+
if request.method == 'POST':
21+
title = request.form['title']
22+
content = request.form['content']
23+
global posts
24+
25+
posts.append({
26+
'title': title,
27+
'content': content
28+
})
29+
30+
return redirect(url_for('blog_page'))
31+
return render_template('new_post.html')
32+
33+
34+
@app.route('/post/<string:title>')
35+
def see_post(title):
36+
global posts
37+
38+
for post in posts:
39+
if post['title'] == title:
40+
return render_template('post.html', post=post)
41+
42+
return render_template('post.html', post=None)
43+
44+
45+
if __name__ == '__main__':
46+
app.run()

section10/code/requirements.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Flask
2+
uwsgi
3+
behave==1.2.5
4+
beautifulsoup4==4.5.3
5+
selenium==3.4.1

section10/code/templates/blog.html

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<script>
5+
window.onload = function() {
6+
setTimeout(function() {
7+
document.getElementById('posts').style.display = 'block';
8+
}, 3000);
9+
};
10+
11+
</script>
12+
</head>
13+
<body>
14+
<h1>This is the blog page</h1>
15+
16+
<a href="{{ url_for('homepage') }}" class="nav-link" id="home-link">Go to home</a>
17+
<a href="{{ url_for('add_post') }}" class="nav-link" id="add-post-link">Create post</a>
18+
19+
<ol id="posts" style="display: none">
20+
{% for post in posts %}
21+
<li class="post"><a href="{{ url_for('see_post', title=post['title']) }}" class="post-link">{{ post['title'] }}</a></li>
22+
{% endfor %}
23+
</ol>
24+
</body>
25+
</html>

section10/code/templates/home.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
5+
</head>
6+
<body>
7+
<h1>This is the homepage</h1>
8+
9+
<a href="{{ url_for('blog_page') }}" class="nav-link" id="blog-link">Go to blog</a>
10+
</body>
11+
</html>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
5+
</head>
6+
<body>
7+
<h1>Create post</h1>
8+
9+
<a href="{{ url_for('blog_page') }}" class="nav-link" id="blog-link">Back to blog</a>
10+
11+
<form method="POST" id="post-form">
12+
<div>
13+
<label for="title">Post title:</label>
14+
<input type="text" name="title" id="title" />
15+
</div>
16+
<div>
17+
<label for="content">Post content:</label>
18+
<textarea name="content" id="content"></textarea>
19+
</div>
20+
<div>
21+
<button type="submit" id="create-post">Create</button>
22+
</div>
23+
</form>
24+
</body>
25+
</html>

section10/code/templates/post.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
5+
</head>
6+
<body>
7+
{% if post %}
8+
<h1>{{ post['title'] }}</h1>
9+
10+
<p>{{ post['content'] }}</p>
11+
{% else %}
12+
<h1>Post not found!</h1>
13+
{% endif %}
14+
</body>
15+
</html>

section10/code/tests/__init__.py

Whitespace-only changes.

section10/code/tests/acceptance/__init__.py

Whitespace-only changes.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Feature: Test that pages have correct content
2+
Scenario: Blog page has a correct title
3+
Given I am on the blog page
4+
Then There is a title shown on the page
5+
And The title tag has content "This is the blog page"
6+
7+
Scenario: Homepage has a correct title
8+
Given I am on the homepage
9+
Then There is a title shown on the page
10+
And The title tag has content "This is the homepage"
11+
12+
Scenario: Blog page loads the posts
13+
Given I am on the blog page
14+
And I wait for the posts to load
15+
Then I can see there is a posts section on the page
16+
17+
Scenario: User can create new posts
18+
Given I am on the new post page
19+
When I enter "Test Post" in the "title" field
20+
And I enter "Test Content" in the "content" field
21+
And I press the submit button
22+
Then I am on the blog page
23+
Given I wait for the posts to load
24+
Then I can see there is a post with title "Test Post" in the posts section

0 commit comments

Comments
 (0)
0