|
15 | 15 |
|
16 | 16 | from rest_framework_simplejwt.settings import api_settings |
17 | 17 |
|
18 | | -from tigacrafting.models import ExpertReportAnnotation, IdentificationTask, PhotoPrediction |
| 18 | +from tigacrafting.models import ExpertReportAnnotation, IdentificationTask, PhotoPrediction, FavoritedReports |
19 | 19 | from tigaserver_app.models import TigaUser, Report, Device, MobileApp |
20 | 20 |
|
21 | 21 | from api.tests.clients import AppAPIClient |
@@ -796,6 +796,53 @@ def test_is_flagged_sets_status_to_flagged(self, api_client, endpoint, common_po |
796 | 796 | annotation = ExpertReportAnnotation.objects.get(pk=response.data['id']) |
797 | 797 | assert annotation.status == expected_result |
798 | 798 |
|
| 799 | + @pytest.mark.parametrize( |
| 800 | + "is_favourite", |
| 801 | + [True, False] |
| 802 | + ) |
| 803 | + def test_is_favourite_creates_FavoritedReports(self, api_client, endpoint, common_post_data, with_add_permission, is_favourite): |
| 804 | + post_data = common_post_data |
| 805 | + post_data['is_favourite'] = is_favourite |
| 806 | + |
| 807 | + response = api_client.post( |
| 808 | + endpoint, |
| 809 | + data=post_data, |
| 810 | + format='json' |
| 811 | + ) |
| 812 | + assert response.status_code == status.HTTP_201_CREATED |
| 813 | + assert response.data['is_favourite'] == is_favourite |
| 814 | + |
| 815 | + annotation = ExpertReportAnnotation.objects.get(pk=response.data['id']) |
| 816 | + assert annotation.is_favourite == is_favourite |
| 817 | + assert FavoritedReports.objects.filter( |
| 818 | + report=annotation.identification_task.report, |
| 819 | + user=annotation.user |
| 820 | + ).exists() == is_favourite |
| 821 | + |
| 822 | + def test_is_favourite_does_nothing_if_already_exists_FavoritedReports(self, api_client, user, identification_task, endpoint, common_post_data, with_add_permission): |
| 823 | + FavoritedReports.objects.create( |
| 824 | + report=identification_task.report, |
| 825 | + user=user |
| 826 | + ) |
| 827 | + |
| 828 | + post_data = common_post_data |
| 829 | + post_data['is_favourite'] = True |
| 830 | + |
| 831 | + response = api_client.post( |
| 832 | + endpoint, |
| 833 | + data=post_data, |
| 834 | + format='json' |
| 835 | + ) |
| 836 | + assert response.status_code == status.HTTP_201_CREATED |
| 837 | + assert response.data['is_favourite'] is True |
| 838 | + |
| 839 | + annotation = ExpertReportAnnotation.objects.get(pk=response.data['id']) |
| 840 | + assert annotation.is_favourite |
| 841 | + assert FavoritedReports.objects.filter( |
| 842 | + report=annotation.identification_task.report, |
| 843 | + user=annotation.user |
| 844 | + ).exists() |
| 845 | + |
799 | 846 | @pytest.mark.parametrize( |
800 | 847 | "pre_assign", |
801 | 848 | [True, False] |
|
0 commit comments