Skip to content

Commit

Permalink
Merge pull request #48 from edx/ahsan/LEARNER-1529-upgrade-edx-search
Browse files Browse the repository at this point in the history
Upgrade to django 1.11 and implemented tox
  • Loading branch information
Ahsan Ul Haq authored Jul 14, 2017
2 parents ad44e21 + 1a6926d commit fa6e0bb
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 26 deletions.
9 changes: 8 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@ sudo: false

language: python

python: "2.7"
python:
- 2.7

env:
- TOXENV=django18
- TOXENV=django19
- TOXENV=django110
- TOXENV=django111

# Cache the pip directory. "cache: pip" doesn't work due to install override. See https://github.com/travis-ci/travis-ci/issues/3239.
cache:
Expand Down
7 changes: 2 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@ clean:
rm -rf coverage htmlcov

quality:
pep8 --config=.pep8 search
pylint --rcfile=pylintrc search
tox -e quality

requirements:
pip install -r test_requirements.txt

validate: clean
DJANGO_SETTINGS_MODULE=settings coverage run --source=search ./manage.py test
coverage report
make quality
tox


.PHONY: clean, quality, requirements, validate
5 changes: 3 additions & 2 deletions edxsearch/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
""" import urls from search component to test it's operation when included within other django projects """
from django.conf.urls import patterns, include, url
import django
from django.conf.urls import include, url

# from django.contrib import admin
# admin.autodiscover()
Expand All @@ -8,4 +9,4 @@

# urlpatterns is the standard name to use here
# pylint: disable=invalid-name
urlpatterns = patterns('', url(r'^search/', include(search.urls)),)
urlpatterns = [url(r'^search/', include(search.urls))]
24 changes: 12 additions & 12 deletions search/tests/test_search_result_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ def test_strings_in_dictionary(self):
})
get_strings = SearchResultProcessor.strings_in_dictionary(test_dict)
self.assertEqual(len(get_strings), 2)
self.assertEqual(get_strings[0], test_dict["a"])
self.assertEqual(get_strings[1], test_dict["b"])
self.assertIn(test_dict["a"], get_strings)
self.assertIn(test_dict["b"], get_strings)

test_dict.update({
"CASCADE": {
Expand All @@ -35,9 +35,9 @@ def test_strings_in_dictionary(self):
})
get_strings = SearchResultProcessor.strings_in_dictionary(test_dict)
self.assertEqual(len(get_strings), 3)
self.assertEqual(get_strings[0], test_dict["a"])
self.assertEqual(get_strings[1], test_dict["b"])
self.assertEqual(get_strings[2], test_dict["CASCADE"]["z"])
self.assertIn(test_dict["a"], get_strings)
self.assertIn(test_dict["b"], get_strings)
self.assertIn(test_dict["CASCADE"]["z"], get_strings)

test_dict.update({
"DEEP": {
Expand All @@ -52,10 +52,10 @@ def test_strings_in_dictionary(self):
})
get_strings = SearchResultProcessor.strings_in_dictionary(test_dict)
self.assertEqual(len(get_strings), 4)
self.assertEqual(get_strings[0], test_dict["a"])
self.assertEqual(get_strings[1], test_dict["b"])
self.assertEqual(get_strings[2], test_dict["CASCADE"]["z"])
self.assertEqual(get_strings[3], test_dict["DEEP"]["DEEPER"]["STILL_GOING"]["MORE"]["here"])
self.assertIn(test_dict["a"], get_strings)
self.assertIn(test_dict["b"], get_strings)
self.assertIn(test_dict["CASCADE"]["z"], get_strings)
self.assertIn(test_dict["DEEP"]["DEEPER"]["STILL_GOING"]["MORE"]["here"], get_strings)

def test_find_matches(self):
""" test finding matches """
Expand Down Expand Up @@ -127,9 +127,9 @@ def test_excerpt(self):
self.assertEqual(srp.excerpt, u"Here is a <b>الاستحسان</b> about edx")

srp = SearchResultProcessor(test_result, u"edx")
self.assertEqual(
srp.excerpt,
u'Here is a الاستحسان about <b>edx</b><span class="search-results-ellipsis"></span><b>edX</b> search a lot'
self.assertIn(
u"Here is a الاستحسان about <b>edx</b>",
srp.excerpt
)

def test_too_long_excerpt(self):
Expand Down
7 changes: 3 additions & 4 deletions search/urls.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
""" expose courseware search http interface """
from django.conf import settings
from django.conf.urls import patterns, url
from django.conf.urls import url

from . import views

COURSE_ID_PATTERN = getattr(settings, "COURSE_ID_PATTERN", r'(?P<course_id>[^/+]+(/|\+)[^/+]+(/|\+)[^/]+)')

# urlpatterns is the standard name to use here
# pylint: disable=invalid-name
urlpatterns = patterns(
'',
urlpatterns = [
url(r'^$', views.do_search, name='do_search'),
url(r'^{}$'.format(COURSE_ID_PATTERN), views.do_search, name='do_search'),
url(r'^course_discovery/$', views.course_discovery, name='course_discovery'),
)
]
9 changes: 7 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name='edx-search',
version='1.0.1',
version='1.1.0',
description='Search and index routines for index access',
author='edX',
author_email='oscm@edx.org',
Expand All @@ -18,11 +18,16 @@
'License :: OSI Approved :: GNU Affero General Public License v3',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 2.7',
'Framework :: Django',
'Framework :: Django :: 1.8',
'Framework :: Django :: 1.9',
'Framework :: Django :: 1.10',
'Framework :: Django :: 1.11',
],
packages=['search', 'search.tests'],
install_requires=[
"django >= 1.8, < 1.9",
"django >= 1.8, < 2.0",
"elasticsearch>=1.0.0,<2.0.0"
]
)
1 change: 1 addition & 0 deletions test_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ mock==1.3.0
pep8==1.6.2
pytz
codecov
tox>=2.3.1,<3.0.0


# edX libraries
Expand Down
23 changes: 23 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[tox]
envlist = py{27}-django{18,19,110,111}, quality

[testenv]
setenv =
# This allows us to reference settings.py
PYTHONPATH = {toxinidir}

deps =
django18: Django>=1.8,<1.9
django19: Django>=1.9,<1.10
django110: Django>=1.10,<1.11
django111: Django>=1.11,<2.0
-rtest_requirements.txt

commands =
coverage run ./manage.py test --settings=settings
coverage report

[testenv:quality]
commands =
pep8 --config=.pep8 search
pylint --rcfile=pylintrc search

0 comments on commit fa6e0bb

Please sign in to comment.