Skip to content

Added pytest for /posts route and updated template #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
56 changes: 33 additions & 23 deletions blogexample/templates/posts.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,40 @@

<title>Posts</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>

<link rel="stylesheet" href="{{ url_for('static', filename='css/styles.css') }}">

<link rel="stylesheet" type="text/css" href="../static/css/styles.css">
<style type="text/css">
#us{
float: right;
margin-right: 20px;
margin-top: 10px;
<style>
.flashes-container{
display: flex;
align-items: center;
justify-content: center;
}
#us h3{
margin: 0 0 0 0;
.flashes{

color: rgb(77, 158, 190);
align-self: center;
}
.ps{
width: 60%;
margin-top: 20px;
margin-left: 20%
}
#icon{
float: right;
margin-top: -15px;
.icon{
margin-top: -20px;
display: flex;
justify-content: flex-end;
align-items: center;
gap:12px;
}
#signout{
width: 100px;
height: 20px;
#myform{
display:inline;
}
#signout a{
padding: 2px 0px 2px 20px;
#myform button{
padding:0;

}
</style>
</head>
Expand All @@ -47,20 +52,25 @@
</div>
{% with messages = get_flashed_messages() %}
{% if messages %}
<div class="flashes-container">
{% for message in messages %}
<h3 class="flashes" align="center" style="color:#337ab7">{{ message }}</h3>
<h3 class="flashes">{{ message }}</h3>
{% endfor %}
</div>
{% endif %}
{% endwith %}
<div class="ps">
{% for each_post in posts %}
<div class="panel panel-info">
<div class="panel-heading">
<div><h3 class="panel-title">{{each_post.title}}</h3></div>
<div id="icon">
<a class="glyphicon glyphicon-sunglasses" href="/detail/{{ each_post.url }}"></a>&nbsp &nbsp
<a class="glyphicon glyphicon-pencil" href="/update/{{ each_post.id }}"></a>&nbsp &nbsp
<a class="glyphicon glyphicon-trash" id="del" href="/delete/{{ each_post.id }}"></a>
<div class="icon">
<a class="glyphicon glyphicon-sunglasses" href="/detail/{{ each_post.url }}"></a>
<a class="glyphicon glyphicon-pencil" href="/update/{{ each_post.id }}"></a>
<form method="POST" id="myform" action="{{ url_for('blog.delete_post', pid=each_post.id) }}" onsubmit="return confirm('Are you sure you want to delete this post?');">
<button type="submit" class="btn btn-link glyphicon glyphicon-trash"></button>
</form>

</div>
</div>
<div class="panel-body"><p>{{ each_post.body|safe }}</p>
Expand Down
Binary file modified lib/__pycache__/util_datetime.cpython-36.pyc
Binary file not shown.
Binary file modified lib/__pycache__/util_sqlalchemy.cpython-36.pyc
Binary file not shown.
3 changes: 3 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[pytest]
pythonpath = .
addopts = --maxfail=1 --disable-warnings -v
11 changes: 11 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import pytest
from blogexample.app import create_app # Adjust to your actual app location

@pytest.fixture
def app():
app = create_app() # If your app creation function is called create_app
yield app

@pytest.fixture
def client(app):
return app.test_client()
4 changes: 4 additions & 0 deletions tests/test_routes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
def test_home_route_status_code(client):
"""Test the status code of the posts route"""
response = client.get('/posts')
assert response.status_code == 200