Skip to content

Commit 6245d48

Browse files
authored
Fix django urls import (#343)
* fixing deprecated import * fix for django in python 2.7 * skip pymongo map_reduce test when testing on latest pymongo versions since the map_reduce functionality has been removed
1 parent 5b16895 commit 6245d48

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

tests/apps/app_django.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@
99
import time
1010
import opentracing
1111
import opentracing.ext.tags as ext
12+
try:
13+
from django.urls import re_path
14+
except ImportError:
15+
from django.conf.urls import url as re_path
1216

13-
from django.conf.urls import url
1417
from django.http import HttpResponse, Http404
1518

1619
filepath, extension = os.path.splitext(__file__)
@@ -123,9 +126,9 @@ def complex(request):
123126

124127

125128
urlpatterns = [
126-
url(r'^$', index, name='index'),
127-
url(r'^cause_error$', cause_error, name='cause_error'),
128-
url(r'^another$', another),
129-
url(r'^not_found$', not_found, name='not_found'),
130-
url(r'^complex$', complex, name='complex')
129+
re_path(r'^$', index, name='index'),
130+
re_path(r'^cause_error$', cause_error, name='cause_error'),
131+
re_path(r'^another$', another),
132+
re_path(r'^not_found$', not_found, name='not_found'),
133+
re_path(r'^complex$', complex, name='complex')
131134
]

tests/clients/test_pymongo.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import json
77
import unittest
88
import logging
9+
import pytest
910

1011
from nose.tools import (assert_is_none, assert_is_not_none,
1112
assert_false, assert_true, assert_list_equal)
@@ -18,6 +19,10 @@
1819

1920
logger = logging.getLogger(__name__)
2021

22+
pymongoversion = pytest.mark.skipif(
23+
pymongo.version_tuple >= (4, 0), reason="map reduce is removed in pymongo 4.0"
24+
)
25+
2126

2227
class TestPyMongoTracer(unittest.TestCase):
2328
def setUp(self):
@@ -169,6 +174,7 @@ def test_successful_aggregate_query(self):
169174
payload = json.loads(db_span.data["mongo"]["json"])
170175
assert_true({"$match": {"type": "string"}} in payload, db_span.data["mongo"]["json"])
171176

177+
@pymongoversion
172178
def test_successful_map_reduce_query(self):
173179
mapper = "function () { this.tags.forEach(function(z) { emit(z, 1); }); }"
174180
reducer = "function (key, values) { return len(values); }"

0 commit comments

Comments
 (0)