Add tests for the edit_question view

This commit is contained in:
Matthew Welch 2021-03-29 18:17:29 -07:00
parent a69c85c588
commit b032e793de
4 changed files with 31 additions and 3 deletions

View File

@ -35,8 +35,8 @@
<span class="">Created By ItIsGood.com</span> <span class="">Created By ItIsGood.com</span>
</div> </div>
</footer> </footer>
</body>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script> <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/js/bootstrap.bundle.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/js/bootstrap.bundle.min.js"></script>
{% block scripts %}{% endblock %} {% block scripts %}{% endblock %}
</body>
</html> </html>

View File

@ -20,8 +20,8 @@
<span class="">Created By ItIsGood.com</span> <span class="">Created By ItIsGood.com</span>
</div> </div>
</footer> </footer>
</body>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script> <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/js/bootstrap.bundle.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/js/bootstrap.bundle.min.js"></script>
{% block scripts %}{% endblock %} {% block scripts %}{% endblock %}
</body>
</html> </html>

View File

@ -19,7 +19,7 @@ def session():
@pytest.fixture(scope="module") @pytest.fixture(scope="module")
def init_database(client, session): def init_database(session):
init_db() init_db()
user_datastore = SQLAlchemySessionUserDatastore(session, User, Role) user_datastore = SQLAlchemySessionUserDatastore(session, User, Role)

View File

@ -1,3 +1,5 @@
import json
from html5validate import validate
from flask.testing import FlaskClient from flask.testing import FlaskClient
@ -9,3 +11,29 @@ def test_admin_home_with_basic_user(client: FlaskClient, login_basic_user):
def test_admin_home_with_admin_user(client: FlaskClient, login_admin_user): def test_admin_home_with_admin_user(client: FlaskClient, login_admin_user):
response = client.get("/admin/") response = client.get("/admin/")
assert response.status_code == 200 assert response.status_code == 200
def test_edit_question_view_gives_json(client: FlaskClient, login_admin_user):
response = client.get("/admin/questions/edit/0", headers={"Accept": "application/json"})
assert response.headers.get("Content-Type") == "application/json"
data = json.loads(response.data)
assert "question_id" in data.keys()
assert type(data["question_id"]) is int
assert "question" in data.keys()
assert type(data["question"]) is str
assert "answer" in data.keys()
assert type(data["answer"]) is str
assert "addresses" in data.keys()
assert type(data["addresses"]) is str
def test_edit_question_view_gives_html(client: FlaskClient, login_admin_user):
response = client.get("/admin/questions/edit/0", headers={"Accept": "text/html"})
assert "text/html" in response.headers.get("Content-Type")
assert validate(response.data) is None
def test_edit_question_view(client: FlaskClient, login_admin_user):
response = client.get("/admin/questions/edit/0")
assert "text/html" in response.headers.get("Content-Type")
assert validate(response.data) is None