Skip to content

Commit

Permalink
EDUCATOR-786 | Support Django 1.11; Upgrade django_nose; Mock out rea…
Browse files Browse the repository at this point in the history
…d_replica for testing; bump tox version.
  • Loading branch information
iloveagent57 committed Jul 14, 2017
1 parent 3fd9244 commit 61a49b4
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 34 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,4 @@ submissions_test_db
# Sphinx documentation
docs/_build/

venvs
35 changes: 21 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
language: python
python:
- "2.7"
- '2.7'
env:
- TOXENV=django18
- TOXENV=django19
- TOXENV=django110
- TOXENV=django18
- TOXENV=django110
- TOXENV=django111
matrix:
allow_failures:
- env: TOXENV=django19
- env: TOXENV=django110
# Use docker for travis builds
- env: TOXENV=django110
sudo: false
install:
- "pip install -r requirements.txt"
- "pip install -r test-requirements.txt"
- "python setup.py install"
- "pip install coveralls"
- pip install -r requirements.txt
- pip install -r test-requirements.txt
- python setup.py install
- pip install coveralls
script:
- "tox"
after_success:
coveralls
- tox
after_success: 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
3 changes: 2 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ To run the test suite:

.. 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
Expand Down
7 changes: 4 additions & 3 deletions settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
'ENGINE': 'django.db.backends.sqlite3',
'TEST_NAME': 'submissions_test_db',
},

'read_replica': {
'ENGINE': 'django.db.backends.sqlite3',
'TEST_MIRROR': 'default'
}
'TEST': {
'MIRROR': 'default',
},
},
}

CACHES = {
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def load_requirements(*requirements_paths):

setup(
name='edx-submissions',
version='2.0.1',
version='2.0.2',
author='edX',
description='An API for creating submissions and scores.',
url='http://github.com/edx/edx-submissions.git',
Expand Down
36 changes: 26 additions & 10 deletions submissions/tests/test_read_replica.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,27 @@
Test API calls using the read replica.
"""
import copy

from django.conf import settings
from django.test import TransactionTestCase
import mock

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):
""" Test queries that use the read replica. """

STUDENT_ITEM = {
"student_id": "test student",
"course_id": "test course",
Expand All @@ -31,15 +45,17 @@ def setUp(self):
)

def test_get_submission_and_student(self):
retrieved = sub_api.get_submission_and_student(self.submission['uuid'], read_replica=True)
expected = copy.deepcopy(self.submission)
expected['student_item'] = copy.deepcopy(self.STUDENT_ITEM)
self.assertEqual(retrieved, expected)
with mock.patch('submissions.api._use_read_replica', _mock_use_read_replica):
retrieved = sub_api.get_submission_and_student(self.submission['uuid'], read_replica=True)
expected = copy.deepcopy(self.submission)
expected['student_item'] = copy.deepcopy(self.STUDENT_ITEM)
self.assertEqual(retrieved, expected)

def test_get_latest_score_for_submission(self):
retrieved = sub_api.get_latest_score_for_submission(self.submission['uuid'], read_replica=True)
self.assertEqual(retrieved['points_possible'], self.SCORE['points_possible'])
self.assertEqual(retrieved['points_earned'], self.SCORE['points_earned'])
with mock.patch('submissions.api._use_read_replica', _mock_use_read_replica):
retrieved = sub_api.get_latest_score_for_submission(self.submission['uuid'], read_replica=True)
self.assertEqual(retrieved['points_possible'], self.SCORE['points_possible'])
self.assertEqual(retrieved['points_earned'], self.SCORE['points_earned'])

def test_get_top_submissions(self):
student_item_1 = copy.deepcopy(self.STUDENT_ITEM)
Expand All @@ -60,7 +76,7 @@ def test_get_top_submissions(self):
sub_api.set_score(student_3['uuid'], 2, 10)

# 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(
self.STUDENT_ITEM['course_id'],
self.STUDENT_ITEM['item_id'],
Expand All @@ -79,4 +95,4 @@ def test_get_top_submissions(self):
'score': 4
},
]
)
)
4 changes: 2 additions & 2 deletions test-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ddt==0.8.0
django-nose==1.4.1
django-nose==1.4.4
freezegun==0.1.11
mock==1.0.1
nose==1.3.3
Expand All @@ -16,4 +16,4 @@ sphinx-rtd-theme==0.1.5
sphinxcontrib-napoleon==0.2.3

# Tox
tox==2.6.0
tox==2.7.0
2 changes: 1 addition & 1 deletion tox-requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Django<1.11
Django<=1.11
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[tox]
envlist = django{18,19,110}
envlist = django{18,110,111}

[testenv]
deps =
-r{toxinidir}/requirements.txt
-r{toxinidir}/test-requirements.txt
django18: Django>=1.8,<1.9
django19: Django>=1.9,<1.10
django110: Django>=1.10,<1.11
django111: Django>=1.11,<1.12
commands =
python manage.py test
python setup.py build_sphinx

0 comments on commit 61a49b4

Please sign in to comment.