예제 #1
0
    def test_can_successfully_rename_a_list(self):
        """Test that a list can be renamed."""
        company_list = CompanyListFactory(adviser=self.user, name='old name')
        url = _get_list_detail_url(company_list.pk)

        new_name = 'new name'
        response = self.api_client.patch(
            url,
            data={
                'name': new_name,
            },
        )

        assert response.status_code == status.HTTP_200_OK

        response_data = response.json()
        assert response_data == {
            'id': str(company_list.pk),
            'item_count': 0,
            'name': new_name,
            'created_on': format_date_or_datetime(company_list.created_on),
        }

        company_list.refresh_from_db()
        assert company_list.name == new_name
예제 #2
0
    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.')