'Enrollment attributes should always be written, regardless of whether
the enrollment is being created or updated.'

def test_enrollment_attributes_always_written(self):

    course_key = self.course.id
    for mode in [CourseMode.DEFAULT_MODE_SLUG, CourseMode.VERIFIED]:
        CourseModeFactory.create(course_id=course_key, mode_slug=mode, mode_display_name=mode)
    order_number = 'EDX-1000'
    enrollment_attributes = [{'namespace': 'order', 'name': 'order_number', 'value': order_number}]
    mode = CourseMode.VERIFIED
    self.assert_enrollment_status(as_server=True, is_active=True, mode=mode, enrollment_attributes=enrollment_attributes)
    enrollment = CourseEnrollment.objects.get(user=self.user, course_id=course_key)
    self.assertTrue(enrollment.is_active)
    self.assertEqual(enrollment.mode, CourseMode.VERIFIED)
    self.assertEqual(enrollment.attributes.get(namespace='order', name='order_number').value, order_number)
    order_number = 'EDX-2000'
    enrollment_attributes = [{'namespace': 'order', 'name': 'order_number', 'value': order_number}]
    mode = CourseMode.DEFAULT_MODE_SLUG
    self.assert_enrollment_status(as_server=True, mode=mode, enrollment_attributes=enrollment_attributes)
    enrollment.refresh_from_db()
    self.assertTrue(enrollment.is_active)
    self.assertEqual(enrollment.mode, mode)
    self.assertEqual(enrollment.attributes.get(namespace='order', name='order_number').value, order_number)
