Skip to content

Commit

Permalink
Merge 803c7f0 into 4088018
Browse files Browse the repository at this point in the history
  • Loading branch information
Muzaffar yousaf committed Nov 10, 2015
2 parents 4088018 + 803c7f0 commit a1ff642
Show file tree
Hide file tree
Showing 8 changed files with 161 additions and 271 deletions.
278 changes: 111 additions & 167 deletions milestones/migrations/0001_initial.py

Large diffs are not rendered by default.

36 changes: 36 additions & 0 deletions milestones/migrations/0002_data__seed_relationship_types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models

from milestones.data import fetch_milestone_relationship_types


def seed_relationship_types(apps, schema_editor):
"""Seed the relationship types."""
MilestoneRelationshipType = apps.get_model("milestones", "MilestoneRelationshipType")
db_alias = schema_editor.connection.alias
for name in fetch_milestone_relationship_types().values():
MilestoneRelationshipType.objects.using(db_alias).get_or_create(
name=name,
description='Autogenerated milestone relationship type "{}"'.format(name),
)


def delete_relationship_types(apps, schema_editor):
"""Clean up any relationships we made."""
MilestoneRelationshipType = apps.get_model("milestones", "MilestoneRelationshipType")
db_alias = schema_editor.connection.alias
for name in fetch_milestone_relationship_types().values():
MilestoneRelationshipType.objects.using(db_alias).filter(name=name).delete()


class Migration(migrations.Migration):

dependencies = [
('milestones', '0001_initial'),
]

operations = [
migrations.RunPython(seed_relationship_types, delete_relationship_types),
]
87 changes: 0 additions & 87 deletions milestones/migrations/0002_seed_relationship_types.py

This file was deleted.

20 changes: 10 additions & 10 deletions milestones/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,14 @@ def test_get_milestone_invalid_milestone(self):

def test_remove_milestone(self):
""" Unit Test: test_remove_milestone """
with self.assertNumQueries(6):
with self.assertNumQueries(5):
api.remove_milestone(self.test_milestone['id'])
with self.assertRaises(exceptions.InvalidMilestoneException):
api.get_milestone(self.test_milestone['id'])

def test_remove_milestone_bogus_milestone(self):
""" Unit Test: test_remove_milestone_bogus_milestone """
with self.assertNumQueries(6):
with self.assertNumQueries(5):
api.remove_milestone(self.test_milestone['id'])

with self.assertRaises(exceptions.InvalidMilestoneException):
Expand Down Expand Up @@ -264,7 +264,7 @@ def test_add_course_milestone_inactive_to_active(self):
self.test_milestone
)
api.remove_course_milestone(self.test_course_key, self.test_milestone)
with self.assertNumQueries(5):
with self.assertNumQueries(4):
api.add_course_milestone(
self.test_course_key,
self.relationship_types['REQUIRES'],
Expand Down Expand Up @@ -412,7 +412,7 @@ def test_remove_course_milestone(self):
self.relationship_types['REQUIRES']
)
self.assertEqual(len(requirer_milestones), 1)
with self.assertNumQueries(4):
with self.assertNumQueries(3):
api.remove_course_milestone(self.test_course_key, self.test_milestone)
requirer_milestones = api.get_course_milestones(self.test_course_key)
self.assertEqual(len(requirer_milestones), 0)
Expand Down Expand Up @@ -482,7 +482,7 @@ def test_add_course_content_milestone_inactive_to_active(self):
self.test_content_key,
self.test_milestone
)
with self.assertNumQueries(5):
with self.assertNumQueries(4):
api.add_course_content_milestone(
self.test_course_key,
self.test_content_key,
Expand Down Expand Up @@ -558,7 +558,7 @@ def test_remove_course_content_milestone(self):
self.relationship_types['REQUIRES']
)
self.assertEqual(len(requirer_milestones), 1)
with self.assertNumQueries(4):
with self.assertNumQueries(3):
api.remove_course_content_milestone(
self.test_course_key,
self.test_content_key,
Expand Down Expand Up @@ -601,7 +601,7 @@ def test_add_user_milestone_inactive_to_active(self):
""" Unit Test: test_add_user_milestone """
api.add_user_milestone(self.serialized_test_user, self.test_milestone)
api.remove_user_milestone(self.serialized_test_user, self.test_milestone)
with self.assertNumQueries(4):
with self.assertNumQueries(3):
api.add_user_milestone(self.serialized_test_user, self.test_milestone)
self.assertTrue(api.user_has_milestone(self.serialized_test_user, self.test_milestone))

Expand All @@ -624,7 +624,7 @@ def test_remove_user_milestone(self):
""" Unit Test: test_remove_user_milestone """
api.add_user_milestone(self.serialized_test_user, self.test_milestone)
self.assertTrue(api.user_has_milestone(self.serialized_test_user, self.test_milestone))
with self.assertNumQueries(3):
with self.assertNumQueries(2):
api.remove_user_milestone(self.serialized_test_user, self.test_milestone)
self.assertFalse(api.user_has_milestone(self.serialized_test_user, self.test_milestone))

Expand Down Expand Up @@ -664,7 +664,7 @@ def test_remove_course_references(self):
len(api.get_course_content_milestones(self.test_course_key, self.test_content_key)), 1)

# Remove the course dependency
with self.assertNumQueries(6):
with self.assertNumQueries(4):
api.remove_course_references(self.test_course_key)
self.assertEqual(len(api.get_course_milestones(self.test_course_key)), 0)

Expand All @@ -689,7 +689,7 @@ def test_remove_content_references(self):
self.assertEqual(len(milestones), 1)

# Remove the content dependency
with self.assertNumQueries(3):
with self.assertNumQueries(2):
api.remove_content_references(self.test_content_key)
milestones = api.get_course_content_milestones(self.test_course_key, self.test_content_key)
self.assertEqual(len(milestones), 0)
Expand Down
2 changes: 1 addition & 1 deletion milestones/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def setUp(self):
self.test_course_key = CourseKey.from_string('the/course/key')
self.test_prerequisite_course_key = CourseKey.from_string('the/prerequisite/key')
self.test_content_key = UsageKey.from_string('i4x://the/content/key/12345678')
self.test_user = User.objects.create(
self.test_user = User.objects.create_user(
first_name='Test',
last_name='User',
email='test_user@edx.org',
Expand Down
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Django/Framework Packages
django==1.4.12
django>=1.8,<1.9
django-model-utils==2.3.1
South>=0.7.6

# Testing Packages
coverage==3.7.1
Expand Down
1 change: 0 additions & 1 deletion settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

'milestones',
'django_nose',
'south',
)

MIDDLEWARE_CLASSES = {}
5 changes: 2 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

setup(
name='edx-milestones',
version='0.1.3',
version='0.1.4',
description='Significant events module for Open edX',
long_description=open('README.md').read(),
author='edX',
Expand All @@ -23,9 +23,8 @@
dependency_links=[
],
install_requires=[
"django>=1.4.12",
"django>=1.8,<1.9",
"django-model-utils==1.4.0",
"South>=0.7.6",
],
tests_require=[
"coverage==3.7.1",
Expand Down

0 comments on commit a1ff642

Please sign in to comment.