'Dry method to generate course modes dict and test with response data.'

def _assert_generated_modes(self, response):

    modes = CourseMode.modes_for_course(self.course.id, include_expired=True)
    modes_data = []
    for mode in modes:
        expiry = (mode.expiration_datetime.strftime('%Y-%m-%dT%H:%M:%SZ') if mode.expiration_datetime else None)
        modes_data.append({'sku': mode.sku, 'expiration_datetime': expiry, 'name': mode.name, 'currency': mode.currency, 'bulk_sku': mode.bulk_sku, 'min_price': mode.min_price, 'suggested_prices': mode.suggested_prices, 'slug': mode.slug, 'description': mode.description})
    self.assertEqual(response.status_code, 200)
    data = json.loads(response.content)
    self.assertEqual(len(data), 1)
    self.assertEqual(modes_data, data[0]['course_modes'])
    self.assertEqual({CourseMode.VERIFIED, CourseMode.AUDIT, CourseMode.NO_ID_PROFESSIONAL_MODE, CourseMode.PROFESSIONAL, CourseMode.HONOR}, {mode['slug'] for mode in data[0]['course_modes']})
