Skip to content

Commit

Permalink
Merge pull request #35 from edx/feanil/update_metadata
Browse files Browse the repository at this point in the history
Add python 3 support.
  • Loading branch information
feanil authored Jun 6, 2019
2 parents 1d2c054 + 8fff540 commit 0673ca0
Show file tree
Hide file tree
Showing 35 changed files with 93 additions and 38 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

# Packaging files:
*.eggs
*.egg-info

# Installation artifacts
src
Expand Down
19 changes: 11 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,35 @@
language: python

python:
- 2.7
- 3.6

env:
- TOXENV=django18
- TOXENV=django111

matrix:
include:
- python: 2.7
env: TOXENV=quality
- python: 3.6
env: TOXENV=py36
allow_failures:
- python: 3.6
env: TOXENV=quality

before_install:
- export DJANGO_SETTINGS_MODULE=settings

install:
- make install
sudo: false

script:
- make test

after_success: coveralls

deploy:
provider: pypi
user: edx
distributions: sdist bdist_wheel
on:
tags: true
python: 2.7
python: 3.6
condition: '$TOXENV = django111'
password:
secure: oVeS9OrvR5XvJMg86eO004xk9KFh9IbUxWqyWYYFZf1drtrzG2Bm7+F0BgF1hY2l+qyHXinPCCeBmV9CEfav80se1r8K0JFu9MwBHQkvaeBAJV+ItQ2ZumtgNNONoL5VZHIRbEYwl/lbZCWaXpmDLkJSlRVYCECP2bH+RcZkbQM=
1 change: 1 addition & 0 deletions manage.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python
from __future__ import absolute_import, unicode_literals
import os
import sys

Expand Down
3 changes: 2 additions & 1 deletion milestones/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""
Milestones app initialization module
"""
__version__ = '0.1.13'
from __future__ import unicode_literals
__version__ = '0.2.0'
1 change: 1 addition & 0 deletions milestones/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Admin module for milestones app
"""
from __future__ import absolute_import, unicode_literals
from django.contrib import admin

from milestones.models import (
Expand Down
3 changes: 2 additions & 1 deletion milestones/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
Note the terminology difference at this layer vs. Data -- add/edit/get/remove
"""
from __future__ import absolute_import, unicode_literals
from . import data
from . import exceptions
from . import validators
Expand Down Expand Up @@ -218,7 +219,7 @@ def get_course_milestones_fulfillment_paths(course_key, user):
# Build the set of fulfillment paths for the outstanding milestones
fulfillment_paths = {}
for milestone in required_milestones:
dict_key = '{}.{}'.format(milestone['namespace'].encode('utf-8'), milestone['name'].encode('utf-8'))
dict_key = '{}.{}'.format(milestone['namespace'], milestone['name'])
fulfillment_paths[dict_key] = {}
milestone_courses = data.fetch_milestone_courses(
milestone,
Expand Down
8 changes: 5 additions & 3 deletions milestones/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@
else:
import milestones.resources as remote
"""
from __future__ import absolute_import
from __future__ import absolute_import, unicode_literals

import six

from . import exceptions
from . import models as internal
from . import serializers
import six


# PRIVATE/INTERNAL METHODS (public methods located further down)
Expand Down Expand Up @@ -176,7 +178,7 @@ def fetch_milestone(milestone_id):
exceptions.raise_exception("Milestone", {'id': milestone_id}, exceptions.InvalidMilestoneException)
milestone = {'id': milestone_id}
milestones = fetch_milestones(milestone)
if not len(milestones):
if not milestones:
exceptions.raise_exception("Milestone", milestone, exceptions.InvalidMilestoneException)
return milestones[0]

Expand Down
1 change: 1 addition & 0 deletions milestones/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Application-specific exception classes used throughout the implementation
"""
from __future__ import absolute_import, unicode_literals
from django.core.exceptions import ValidationError


Expand Down
2 changes: 2 additions & 0 deletions milestones/management/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""
Milestones management package initialization module
"""

from __future__ import unicode_literals
2 changes: 2 additions & 0 deletions milestones/management/commands/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""
Milestones management commands package initialization module
"""

from __future__ import unicode_literals
2 changes: 2 additions & 0 deletions milestones/management/commands/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""
Milestones management commands tests package initialization module
"""

from __future__ import unicode_literals
1 change: 1 addition & 0 deletions milestones/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from __future__ import absolute_import
from django.db import models, migrations
import django.utils.timezone
import model_utils.fields
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from __future__ import absolute_import
from django.db import migrations, models

from milestones.data import fetch_milestone_relationship_types
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from __future__ import absolute_import
from django.db import migrations, models


Expand Down
1 change: 1 addition & 0 deletions milestones/migrations/0004_auto_20151221_1445.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from __future__ import absolute_import
from django.db import migrations, models


Expand Down
2 changes: 2 additions & 0 deletions milestones/migrations/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""
Milestones migrations package initialization module
"""

from __future__ import unicode_literals
27 changes: 17 additions & 10 deletions milestones/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@
which leverages Django's signal framework.
"""

from __future__ import absolute_import, unicode_literals
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
from model_utils.models import TimeStampedModel


@python_2_unicode_compatible
class Milestone(TimeStampedModel):
"""
A Milestone is a representation of an accomplishment which can be
Expand All @@ -31,10 +34,11 @@ class Meta:
""" Meta class for this Django model """
unique_together = (("namespace", "name"),)

def __unicode__(self):
return unicode(self.namespace)
def __str__(self):
return self.namespace


@python_2_unicode_compatible
class MilestoneRelationshipType(TimeStampedModel):
"""
A MilestoneRelationshipType represents a category of link available
Expand All @@ -60,8 +64,8 @@ class MilestoneRelationshipType(TimeStampedModel):
description = models.TextField(blank=True)
active = models.BooleanField(default=True)

def __unicode__(self):
return unicode(self.name)
def __str__(self):
return self.name

@classmethod
# pylint: disable=invalid-name
Expand All @@ -74,6 +78,7 @@ def get_supported_milestone_relationship_types(cls):
return RELATIONSHIP_TYPE_CHOICES


@python_2_unicode_compatible
class CourseMilestone(TimeStampedModel):
"""
A CourseMilestone represents the link between a Course and a
Expand All @@ -93,10 +98,11 @@ class Meta:
""" Meta class for this Django model """
unique_together = (("course_id", "milestone"),)

def __unicode__(self):
return unicode("%s:%s:%s" % (self.course_id, self.milestone_relationship_type, self.milestone))
def __str__(self):
return "%s:%s:%s" % (self.course_id, self.milestone_relationship_type, self.milestone)


@python_2_unicode_compatible
class CourseContentMilestone(TimeStampedModel):
"""
A CourseContentMilestone represents the link between a specific
Expand Down Expand Up @@ -124,10 +130,11 @@ class Meta:
""" Meta class for this Django model """
unique_together = (("course_id", "content_id", "milestone"),)

def __unicode__(self):
return unicode("%s:%s:%s" % (self.content_id, self.milestone_relationship_type, self.milestone))
def __str__(self):
return "%s:%s:%s" % (self.content_id, self.milestone_relationship_type, self.milestone)


@python_2_unicode_compatible
class UserMilestone(TimeStampedModel):
"""
A UserMilestone represents an stage reached or event experienced
Expand All @@ -153,5 +160,5 @@ class Meta:
""" Meta class for this Django model """
unique_together = ("user_id", "milestone")

def __unicode__(self):
return unicode("%s:%s" % (self.user_id, self.milestone))
def __str__(self):
return "%s:%s" % (self.user_id, self.milestone)
2 changes: 2 additions & 0 deletions milestones/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@
This module should only be called directly by data.py, in order to
maintain the intended data layer abstractions/contracts.
"""

from __future__ import unicode_literals
1 change: 1 addition & 0 deletions milestones/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Data layer serialization operations. Converts querysets to simple
python containers (mainly arrays and dicts).
"""
from __future__ import absolute_import, unicode_literals
import json

from . import models
Expand Down
1 change: 1 addition & 0 deletions milestones/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
A wrapper class around requested methods exposed in api.py
"""

from __future__ import absolute_import, unicode_literals
import types

from milestones import api as milestones_api
Expand Down
2 changes: 2 additions & 0 deletions milestones/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""
Milestones Tests initialization module
"""

from __future__ import unicode_literals
2 changes: 2 additions & 0 deletions milestones/tests/mocks/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
""" Milestones Tests Mocks initialization module """

from __future__ import unicode_literals
2 changes: 2 additions & 0 deletions milestones/tests/mocks/resources.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""
Mock implementations of remote dependencies for test isolation
"""

from __future__ import unicode_literals
3 changes: 2 additions & 1 deletion milestones/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"""
Milestones API Module Test Cases
"""
from __future__ import absolute_import
from __future__ import absolute_import, unicode_literals

from opaque_keys.edx.keys import UsageKey

import milestones.api as api
Expand Down
2 changes: 1 addition & 1 deletion milestones/tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Note: 'Unit Test: ' labels are output to the console during test runs
"""
from __future__ import absolute_import
from __future__ import absolute_import, unicode_literals
import milestones.api as api
import milestones.data as data
import milestones.exceptions as exceptions
Expand Down
1 change: 1 addition & 0 deletions milestones/tests/test_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Test for the xBlock service
"""

from __future__ import absolute_import, unicode_literals
import unittest
import types

Expand Down
1 change: 1 addition & 0 deletions milestones/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"""
Utility module for Milestones test cases
"""
from __future__ import absolute_import, unicode_literals
from django.contrib.auth.models import User
from django.test import TestCase
from opaque_keys.edx.keys import CourseKey, UsageKey
Expand Down
2 changes: 2 additions & 0 deletions milestones/urls.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""
urls.py -- useful some day when views.py comes alive
"""

from __future__ import unicode_literals
9 changes: 5 additions & 4 deletions milestones/validators.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
"""
Validators confirm the integrity of inbound information prior to a data.py handoff
"""
from __future__ import absolute_import
from __future__ import absolute_import, unicode_literals

import json
import six

from opaque_keys import InvalidKeyError
from opaque_keys.edx.keys import CourseKey, UsageKey

from .data import fetch_milestone_relationship_types
import six


def course_key_is_valid(course_key):
Expand Down Expand Up @@ -62,9 +63,9 @@ def milestone_data_is_valid(milestone_data):
return False
if 'id' in milestone_data and not milestone_data.get('id'):
return False
if 'name' in milestone_data and not len(milestone_data.get('name')):
if 'name' in milestone_data and not milestone_data.get('name'):
return False
if 'namespace' in milestone_data and not len(milestone_data.get('namespace')):
if 'namespace' in milestone_data and not milestone_data.get('namespace'):
return False
return True

Expand Down
2 changes: 2 additions & 0 deletions milestones/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
In this particular application, the views simply hand-off to the
orchestration layer, which manages the application's workflows.
"""

from __future__ import unicode_literals
2 changes: 1 addition & 1 deletion openedx.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
oeps:
oep-7: false
oep-7: true
oep-18: false

tags:
Expand Down
1 change: 1 addition & 0 deletions settings.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import unicode_literals
DEBUG=True
TEST_MODE=True
TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'
Expand Down
Loading

0 comments on commit 0673ca0

Please sign in to comment.