10000 Add acceptance testing barebones. · abigit24/testing-python-apps@9387bfa · GitHub
[go: up one dir, main page]

Skip to content

Commit 9387bfa

Browse files
committed
Add acceptance testing barebones.
1 parent ac77623 commit 9387bfa

20 files changed

+243
-3
lines changed

section6/video_code/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Set up
2+
3+
We'll need a few things to install for this section:
4+
5+
- https://sites.google.com/a/chromium.org/chromedriver/downloads
6+
- behave (http://pythonhosted.org/behave/)
7+
- selenium (http://selenium-python.readthedocs.io/installation.html)
8+
9+
10+
## Running the tests
11+
12+
To run the tests, you'll need to do this in a terminal (but remember to have the Flask app running!):
13+
14+
```bash
15+
source venv/bin/activate
16+
cd section6/video_code/
17+
python -m behave tests/acceptance
18+
```
19+
20+
If you want to run the tests in PyCharm, you'll need to create appropriate configurations.
21+
22+
Create a Python configuration for the app.
23+
24+
[]
25+
26+
Create a Python configuration for the running of behave tests.
27+
28+
[]

section6/video_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()

section6/video_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
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
5+
</head>
6+
<body>
7+
<h1>This is the blog page</h1>
8+
9+
<a href="{{ url_for('homepage') }}" class="nav-link" id="home-link">Go to home</a>
10+
<a href="{{ url_for('add_post') }}" class="nav-link" id="add-post-link">Create post</a>
11+
12+
{% if posts|length > 0 %}
13+
<ol>
14+
{% for post in posts %}
15+
<li><a href="{{ url_for('see_post', title=post['title']) }}">{{ post['title'] }}</a></li>
16+
{% endfor %}
17+
</ol>
18+
{% endif %}
19+
</body>
20+
</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">
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>
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>

section6/video_code/tests/__init__.py

Whitespace-only changes.

section6/video_code/tests/acceptance/__init__.py

Whitespace-only changes.

section6/video_code/tests/acceptance/pages/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)
0