Skip to content

Commit

Permalink
✅ Assure tests hit WSGI middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
tony committed Oct 28, 2018
1 parent ab2fdb6 commit 4025070
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@

import pytest

import requests
from examples.flask_todo.app import create_app
from flask import url_for
from wsgi_intercept.interceptor import RequestsInterceptor

from flask_mongo_profiler.contrib.mongoengine import profiling as profiling_models


@pytest.fixture
Expand All @@ -14,8 +18,30 @@ def app():
return app


@pytest.fixture(autouse=True)
def clear_db():
profiling_models.ProfilingRequest.objects.delete()
profiling_models.ProfilingQuery.objects.delete()


def test_example(app, client):
client.get(url_for('index'))
with RequestsInterceptor(lambda: app.wsgi_app, host='localhost', port=5000) as url:
response = requests.get(url)
assert response.status_code == 200

assert profiling_models.ProfilingRequest.objects.count() == 1
assert profiling_models.ProfilingQuery.objects.count() == 1
client.get(url_for('admin.index'))

# List of requests
client.get(url_for('profilingrequest.index_view'))

# Pull a profiling artifact of the request created when visiting 'index'
request_profile = profiling_models.ProfilingRequest.objects.first()
client.get(url_for('profilingrequest.details_view', id=request_profile.id))

client.get(url_for('profilingquery.index_view'))

# Same as above,
query_profile = profiling_models.ProfilingQuery.objects.first()
client.get(url_for('profilingquery.details_view', id=query_profile.id))

0 comments on commit 4025070

Please sign in to comment.