Commit 76b37250 by Alex Dusenbery Committed by GitHub

Merge pull request #59 from edx/aed/django1.11

EDUCATOR-786 | Support Django 1.11
parents 3fd9244b 61a49b43
...@@ -54,3 +54,4 @@ submissions_test_db ...@@ -54,3 +54,4 @@ submissions_test_db
# Sphinx documentation # Sphinx documentation
docs/_build/ docs/_build/
venvs
language: python language: python
python: python:
- "2.7" - '2.7'
env: env:
- TOXENV=django18 - TOXENV=django18
- TOXENV=django19 - TOXENV=django110
- TOXENV=django110 - TOXENV=django111
matrix: matrix:
allow_failures: allow_failures:
- env: TOXENV=django19 - env: TOXENV=django110
- env: TOXENV=django110
# Use docker for travis builds
sudo: false sudo: false
install: install:
- "pip install -r requirements.txt" - pip install -r requirements.txt
- "pip install -r test-requirements.txt" - pip install -r test-requirements.txt
- "python setup.py install" - python setup.py install
- "pip install coveralls" - pip install coveralls
script: script:
- "tox" - tox
after_success: after_success: coveralls
coveralls # Set password via "travis encrypt --add deploy.password"; for details, see
# https://docs.travis-ci.com/user/deployment/pypi
deploy:
provider: pypi
user: edx
distributions: sdist bdist_wheel
skip_upload_docs: true
password:
secure: BlYK3lplRoPiNfzqslxyReJZrC1QUT9Ls1A1xIxc3IHxKl9WEkqC2xO5vBvQDFKtMyooq8bGeN/gfksaZpRYqBmrO7hPITiz0FH0wPFdjoIikI4NTqKVxjhqUho0ZWmpxNXrX/iMd9Y2R4uZRXZGaWaTSRHfF9fPVlkbo66s7vw=
tags: true
...@@ -36,7 +36,8 @@ To run the test suite: ...@@ -36,7 +36,8 @@ To run the test suite:
.. code:: bash .. code:: bash
python manage.py test pip install -r test-requirements.txt
tox # to run only a single environment, do e.g. tox -e django18
License License
......
...@@ -10,11 +10,12 @@ DATABASES = { ...@@ -10,11 +10,12 @@ DATABASES = {
'ENGINE': 'django.db.backends.sqlite3', 'ENGINE': 'django.db.backends.sqlite3',
'TEST_NAME': 'submissions_test_db', 'TEST_NAME': 'submissions_test_db',
}, },
'read_replica': { 'read_replica': {
'ENGINE': 'django.db.backends.sqlite3', 'ENGINE': 'django.db.backends.sqlite3',
'TEST_MIRROR': 'default' 'TEST': {
} 'MIRROR': 'default',
},
},
} }
CACHES = { CACHES = {
......
...@@ -33,7 +33,7 @@ def load_requirements(*requirements_paths): ...@@ -33,7 +33,7 @@ def load_requirements(*requirements_paths):
setup( setup(
name='edx-submissions', name='edx-submissions',
version='2.0.1', version='2.0.2',
author='edX', author='edX',
description='An API for creating submissions and scores.', description='An API for creating submissions and scores.',
url='http://github.com/edx/edx-submissions.git', url='http://github.com/edx/edx-submissions.git',
......
...@@ -2,13 +2,27 @@ ...@@ -2,13 +2,27 @@
Test API calls using the read replica. Test API calls using the read replica.
""" """
import copy import copy
from django.conf import settings
from django.test import TransactionTestCase from django.test import TransactionTestCase
import mock
from submissions import api as sub_api from submissions import api as sub_api
def _mock_use_read_replica(queryset):
"""
The Django DATABASES setting TEST_MIRROR isn't reliable.
See: https://code.djangoproject.com/ticket/23718
"""
return (
queryset.using('default')
if 'read_replica' in settings.DATABASES
else queryset
)
class ReadReplicaTest(TransactionTestCase): class ReadReplicaTest(TransactionTestCase):
""" Test queries that use the read replica. """ """ Test queries that use the read replica. """
STUDENT_ITEM = { STUDENT_ITEM = {
"student_id": "test student", "student_id": "test student",
"course_id": "test course", "course_id": "test course",
...@@ -31,15 +45,17 @@ class ReadReplicaTest(TransactionTestCase): ...@@ -31,15 +45,17 @@ class ReadReplicaTest(TransactionTestCase):
) )
def test_get_submission_and_student(self): def test_get_submission_and_student(self):
retrieved = sub_api.get_submission_and_student(self.submission['uuid'], read_replica=True) with mock.patch('submissions.api._use_read_replica', _mock_use_read_replica):
expected = copy.deepcopy(self.submission) retrieved = sub_api.get_submission_and_student(self.submission['uuid'], read_replica=True)
expected['student_item'] = copy.deepcopy(self.STUDENT_ITEM) expected = copy.deepcopy(self.submission)
self.assertEqual(retrieved, expected) expected['student_item'] = copy.deepcopy(self.STUDENT_ITEM)
self.assertEqual(retrieved, expected)
def test_get_latest_score_for_submission(self): def test_get_latest_score_for_submission(self):
retrieved = sub_api.get_latest_score_for_submission(self.submission['uuid'], read_replica=True) with mock.patch('submissions.api._use_read_replica', _mock_use_read_replica):
self.assertEqual(retrieved['points_possible'], self.SCORE['points_possible']) retrieved = sub_api.get_latest_score_for_submission(self.submission['uuid'], read_replica=True)
self.assertEqual(retrieved['points_earned'], self.SCORE['points_earned']) self.assertEqual(retrieved['points_possible'], self.SCORE['points_possible'])
self.assertEqual(retrieved['points_earned'], self.SCORE['points_earned'])
def test_get_top_submissions(self): def test_get_top_submissions(self):
student_item_1 = copy.deepcopy(self.STUDENT_ITEM) student_item_1 = copy.deepcopy(self.STUDENT_ITEM)
...@@ -60,7 +76,7 @@ class ReadReplicaTest(TransactionTestCase): ...@@ -60,7 +76,7 @@ class ReadReplicaTest(TransactionTestCase):
sub_api.set_score(student_3['uuid'], 2, 10) sub_api.set_score(student_3['uuid'], 2, 10)
# Use the read-replica # Use the read-replica
with self.assertNumQueries(0): with mock.patch('submissions.api._use_read_replica', _mock_use_read_replica):
top_scores = sub_api.get_top_submissions( top_scores = sub_api.get_top_submissions(
self.STUDENT_ITEM['course_id'], self.STUDENT_ITEM['course_id'],
self.STUDENT_ITEM['item_id'], self.STUDENT_ITEM['item_id'],
...@@ -79,4 +95,4 @@ class ReadReplicaTest(TransactionTestCase): ...@@ -79,4 +95,4 @@ class ReadReplicaTest(TransactionTestCase):
'score': 4 'score': 4
}, },
] ]
) )
\ No newline at end of file
ddt==0.8.0 ddt==0.8.0
django-nose==1.4.1 django-nose==1.4.4
freezegun==0.1.11 freezegun==0.1.11
mock==1.0.1 mock==1.0.1
nose==1.3.3 nose==1.3.3
...@@ -16,4 +16,4 @@ sphinx-rtd-theme==0.1.5 ...@@ -16,4 +16,4 @@ sphinx-rtd-theme==0.1.5
sphinxcontrib-napoleon==0.2.3 sphinxcontrib-napoleon==0.2.3
# Tox # Tox
tox==2.6.0 tox==2.7.0
[tox] [tox]
envlist = django{18,19,110} envlist = django{18,110,111}
[testenv] [testenv]
deps = deps =
-r{toxinidir}/requirements.txt -r{toxinidir}/requirements.txt
-r{toxinidir}/test-requirements.txt -r{toxinidir}/test-requirements.txt
django18: Django>=1.8,<1.9 django18: Django>=1.8,<1.9
django19: Django>=1.9,<1.10
django110: Django>=1.10,<1.11 django110: Django>=1.10,<1.11
django111: Django>=1.11,<1.12
commands = commands =
python manage.py test python manage.py test
python setup.py build_sphinx python setup.py build_sphinx
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment