'Verify user gets redirected to ecommerce checkout when ecommerce checkout is enabled.'

@httpretty.activate
@override_settings(ECOMMERCE_API_URL=TEST_API_URL, ECOMMERCE_PUBLIC_URL_ROOT=TEST_PUBLIC_URL_ROOT)
def test_start_flow_with_ecommerce(self):

    sku = 'TESTSKU'
    httpretty.register_uri(httpretty.GET, '{}/payment/processors/'.format(TEST_API_URL), body=json.dumps(['foo', 'bar']), content_type='application/json')
    configuration = CommerceConfiguration.objects.create(checkout_on_ecommerce_service=True)
    checkout_page = configuration.MULTIPLE_ITEMS_BASKET_PAGE_URL
    checkout_page += '?utm_source=test'
    httpretty.register_uri(httpretty.GET, '{}{}'.format(TEST_PUBLIC_URL_ROOT, checkout_page))
    course = self._create_course('verified', sku=sku)
    self._enroll(course.id)
    url_with_utm = 'http://www.example.com/basket/add/?utm_source=test&sku=TESTSKU'
    with mock.patch.object(EcommerceService, 'get_checkout_page_url', return_value=url_with_utm):
        response = self._get_page('verify_student_start_flow', course.id, expected_status_code=302)
    expected_page = '{}{}&sku={}'.format(TEST_PUBLIC_URL_ROOT, checkout_page, sku)
    self.assertRedirects(response, expected_page, fetch_redirect_response=False)
