Skip to content
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

Add testing for current Django versions #200

Merged
merged 9 commits into from
May 12, 2020
Merged
Show file tree
Hide file tree
Changes from 6 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
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ python:
- "3.8"

install:
- pip install tox
- pip install tox tox-travis

notifications:
email:
Expand All @@ -19,4 +19,4 @@ notifications:
on_failure: always

script:
- tox -e $(echo py$TRAVIS_PYTHON_VERSION | tr -d .)
- tox
1 change: 0 additions & 1 deletion tests/ext/django/app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did we remove this 'django.contrib.auth.middleware.SessionAuthenticationMiddleware' ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The SessionAuthenticationMiddleware class is removed. It provided no functionality since session authentication is unconditionally enabled in Django 1.10.

https://docs.djangoproject.com/en/2.0/releases/2.0/#miscellaneous

'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
Expand Down
4 changes: 3 additions & 1 deletion tests/ext/django/test_middleware.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import django
from aws_xray_sdk import global_sdk_config
from django.core.urlresolvers import reverse
from django.urls import reverse
from django.test import TestCase

from aws_xray_sdk.core import xray_recorder, lambda_launcher
from aws_xray_sdk.core.context import Context
from aws_xray_sdk.core.models import http, facade_segment, segment
from aws_xray_sdk.core import patch
from tests.util import get_new_stubbed_recorder
import os

Expand Down Expand Up @@ -66,6 +67,7 @@ def test_fault(self):
assert exception.type == 'KeyError'

def test_db(self):
patch(('sqlite3',))
url = reverse('call_db')
self.client.get(url)
segment = xray_recorder.emitter.pop()
Expand Down
12 changes: 8 additions & 4 deletions tests/ext/sqlite3/test_sqlite3.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
from aws_xray_sdk.core import xray_recorder
from aws_xray_sdk.core.context import Context

patch(('sqlite3',))
db = sqlite3.connect(":memory:")

@pytest.fixture(scope="module")
def db():
patch(('sqlite3',))
return sqlite3.connect(":memory:")


@pytest.fixture(autouse=True)
Expand All @@ -24,7 +27,8 @@ def construct_ctx():
xray_recorder.clear_trace_entities()


def test_execute():
def test_execute(db):

q = 'SELECT name FROM sqlite_master'
db.execute(q)

Expand All @@ -35,7 +39,7 @@ def test_execute():
assert sql['database_version']


def test_invalid_syntax():
def test_invalid_syntax(db):
q = 'some_query'
try:
db.execute(q)
Expand Down
18 changes: 11 additions & 7 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
[tox]
envlist =
py{27,34,35,36,37,38}
py{27,34,35,36,37,38}-default
py{35,36,37,38}-aiohttp2
py{27,34,35,36,37}-django111
py{35,36,37,38}-django22
py{36,37,38}-django30
coverage-report

skip_missing_interpreters = True
Expand All @@ -17,9 +20,10 @@ deps =
sqlalchemy
Flask-SQLAlchemy
future
# the sdk doesn't support earlier version of django
django >= 1.10, <2.0
django-fake-model
django111: Django==1.11.*
django22: Django==2.2.*
django30: Django==3.0.*
django{111,22,30}: django-fake-model
pynamodb >= 3.3.1
psycopg2
pg8000
Expand All @@ -34,9 +38,9 @@ deps =
py{35,36,37,38}: aiobotocore >= 0.10.0

commands =
py{27,34}: coverage run --source aws_xray_sdk -m py.test tests --ignore tests/ext/aiohttp --ignore tests/ext/aiobotocore --ignore tests/test_async_local_storage.py --ignore tests/test_async_recorder.py
codecov
py{35,36,37,38}: coverage run --source aws_xray_sdk -m py.test tests
py{27,34}-default: coverage run --source aws_xray_sdk -m py.test tests --ignore tests/ext/aiohttp --ignore tests/ext/aiobotocore --ignore tests/ext/django --ignore tests/test_async_local_storage.py --ignore tests/test_async_recorder.py
py{35,36,37,38}-default: coverage run --source aws_xray_sdk -m py.test --ignore tests/ext/django tests
django{111,22,30}: coverage run --source aws_xray_sdk -m py.test tests/ext/django
codecov

setenv =
Expand Down