'Verify that org filtering performs as expected, and that an empty result
is returned if the org passed by the caller does not match the designated
org.'

def test_get_courses_by_org(self):

    primary = 'primary'
    alternate = 'alternate'
    def _fake_get_value(value, default=None):
        'Used    to    stub    out    site_configuration.helpers.get_value().'
        if (value == 'course_org_filter'):
            return alternate
        return default
    user = UserFactory.create()
    primary_course = CourseFactory.create(org=primary, emit_signals=True)
    alternate_course = CourseFactory.create(org=alternate, emit_signals=True)
    self.assertNotEqual(primary_course.org, alternate_course.org)
    unfiltered_courses = get_courses(user)
    for org in [primary_course.org, alternate_course.org]:
        self.assertTrue(any(((course.org == org) for course in unfiltered_courses)))
    filtered_courses = get_courses(user, org=primary)
    self.assertTrue(all(((course.org == primary_course.org) for course in filtered_courses)))
    with mock.patch('openedx.core.djangoapps.site_configuration.helpers.get_value', autospec=True) as mock_get_value:
        mock_get_value.side_effect = _fake_get_value
        no_courses = get_courses(user, org=primary)
        self.assertEqual(no_courses, [])
        site_courses = get_courses(user, org=alternate)
        self.assertTrue(all(((course.org == alternate_course.org) for course in site_courses)))
