'Verifies that create_bookmark do not create duplicate bookmarks.'

@patch('openedx.core.djangoapps.bookmarks.api.tracker.emit')
def test_create_bookmark_do_not_create_duplicates(self, mock_tracker):

    self.assertEqual(len(api.get_bookmarks(user=self.user, course_key=self.course.id)), 2)
    with self.assertNumQueries(9):
        bookmark_data = api.create_bookmark(user=self.user, usage_key=self.vertical_2.location)
    self.assert_bookmark_event_emitted(mock_tracker, event_name='edx.bookmark.added', course_id=unicode(self.course_id), bookmark_id=bookmark_data['id'], component_type=self.vertical_2.location.block_type, component_usage_id=unicode(self.vertical_2.location))
    self.assertEqual(len(api.get_bookmarks(user=self.user, course_key=self.course.id)), 3)
    mock_tracker.reset_mock()
    with self.assertNumQueries(5):
        bookmark_data_2 = api.create_bookmark(user=self.user, usage_key=self.vertical_2.location)
    self.assertEqual(len(api.get_bookmarks(user=self.user, course_key=self.course.id)), 3)
    self.assertEqual(bookmark_data, bookmark_data_2)
    self.assert_no_events_were_emitted(mock_tracker)
