<commit_before>from django.conf import settings
from django.dispatch import receiver
from django.test import TestCase

from opaque_keys.edx.keys import CourseKey

from milestones import api

from mocks import signals as mock_signals

class ReceiverTestCase(TestCase):

    def setUp(self):
        self.signal_log = []
        self.test_course_key = CourseKey.from_string('the/course/key')
        self.test_prerequisite_course_key = CourseKey.from_string('prerequisite/course/key')
        self.test_milestone_data = {
            'name': 'Test Milestone',
            'namespace': unicode(self.test_prerequisite_course_key),
            'description': 'This is only a test.',
        }

    def test_on_course_deleted(self):
        # Note, this test adds a milestone and two course links
        # We're going to confirm that all three entities are removed

        # Add a new milestone and links to the system
        milestone = api.add_milestone(milestone=self.test_milestone_data)
        milestones = api.add_course_milestone(course_key=self.test_course_key, relationship='requires', milestone=milestone)
        milestones = api.add_course_milestone(course_key=self.test_prerequisite_course_key, relationship='fulfills', milestone=milestone)

        # Inform the milestones app that the prerequisite course has
        # now been removed from the system.
        mock_signals.course_deleted.send(
            sender=self,
            course_key=self.test_prerequisite_course_key
        )

        # Confirm the milestone and links no longer exist
        milestones = api.get_milestones(namespace=unicode(self.test_prerequisite_course_key))
        self.assertEqual(len(milestones), 0)

        course_milestones = api.get_course_milestones(course_key=self.test_course_key)
        self.assertEqual(len(course_milestones), 0)

        prereq_milestones = api.get_course_milestones(course_key=self.test_prerequisite_course_key)
        self.assertEqual(len(prereq_milestones), 0)

    # def test_on_course_prerequisite_course_added(self):

    #     # Broadcast the event to the application
    #     mock_signals.course_prerequisite_course_added.send(
    #         sender=self,
    #         course_key=self.test_course_key,
    #         prerequisite_course_key=self.test_prerequisite_course_key,
    #     )

    #     # Confirm the prerequisite course fulfills its generic milestone
    #     # The namespace for generic course milestones is the course identifier
    #     prereq_milestones = api.get_course_milestones(course_key=self.test_prerequisite_course_key, relationship='fulfills')
    #     self.assertEqual(unicode(self.test_prerequisite_course_key), prereq_milestones[0]['namespace'])

    #     # Confirm the main course requires the prerequisite course's generic milestone
    #     course_milestones = api.get_course_milestones(course_key=self.test_course_key, relationship='requires')
    #     self.assertEqual(unicode(self.test_prerequisite_course_key), course_milestones[0]['namespace'])

    # def test_on_course_prerequisite_course_removed(self):

    #     # Broadcast the events to the application
    #     mock_signals.course_prerequisite_course_added.send(
    #         sender=self,
    #         course_key=self.test_course_key,
    #         prerequisite_course_key=self.test_prerequisite_course_key,
    #     )

    #     # Confirm the prerequisite course fulfills its generic milestone
    #     prereq_milestones = api.get_course_milestones(course_key=self.test_prerequisite_course_key, relationship='fulfills')
    #     self.assertEqual(unicode(self.test_prerequisite_course_key), prereq_milestones[0]['namespace'])

    #     # Confirm the main course requires the prerequisite course's generic milestone
    #     course_milestones = api.get_course_milestones(course_key=self.test_course_key, relationship='requires')
    #     self.assertEqual(len(course_milestones), 1)


    #     mock_signals.course_prerequisite_course_removed.send(
    #         sender=self,
    #         course_key=self.test_course_key,
    #         prerequisite_course_key=self.test_prerequisite_course_key,
    #     )

    #     # Confirm the prerequisite course still fulfills its generic milestone
    #     prereq_milestones = api.get_course_milestones(course_key=self.test_prerequisite_course_key, relationship='fulfills')
    #     self.assertEqual(unicode(self.test_prerequisite_course_key), prereq_milestones[0]['namespace'])

    #     # Confirm the main course no longer requires the prerequisite course's generic milestone
    #     course_milestones = api.get_course_milestones(course_key=self.test_course_key, relationship='requires')
    #     self.assertEqual(len(course_milestones), 0)<commit_msg>Addressed pep8 violations<commit_after>from django.conf import settings
from django.dispatch import receiver
from django.test import TestCase

from opaque_keys.edx.keys import CourseKey

from milestones import api

from mocks import signals as mock_signals


class ReceiverTestCase(TestCase):

    def setUp(self):
        self.signal_log = []
        self.test_course_key = CourseKey.from_string('the/course/key')
        self.test_prerequisite_course_key = CourseKey.from_string('prerequisite/course/key')
        self.test_milestone_data = {
            'name': 'Test Milestone',
            'namespace': unicode(self.test_prerequisite_course_key),
            'description': 'This is only a test.',
        }

    def test_on_course_deleted(self):
        # Note, this test adds a milestone and two course links
        # We're going to confirm that all three entities are removed

        # Add a new milestone and links to the system
        milestone = api.add_milestone(milestone=self.test_milestone_data)
        milestones = api.add_course_milestone(course_key=self.test_course_key, relationship='requires', milestone=milestone)
        milestones = api.add_course_milestone(course_key=self.test_prerequisite_course_key, relationship='fulfills', milestone=milestone)

        # Inform the milestones app that the prerequisite course has
        # now been removed from the system.
        mock_signals.course_deleted.send(
            sender=self,
            course_key=self.test_prerequisite_course_key
        )

        # Confirm the milestone and links no longer exist
        milestones = api.get_milestones(namespace=unicode(self.test_prerequisite_course_key))
        self.assertEqual(len(milestones), 0)

        course_milestones = api.get_course_milestones(course_key=self.test_course_key)
        self.assertEqual(len(course_milestones), 0)

        prereq_milestones = api.get_course_milestones(course_key=self.test_prerequisite_course_key)
        self.assertEqual(len(prereq_milestones), 0)
{'fraction_non_alphanumeric': 0.07575085071756177, 'fraction_numerical': 0.0019233614440005919, 'mean_word_length': 3.710801393728223, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1538131', 'n_tokens_mistral': 2093, 'n_tokens_neox': 1908, 'n_words': 378}