'Verify that when enabled, the cache is used.'

@waffle.testutils.override_switch('populate-multitenant-programs', True)
def test_cache_utilization(self):

    catalog_integration = self.create_catalog_integration(cache_ttl=5)
    api = create_catalog_api_client(self.user)
    expected_collection = ['some', 'test', 'data']
    data = {'next': None, 'results': expected_collection}
    self._mock_catalog_api([httpretty.Response(body=json.dumps(data), content_type='application/json')])
    resource_id = 1
    url = '{api_root}/programs/{resource_id}/'.format(api_root=CatalogIntegration.current().get_internal_api_url().strip('/'), resource_id=resource_id)
    expected_resource = {'key': 'value'}
    self._mock_catalog_api([httpretty.Response(body=json.dumps(expected_resource), content_type='application/json')], url=url)
    cache_key = CatalogIntegration.current().CACHE_KEY
    get_edx_api_data(catalog_integration, 'programs', api=api, cache_key=cache_key)
    get_edx_api_data(catalog_integration, 'programs', api=api, resource_id=resource_id, cache_key=cache_key)
    actual_collection = get_edx_api_data(catalog_integration, 'programs', api=api, cache_key=cache_key)
    self.assertEqual(actual_collection, expected_collection)
    actual_resource = get_edx_api_data(catalog_integration, 'programs', api=api, resource_id=resource_id, cache_key=cache_key)
    self.assertEqual(actual_resource, expected_resource)
    self._assert_num_requests(2)
