Skip to content

Commit

Permalink
Merge pull request #111 from edx/BOM-1017
Browse files Browse the repository at this point in the history
Django upgrade to 2.2 - BOM-1017
  • Loading branch information
mraarif authored Nov 15, 2019
2 parents c33bd8f + 022460d commit 277ffe7
Show file tree
Hide file tree
Showing 18 changed files with 267 additions and 191 deletions.
30 changes: 27 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,35 @@
language: python
python:
- "2.7"
- "3.6"
- "3.5"

env:
- TOXENV=django111
- TOXENV=django20
- TOXENV=django21
- TOXENV=django22

matrix:
exclude:
- python: "2.7"
env: TOXENV=django20
- python: "2.7"
env: TOXENV=django21
- python: "2.7"
env: TOXENV=django22
include:
- python: "3.5"
env: TOXENV=quality
- python: "2.7"
env: TOXENV=pytest-py27
- python: "3.5"
env: TOXENV=pytest-py35

install:
- make requirements
- pip install coveralls
script:
- tox -- --hypothesis-profile=ci
- make quality
after_success:
- coveralls
deploy:
Expand All @@ -17,5 +39,7 @@ deploy:
secure: cnCf0zDyTEJycCDcxhH1GsvOWNGImjwc8WIrD/D5Hsk7p0IeMaEjc/t6gc1LO2iQKGlZq/BLDxUBmsEbrQUD1wvSBg/J+9Ji6yn9jJ87X6QSNq+Xy0brLe9RAeMElG3OLqbj6FHRMzk2EmOEJXI9ATqlXfdqFwgKCYrvf2GT2Ug=
on:
tags: true
python: "3.5"
condition: "$TOXENV = django111"
distributions: sdist bdist_wheel
repo: edx/opaque-keys
repo: edx/opaque-keys
3 changes: 0 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ clean: ## remove generated byte code, coverage reports, and build artifacts
html_coverage:
coverage html && open htmlcov/index.html

quality:
pycodestyle --config=.pep8 opaque_keys
pylint --rcfile=pylintrc opaque_keys

requirements:
pip install -r requirements/dev.txt
Expand Down
5 changes: 3 additions & 2 deletions opaque_keys/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
"""
from abc import ABCMeta, abstractmethod
from functools import total_ordering

from _collections import defaultdict
from six import (
iteritems,
python_2_unicode_compatible,
Expand All @@ -20,6 +18,9 @@
)
from stevedore.enabled import EnabledExtensionManager

# pylint: disable=wrong-import-order
from _collections import defaultdict


class InvalidKeyError(Exception):
"""
Expand Down
10 changes: 4 additions & 6 deletions opaque_keys/edx/django/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,7 @@ def to_python(self, value):
))
value = value.rstrip()
return self.KEY_CLASS.from_string(value)
else:
return value
return value

def get_prep_value(self, value):
if value is self.Empty or value is None:
Expand All @@ -147,15 +146,14 @@ def get_prep_value(self, value):
def validate(self, value, model_instance):
"""Validate Empty values, otherwise defer to the parent"""
# raise validation error if the use of this field says it can't be blank but it is
if not self.blank and value is self.Empty:
raise ValidationError(self.error_messages['blank'])
else:
if self.blank or value is not self.Empty:
return super(OpaqueKeyField, self).validate(value, model_instance)
raise ValidationError(self.error_messages['blank'])

def run_validators(self, value):
"""Validate Empty values, otherwise defer to the parent"""
if value is self.Empty:
return
return None

return super(OpaqueKeyField, self).run_validators(value)

Expand Down
2 changes: 0 additions & 2 deletions opaque_keys/edx/django/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
@pytest.fixture(autouse=True)
def enable_db_access_for_all_tests(db):
"""Enable DB access for all tests."""
pass


# pylint: disable=no-member
Expand All @@ -44,7 +43,6 @@ def test_load_model_from_db(self):

class EmptyKeyClassField(OpaqueKeyField):
"""An invalid class."""
pass


# pylint: disable=protected-access
Expand Down
5 changes: 3 additions & 2 deletions opaque_keys/edx/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,10 @@ def map_into_course(self, course_key):
Implement map_into_course for API compatibility. Shouldn't be used in
new code.
"""

if course_key == self.context_key:
return self
else:
raise ValueError("Cannot use map_into_course like that with this key type.")
raise ValueError("Cannot use map_into_course like that with this key type.")


class AsideDefinitionKey(DefinitionKey):
Expand Down Expand Up @@ -300,6 +300,7 @@ def default(self, key): # pylint: disable=arguments-differ, method-hidden
if isinstance(key, OpaqueKey):
return text_type(key)
super(i4xEncoder, self).default(key)
return None


class BlockTypeKey(OpaqueKey):
Expand Down
6 changes: 5 additions & 1 deletion opaque_keys/edx/locator.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,10 @@ def offering(self):
DeprecationWarning,
stacklevel=2
)

if not self.course and not self.run:
return None
elif not self.run and self.course:
if not self.run and self.course:
return self.course
return "/".join([self.course, self.run])

Expand Down Expand Up @@ -796,6 +797,7 @@ def _parse_block_ref(cls, block_ref, deprecated=False):
is_valid_deprecated = deprecated and cls.DEPRECATED_ALLOWED_ID_RE.match(block_ref)
is_valid = cls.ALLOWED_ID_RE.match(block_ref)

# pylint: disable=no-else-return
if is_valid or is_valid_deprecated:
return block_ref
else:
Expand Down Expand Up @@ -834,6 +836,8 @@ def offering(self):
DeprecationWarning,
stacklevel=2
)

# pylint: disable=no-else-return
if not self.course and not self.run:
return None
elif not self.run and self.course:
Expand Down
4 changes: 4 additions & 0 deletions opaque_keys/edx/tests/test_aside_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class TestEncode(TestCase):
"""Tests of encoding and decoding functions."""

@given(text=ENCODING_TEXT)
@settings(suppress_health_check=[HealthCheck.too_slow])
def test_encode_v1_roundtrip(self, text):
"""
Test all combinations that include characters we're trying to encode, or using in the encoding.
Expand All @@ -42,6 +43,7 @@ def test_encode_v1_roundtrip(self, text):
self.assertEqual(text, decoded)

@given(left=ENCODING_TEXT, right=ENCODING_TEXT)
@settings(suppress_health_check=[HealthCheck.too_slow])
def test_join_v1_roundtrip(self, left, right):
assume(not left.endswith(':'))
assume('::' not in left)
Expand All @@ -64,6 +66,7 @@ def test_decode_v1_roundtrip(self, text):
self.assertEqual(text, encoded)

@given(text=ENCODING_TEXT)
@settings(suppress_health_check=[HealthCheck.too_slow])
def test_encode_v2_roundtrip(self, text):
"""
Test all combinations that include characters we're trying to encode, or using in the encoding.
Expand All @@ -87,6 +90,7 @@ def test_decode_v2_roundtrip(self, text):
self.assertEqual(text, encoded)

@given(left=ENCODING_TEXT, right=ENCODING_TEXT)
@settings(suppress_health_check=[HealthCheck.too_slow])
def test_join_v2_roundtrip(self, left, right):
joined = _join_keys_v2(left, right)
(_left, _right) = _split_keys_v2(joined)
Expand Down
4 changes: 3 additions & 1 deletion opaque_keys/edx/tests/test_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import logging

from hypothesis import strategies, _strategies, given, assume, example
from hypothesis import strategies, _strategies, given, assume, example, HealthCheck, settings
from six import text_type
from six.moves import range # pylint: disable=redefined-builtin
from opaque_keys.edx.keys import CourseKey, UsageKey, DefinitionKey, BlockTypeKey, AssetKey
Expand Down Expand Up @@ -130,6 +130,7 @@ def perturbed_strings(string_strategy):
serialized=strategies.shared(valid_key_string(), key="diff_serial_diff_key"),
perturbed=perturbed_strings(strategies.shared(valid_key_string(), key="diff_serial_diff_key")),
)
@settings(suppress_health_check=[HealthCheck.too_slow])
@example(
key_type=DefinitionKey,
serialized='def-v1:000000000000000000000000+type@-',
Expand Down Expand Up @@ -195,6 +196,7 @@ def test_perturbed_serializations(key_type, serialized, perturbed):
serialized=valid_key_string(),
perturbed=valid_key_string(),
)
@settings(suppress_health_check=[HealthCheck.too_slow])
def test_unique_deserialization(key_type, serialized, perturbed):
assume(serialized != perturbed)

Expand Down
8 changes: 4 additions & 4 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
# make upgrade
#
pbr==5.2.0 # via stevedore
pymongo==3.8.0
six==1.12.0
stevedore==1.30.1
pbr==5.4.3 # via stevedore
pymongo==3.9.0
six==1.13.0
stevedore==1.31.0
105 changes: 55 additions & 50 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,84 +6,89 @@
#
alabaster==0.7.12
apipkg==1.5
asn1crypto==0.24.0
astroid==1.5.3
astroid==1.6.6
atomicwrites==1.3.0
attrs==19.1.0
babel==2.6.0
backports.functools-lru-cache==1.5
attrs==19.3.0
babel==2.7.0
backports.functools-lru-cache==1.6.1
bleach==3.1.0
certifi==2019.3.9
cffi==1.12.3
certifi==2019.9.11
cffi==1.13.2
chardet==3.0.4
click-log==0.3.2
click==7.0
configparser==3.7.4
coverage==4.5.3
coveralls==1.7.0
cryptography==2.6.1
configparser==4.0.2
contextlib2==0.6.0.post1
coverage==4.5.4
coveralls==1.8.2
cryptography==2.8
ddt==1.2.1
docopt==0.6.2
docutils==0.14
edx-lint==1.1.2
edx-sphinx-theme==1.4.0
docutils==0.15.2
edx-lint==1.4.1
edx-sphinx-theme==1.5.0
enum34==1.1.6
execnet==1.6.0
filelock==3.0.10
execnet==1.7.1
filelock==3.0.12
funcsigs==1.0.2
futures==3.2.0 ; python_version == "2.7"
hypothesis==4.23.4
futures==3.3.0 ; python_version == "2.7"
hypothesis==4.44.1
idna==2.8
imagesize==1.1.0
ipaddress==1.0.22
isort==4.3.20
jinja2==2.10.1
lazy-object-proxy==1.4.1
importlib-metadata==0.23
ipaddress==1.0.23
isort==4.3.21
jinja2==2.10.3
lazy-object-proxy==1.4.3
markupsafe==1.1.1
mccabe==0.6.1
mock==3.0.5
more-itertools==5.0.0
packaging==19.0
pathlib2==2.3.3
pbr==5.2.0
packaging==19.2
pathlib2==2.3.5
pbr==5.4.3
pep8==1.7.1
pip-tools==3.7.0
pluggy==0.11.0
pip-tools==4.2.0
pluggy==0.13.0
py==1.8.0
pycodestyle==2.5.0
pycparser==2.19
pygments==2.4.0
pygments==2.4.2
pylint-celery==0.3
pylint-django==0.7.2
pylint-plugin-utils==0.5
pylint==1.7.6
pymongo==3.8.0
pylint-django==0.11.1
pylint-plugin-utils==0.6
pylint==1.9.5
pymongo==3.9.0
pyopenssl==19.0.0
pyparsing==2.4.0
pyparsing==2.4.5
pytest-cache==1.0
pytest-cov==2.7.1
pytest-django==3.4.8
pytest-forked==1.0.2
pytest-cov==2.8.1
pytest-django==3.7.0
pytest-forked==1.1.3
pytest-pep8==1.0.6
pytest-pylint==0.14.0
pytest-xdist==1.28.0
pytest==4.5.0
pytz==2019.1
pytest-pylint==0.14.1
pytest-xdist==1.30.0
pytest==4.6.6
pytz==2019.3
readme-renderer==24.0
requests==2.21.0
requests==2.22.0
scandir==1.10.0
singledispatch==3.4.0.3
six==1.12.0
snowballstemmer==1.2.1
six==1.13.0
snowballstemmer==2.0.0
sphinx==1.8.5
sphinxcontrib-websupport==1.1.0
stevedore==1.30.1
sphinxcontrib-websupport==1.1.2
stevedore==1.31.0
toml==0.10.0
tox-battery==0.5.1
tox==3.11.0
typing==3.6.6
urllib3[secure]==1.24.3
virtualenv==16.6.0
tox==3.14.0
typing==3.7.4.1
urllib3[secure]==1.25.7
virtualenv==16.7.7
wcwidth==0.1.7
webencodings==0.5.1
wrapt==1.11.1
wrapt==1.11.2
zipp==0.6.0

# The following packages are considered to be unsafe in a requirements file:
# setuptools==41.6.0 # via sphinx
Loading

0 comments on commit 277ffe7

Please sign in to comment.