'Verifies that create_bookmark raises error when maximum number of units
allowed to bookmark per course are already bookmarked.'

@patch('openedx.core.djangoapps.bookmarks.api.tracker.emit')
@patch('django.conf.settings.MAX_BOOKMARKS_PER_COURSE', 5)
def bookmark_more_than_limit_raise_error(self, mock_tracker):

    max_bookmarks = settings.MAX_BOOKMARKS_PER_COURSE
    (__, blocks, __) = self.create_course_with_bookmarks_count(max_bookmarks)
    with self.assertNumQueries(1):
        with self.assertRaises(BookmarksLimitReachedError):
            api.create_bookmark(user=self.user, usage_key=blocks[(-1)].location)
    self.assert_no_events_were_emitted(mock_tracker)
    self.assertEqual(len(api.get_bookmarks(user=self.user, course_key=self.other_course.id)), 1)
    api.create_bookmark(user=self.user, usage_key=self.other_chapter_1.location)
    self.assertEqual(len(api.get_bookmarks(user=self.user, course_key=self.other_course.id)), 2)
    self.assertEqual(len(api.get_bookmarks(user=self.other_user, course_key=blocks[(-1)].location.course_key)), 0)
    api.create_bookmark(user=self.other_user, usage_key=blocks[(-1)].location)
    self.assertEqual(len(api.get_bookmarks(user=self.other_user, course_key=blocks[(-1)].location.course_key)), 1)
