def test_can_delete_a_list(self): """Test that a list (including its items) can be deleted.""" company_list = CompanyListFactory(adviser=self.user) list_item = CompanyListItemFactory(list=company_list) url = _get_list_detail_url(company_list.pk) response = self.api_client.delete(url) assert response.status_code == status.HTTP_204_NO_CONTENT assert response.content == b'' with pytest.raises(CompanyListItem.DoesNotExist): list_item.refresh_from_db() # The company should not be deleted assert Company.objects.filter(pk=list_item.company.pk).exists()
def test_other_lists_are_not_affected(self): """Test that other lists are not affected when a list is deleted.""" list_to_delete = CompanyListFactory(adviser=self.user) list_item = CompanyListItemFactory(list=list_to_delete) other_list = CompanyListFactory(adviser=self.user) other_list_item = CompanyListItemFactory(company=list_item.company) url = _get_list_detail_url(list_to_delete.pk) response = self.api_client.delete(url) assert response.status_code == status.HTTP_204_NO_CONTENT assert response.content == b'' try: other_list.refresh_from_db() other_list_item.refresh_from_db() except (CompanyList.DoesNotExist, CompanyListItem.DoesNotExist): pytest.fail('Other lists should not be affected.')