Example #1
0
    def test_places_main_returns_last_place_if_there_is_no_chosen(self):
        """
        If there is no 'chosen=True' places in the city it should return
        last 'place' in the city.
        """
        city = CityFactory()
        mentor = UserFactory(
            profile__role=Profile.Role.MENTOR,
            profile__city=city,
        )
        PlaceFactory.create_batch(  # previous not chosen places
            10,
            city=city,
            published=True,
            chosen=False,
        )
        last_not_chosen_place = PlaceFactory(
            city=city,
            published=True,
            chosen=False,
        )
        client = APIClient()
        client.force_authenticate(user=mentor)

        response_data = client.get(PLACES_MAIN).data
        place_id = response_data.get("id")

        self.assertEqual(
            place_id,
            last_not_chosen_place.id,
            msg=("Если нет места с 'chosen=True' должно возвращаться"
                 "последнее."),
        )
Example #2
0
    def setUpClass(cls) -> None:
        super().setUpClass()

        cls.city = CityFactory(name="Тула")
        cls.mentor = UserFactory(
            profile__role=Profile.Role.MENTOR,
            profile__city=cls.city,
        )
        PlaceFactory.create_batch(
            10,
            city=cls.city,
            published=True,
        )
        cls.unauthorized_client = APIClient()

        cls.authorized_client = APIClient()
        cls.authorized_client.force_authenticate(user=cls.mentor)
Example #3
0
    def test_authorized_user_chosen_is_false_filter(self):
        """Result should have only places with 'chosen=False' field."""
        PlaceFactory.create_batch(
            10,
            city=FilterTests.mentor.profile.city,
            published=True,
            chosen=False,
        )
        client = FilterTests.authorized_client
        query_param = {"chosen": False}

        response_data = client.get(PLACES_URL, query_param).data
        count = response_data.get("count")

        self.assertEqual(
            count,
            10,
            msg=("Фильтр 'chosen=False' должен отдавать только места с этим"
                 "флагом."),
        )
Example #4
0
    def setUpClass(cls) -> None:
        super().setUpClass()

        cls.city = CityFactory()
        cls.other_city = CityFactory()
        cls.mentor = UserFactory(profile__city=cls.city)

        cls.tag_1 = PlacesTagFactory(name="tag1")
        cls.tag_2 = PlacesTagFactory(name="tag2")

        PlaceFactory.create_batch(
            10,
            tags=[cls.tag_1],
            city=cls.city,
            published=True,
            chosen=True,
        )
        PlaceFactory.create_batch(
            20,
            tags=[cls.tag_2],
            city=cls.other_city,
            published=True,
            chosen=True,
        )
        PlaceFactory.create_batch(
            40,
            tags=[cls.tag_2],
            city=cls.city,
            published=True,
            chosen=True,
        )

        cls.unauthorized_client = APIClient()

        cls.authorized_client = APIClient()
        cls.authorized_client.force_authenticate(user=cls.mentor)