'indexing course with content groups added test'

def test_content_group_gets_indexed(self):

    added_to_index = self.reindex_course(self.store)
    self.assertEqual(added_to_index, 16)
    response = self.searcher.search(field_dictionary={'course': unicode(self.course.id)})
    self.assertEqual(response['total'], 17)
    group_access_content = {'group_access': {666: [1]}}
    self.client.ajax_post(reverse_usage_url('xblock_handler', self.html_unit1.location), data={'metadata': group_access_content})
    self.publish_item(self.store, self.html_unit1.location)
    self.publish_item(self.store, self.split_test_unit.location)
    with patch((settings.SEARCH_ENGINE + '.index')) as mock_index:
        self.reindex_course(self.store)
        self.assertTrue(mock_index.called)
        indexed_content = self._get_index_values_from_call_args(mock_index)
        self.assertIn(self._html_group_result(self.html_unit1, [1]), indexed_content)
        self.assertIn(self._html_experiment_group_result(self.html_unit4, [unicode(2)]), indexed_content)
        self.assertIn(self._html_experiment_group_result(self.html_unit5, [unicode(3)]), indexed_content)
        self.assertIn(self._html_experiment_group_result(self.html_unit6, [unicode(4)]), indexed_content)
        self.assertNotIn(self._html_experiment_group_result(self.html_unit6, [unicode(5)]), indexed_content)
        self.assertIn(self._vertical_experiment_group_result(self.condition_0_vertical, [unicode(2)]), indexed_content)
        self.assertNotIn(self._vertical_experiment_group_result(self.condition_1_vertical, [unicode(2)]), indexed_content)
        self.assertNotIn(self._vertical_experiment_group_result(self.condition_2_vertical, [unicode(2)]), indexed_content)
        self.assertNotIn(self._vertical_experiment_group_result(self.condition_0_vertical, [unicode(3)]), indexed_content)
        self.assertIn(self._vertical_experiment_group_result(self.condition_1_vertical, [unicode(3)]), indexed_content)
        self.assertNotIn(self._vertical_experiment_group_result(self.condition_2_vertical, [unicode(3)]), indexed_content)
        self.assertNotIn(self._vertical_experiment_group_result(self.condition_0_vertical, [unicode(4)]), indexed_content)
        self.assertNotIn(self._vertical_experiment_group_result(self.condition_1_vertical, [unicode(4)]), indexed_content)
        self.assertIn(self._vertical_experiment_group_result(self.condition_2_vertical, [unicode(4)]), indexed_content)
        mock_index.reset_mock()
