|
6 | 6 | from random import randint
|
7 | 7 |
|
8 | 8 | import mock
|
| 9 | +from edx_django_utils.cache import TieredCache |
9 | 10 | from mock import patch
|
10 | 11 | from pytest import mark
|
11 | 12 | from rest_framework import status
|
@@ -626,6 +627,31 @@ def test_xblocks_api_with_skill_validation_disabled(self):
|
626 | 627 | assert api_response.status_code == 200
|
627 | 628 | assert api_response.json() == []
|
628 | 629 |
|
| 630 | + def test_list_xblock_skills_cache_hit(self): |
| 631 | + cached_data = {'results': [{'id': str(self.xblock_skills[0].id)}]} |
| 632 | + with patch.object( |
| 633 | + TieredCache, |
| 634 | + 'get_cached_response', |
| 635 | + wraps=TieredCache.get_cached_response |
| 636 | + ) as mock_get_cached_response: |
| 637 | + mock_get_cached_response.return_value = mock.MagicMock(is_found=True, value=cached_data) |
| 638 | + response = self.client.get(self.view_url) |
| 639 | + self.assertEqual(response.status_code, status.HTTP_200_OK) |
| 640 | + self.assertEqual(response.data, cached_data) |
| 641 | + mock_get_cached_response.assert_called_once() |
| 642 | + |
| 643 | + def test_list_xblock_skills_caching(self): |
| 644 | + with patch.object(TieredCache, 'set_all_tiers') as mock_set_all_tiers, \ |
| 645 | + patch.object(TieredCache, 'get_cached_response', wraps=TieredCache.get_cached_response) \ |
| 646 | + as mock_get_cached_response: |
| 647 | + |
| 648 | + mock_get_cached_response.return_value = mock.MagicMock(is_found=False) |
| 649 | + response = self.client.get(self.view_url) |
| 650 | + |
| 651 | + self.assertEqual(response.status_code, status.HTTP_200_OK) |
| 652 | + mock_get_cached_response.assert_called_once() |
| 653 | + mock_set_all_tiers.assert_called_once() |
| 654 | + |
629 | 655 |
|
630 | 656 | @mark.django_db
|
631 | 657 | class TestJobPathAPIView(TestCase):
|
|
0 commit comments