'Scenario: When students are added to a cohort, the appropriate notification is shown.
Given I have a course with two cohorts
And there is a user in one cohort
And there is a user in neither cohort
When I add the two users to the cohort that initially had no users
Then there are 2 users in total in the cohort
And I get a notification that 2 users have been added to the cohort
And I get a notification that 1 user was moved from the other cohort
And the user input field is empty
And appropriate events have been emitted'

def test_add_students_to_cohort_success(self):

    start_time = datetime.now(UTC)
    self.cohort_management_page.select_cohort(self.auto_cohort_name)
    self.assertEqual(0, self.cohort_management_page.get_selected_cohort_count())
    self.cohort_management_page.add_students_to_selected_cohort([self.student_name, self.instructor_name])
    EmptyPromise((lambda : (2 == self.cohort_management_page.get_selected_cohort_count())), 'Waiting    for    added    students').fulfill()
    confirmation_messages = self.cohort_management_page.get_cohort_confirmation_messages()
    self.assertEqual(['2    learners    have    been    added    to    this    cohort.', ('1    learner    was    moved    from    ' + self.manual_cohort_name)], confirmation_messages)
    self.assertEqual('', self.cohort_management_page.get_cohort_student_input_field_value())
    self.assertEqual(self.event_collection.find({'name': 'edx.cohort.user_added', 'time': {'$gt': start_time}, 'event.user_id': {'$in': [int(self.instructor_id), int(self.student_id)]}, 'event.cohort_name': self.auto_cohort_name}).count(), 2)
    self.assertEqual(self.event_collection.find({'name': 'edx.cohort.user_removed', 'time': {'$gt': start_time}, 'event.user_id': int(self.student_id), 'event.cohort_name': self.manual_cohort_name}).count(), 1)
    self.assertEqual(self.event_collection.find({'name': 'edx.cohort.user_add_requested', 'time': {'$gt': start_time}, 'event.user_id': int(self.instructor_id), 'event.cohort_name': self.auto_cohort_name, 'event.previous_cohort_name': None}).count(), 1)
    self.assertEqual(self.event_collection.find({'name': 'edx.cohort.user_add_requested', 'time': {'$gt': start_time}, 'event.user_id': int(self.student_id), 'event.cohort_name': self.auto_cohort_name, 'event.previous_cohort_name': self.manual_cohort_name}).count(), 1)
