Esempio n. 1
0
 def setUpClass(cls):
     super().setUpClass()
     cls.city = CityFactory(name=CITY_NAME)
     cls.city_new = CityFactory(name=CITY_NEW_NAME)
     cls.mentor = UserFactory(
         profile__role=Profile.Role.MENTOR,
         profile__city=cls.city,
         password=PASSWORD,
     )
     cls.moderator_reg = UserFactory(
         profile__role=Profile.Role.MODERATOR_REG,
         profile__city=cls.city,
         password=PASSWORD,
     )
     cls.moderator_gen = UserFactory(
         profile__role=Profile.Role.MODERATOR_GEN,
         profile__city=cls.city,
         password=PASSWORD,
     )
     cls.admin = UserFactory(
         profile__role=Profile.Role.ADMIN,
         profile__city=cls.city,
         password=PASSWORD,
     )
     cls.staff_users = [
         cls.moderator_reg,
         cls.moderator_gen,
         cls.admin,
     ]
     cls.users = cls.staff_users + [cls.mentor]
     cls.unauthorized_client = APIClient()
Esempio n. 2
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' должно возвращаться"
                 "последнее."),
        )
Esempio n. 3
0
    def setUpClass(cls) -> None:
        super().setUpClass()

        cls.city = CityFactory(name="Воркута")
        cls.mentor = UserFactory(
            profile__role="mentor",
            profile__city=cls.city,
        )
        cls.moderator_reg = UserFactory(
            profile__role="moderator_reg",
            profile__city=cls.city,
        )
        cls.moderator_gen = UserFactory(
            profile__role="moderator_gen",
            profile__city=cls.city,
        )
        cls.admin = UserFactory(
            profile__role="admin",
            profile__city=cls.city,
        )
        cls.users = [
            cls.mentor,
            cls.moderator_reg,
            cls.moderator_gen,
            cls.admin,
        ]

        cls.unauthorized_client = APIClient()
Esempio n. 4
0
    def setUpClass(cls):
        super().setUpClass()
        cls.city = CityFactory.create(name="Ронг-Ченг")
        cls.mentor = UserFactory(
            profile__role=Profile.Role.MENTOR,
            profile__city=cls.city,
        )
        cls.moderator_reg = UserFactory(
            profile__role=Profile.Role.MODERATOR_REG,
            profile__city=cls.city,
        )
        cls.moderator_gen = UserFactory(
            profile__role=Profile.Role.MODERATOR_GEN,
            profile__city=cls.city,
        )
        cls.admin = UserFactory(
            profile__role=Profile.Role.ADMIN,
            profile__city=cls.city,
        )
        cls.users = [
            cls.mentor,
            cls.moderator_reg,
            cls.moderator_gen,
            cls.admin,
        ]
        cls.unauthorized_client = APIClient()

        cls.path_questions = reverse("questions")
        cls.path_questions_tags = reverse("questions-tags")
Esempio n. 5
0
    def setUpClass(cls):
        super().setUpClass()
        cls.city = CityFactory.create(name="SomeCity")
        cls.mentor = UserFactory(
            profile__role=Profile.Role.MENTOR,
            profile__city=cls.city,
        )
        cls.moderator_reg = UserFactory(
            profile__role=Profile.Role.MODERATOR_REG,
            profile__city=cls.city,
        )
        cls.moderator_gen = UserFactory(
            profile__role=Profile.Role.MODERATOR_GEN,
            profile__city=cls.city,
        )
        cls.admin = UserFactory(
            profile__role=Profile.Role.ADMIN,
            profile__city=cls.city,
        )
        cls.users = [
            cls.mentor,
            cls.moderator_reg,
            cls.moderator_gen,
            cls.admin,
        ]
        cls.unauthorized_client = APIClient()

        cls.path_main = reverse("main_page")
Esempio n. 6
0
    def setUpClass(cls) -> None:
        super().setUpClass()

        cls.city = CityFactory()
        cls.tomorrow = timezone.now() + timedelta(days=1)
        cls.future = timezone.now() + timedelta(days=60)
        cls.past = timezone.now() - timedelta(days=10)
Esempio n. 7
0
 def test_access_to_delete_city_on_admin_site(self):
     """Test access to delete city on admin site"""
     print(self.userAdminSite.urls)
     for user, code in self.user_and_code.items():
         city_new = CityFactory(name=CITY_NEW_NAME)
         client = self.return_authorized_user_client(user=user)
         response = client.post(FULL_DELETE_URL.format(id=city_new.id))
         self.assertEqual(response.status_code, code)
Esempio n. 8
0
    def setUpClass(cls) -> None:
        super().setUpClass()
        cls.path_rights = reverse("rights-list")
        cls.path_righttags = reverse("right-tags")
        cls.tag = RightTagFactory(name="?Петровна?")
        cls.right = RightFactory(tags__num=2)

        cls.city = CityFactory(name="Билибино")
        cls.mentor = UserFactory()

        cls.unauthorized_client = APIClient()
Esempio n. 9
0
    def test_unique_place_for_city_constraint(self):
        city = CityFactory()
        address = "Абонентский ящик АЯ 23"
        title = "Место 1"

        PlaceFactory(city=city, address=address, title=title)

        with self.assertRaises(
                IntegrityError,
                msg=("Убедитесь, что нельзя создать место с одним названием, "
                     "адресом и городом."),
        ):
            PlaceFactory(city=city, address=address, title=title)
Esempio n. 10
0
 def setUpClass(cls):
     super().setUpClass()
     cls.city = CityFactory(name=CITY_NAME)
     cls.city_new = CityFactory(name=CITY_NEW_NAME)
     cls.mentor = UserFactory(
         profile__role=Profile.Role.MENTOR,
         profile__city=cls.city,
         password=PASSWORD,
     )
     cls.moderator_reg = UserFactory(
         profile__role=Profile.Role.MODERATOR_REG,
         profile__city=cls.city,
         password=PASSWORD,
     )
     cls.moderator_gen = UserFactory(
         profile__role=Profile.Role.MODERATOR_GEN,
         profile__city=cls.city,
         password=PASSWORD,
     )
     cls.admin = UserFactory(
         profile__role=Profile.Role.ADMIN,
         profile__city=cls.city,
         password=PASSWORD,
     )
     cls.staff_users = [
         cls.moderator_reg,
         cls.moderator_gen,
         cls.admin,
     ]
     cls.unauthorized_client = Client()
     cls.userAdminSite = UserAdmin(model=User, admin_site=AdminSite())
     cls.user_and_code = {
         cls.mentor: status.HTTP_302_FOUND,
         cls.moderator_reg: status.HTTP_403_FORBIDDEN,
         cls.moderator_gen: status.HTTP_403_FORBIDDEN,
         cls.admin: status.HTTP_200_OK,
     }
Esempio n. 11
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)
Esempio n. 12
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)
Esempio n. 13
0
    def test_places_main_returns_empty_list_if_no_places(self):
        """If there is no places in city should return []."""
        city = CityFactory()
        mentor = UserFactory(
            profile__role=Profile.Role.MENTOR,
            profile__city=city,
        )
        client = APIClient()
        client.force_authenticate(user=mentor)

        response = client.get(PLACES_MAIN)

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(
            response.data,
            [],
            msg="Если нет событий в городе возвращать пустой список.",
        )
Esempio n. 14
0
 def setUpClass(cls):
     super().setUpClass()
     base.MEDIA_ROOT = tempfile.mkdtemp(dir=base.ROOT_DIR)
     cls.city = CityFactory(name=CITY_NAME)
     cls.user = UserFactory(
         profile__role=Profile.Role.MENTOR,
         profile__city=cls.city,
         password=PASSWORD,
     )
     cls.user2 = UserFactory(
         profile__role=Profile.Role.MENTOR,
         profile__city=cls.city,
         password=PASSWORD,
     )
     cls.UPLOADED = SimpleUploadedFile(
         name="small.gif", content=SMALL_GIF, content_type="image/gif"
     )
     cls.unauthorized_client = APIClient()
Esempio n. 15
0
    def setUpClass(cls) -> None:
        super().setUpClass()

        cls.city = CityFactory(name="Ронг-Ченг")
        cls.mentor = UserFactory(
            profile__role=Profile.Role.MENTOR,
            profile__city=cls.city,
        )
        cls.moderator_reg = UserFactory(
            profile__role=Profile.Role.MODERATOR_REG,
            profile__city=cls.city,
        )
        cls.moderator_gen = UserFactory(
            profile__role=Profile.Role.MODERATOR_GEN,
            profile__city=cls.city,
        )
        cls.admin = UserFactory(
            profile__role=Profile.Role.ADMIN,
            profile__city=cls.city,
        )
        cls.unauthorized_client = APIClient()

        cls.authorized_users = [
            cls.mentor,
            cls.moderator_reg,
            cls.moderator_gen,
            cls.admin,
        ]

        cls.all_users = [
            cls.mentor,
            cls.moderator_reg,
            cls.moderator_gen,
            cls.admin,
            cls.unauthorized_client,
        ]

        cls.valid_question = "Very exciting question about the project."
        cls.empty_question = ""
        cls.short_question = "Short question."

        cls.path_questions = reverse("questions")
Esempio n. 16
0
    def test_mentor_cant_book_event_in_other_city(self):
        user = ViewAfishaTests.mentor
        other_city = CityFactory()
        event = EventFactory(
            city=other_city,
        )

        client = self.return_authorized_user_client(user)
        data = {"event": event.id}
        response = client.post(path=EVENTS_PATS_URL, data=data, format="json")

        self.assertContains(
            response,
            status_code=400,
            text="Извините, но мероприятие не в Вашем городе.",
            msg_prefix=(
                f"Проверьте, что пользователь c ролью "
                f"'{user.profile.role}'не может зарегистрироваться "
                f"на мероприятие в другом городе."
            ),
        )
Esempio n. 17
0
    def test_mentor_sees_events_in_the_his_own_city_only(self):
        """Looks for amount records in responses for different users.

        user = don't have any records in his city. We expect zero records.
        users_other_city = has to have 10 records.

        The test assumes that page size is more than 10 records.
        """

        other_city = CityFactory()
        user = ViewAfishaTests.mentor
        user_other_city = UserFactory(profile__city=other_city)
        EventFactory.create_batch(10, city=other_city)

        client_user = self.return_authorized_user_client(user)
        response_data = client_user.get(EVENTS_URL, format="json").data
        count = response_data.get("count")

        self.assertEqual(
            count,
            0,
            msg=(
                "Убедитесь, что пользователю не возвращаются мероприятия "
                "в других городах."
            ),
        )

        client_other_user = self.return_authorized_user_client(user_other_city)
        response_data = client_other_user.get(EVENTS_URL, format="json").data
        count = response_data.get("count")

        self.assertEqual(
            count,
            10,
            msg=(
                "Убедитесь, что пользователю показывается мероприятие в его "
                "городе."
            ),
        )
Esempio n. 18
0
    def setUpClass(cls):
        super().setUpClass()
        cls.city = CityFactory(name="Воркута")
        cls.mentor = UserFactory(
            profile__role=Profile.Role.MENTOR,
            profile__city=cls.city,
        )
        cls.moderator_reg = UserFactory(
            profile__role=Profile.Role.MODERATOR_REG,
            profile__city=cls.city,
        )
        cls.moderator_gen = UserFactory(
            profile__role=Profile.Role.MODERATOR_GEN,
            profile__city=cls.city,
        )
        cls.admin = UserFactory(
            profile__role=Profile.Role.ADMIN,
            profile__city=cls.city,
        )
        cls.users = [
            cls.mentor,
            cls.moderator_reg,
            cls.moderator_gen,
            cls.admin,
        ]
        cls.event = EventFactory(city=cls.mentor.profile.city, )
        cls.booking = EventParticipant.objects.create(
            user=cls.mentor,
            event=cls.event,
        )

        cls.unauthorized_client = APIClient()
        cls.path_events_participants = reverse("event-participants-list")
        cls.path_individual_booking = reverse(
            "event-participants-detail",
            args=[cls.mentor.profile.id],
        )
        cls.path_events = reverse("events")
Esempio n. 19
0
    def test_places_main_returns_last_chosen_place_in_city(self):
        """Should return last place with 'chosen=True' in the city."""
        other_city = CityFactory()
        place_in_city = PlaceFactory(
            city=ViewPlacesTests.city,
            published=True,
            chosen=True,
        )
        PlaceFactory(  # place in other city
            city=other_city,
            published=True,
            chosen=True,
        )
        client = ViewPlacesTests.authorized_client

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

        self.assertEqual(
            place_id,
            place_in_city.id,
            msg="В main должен возвращаться последний объект в городе.",
        )
Esempio n. 20
0
    def test_mentor_can_list_available_events_in_his_city(self):
        """Looks for amount recodes in response.

        The test assumes that pages size is less or equal 10.
        """

        city = CityFactory(name="Вермонт")
        other_city = ViewAfishaTests.city
        user = UserFactory(profile__city=city)
        client = self.return_authorized_user_client(user)
        EventFactory.create_batch(10, city=city)
        EventFactory.create_batch(100, city=other_city)

        response_data = client.get(path=EVENTS_URL).data
        results = response_data.get("results")

        self.assertEqual(
            len(results),
            10,
            msg=(
                "Проверьте что пользователь видит все доступные события "
                "в городе"
            ),
        )
Esempio n. 21
0
 def setUpClass(cls):
     super().setUpClass()
     cls.city = CityFactory(name=CITY_NAME)
     cls.city_2 = CityFactory(name=CITY_2_NAME)
Esempio n. 22
0
 def create_city(self, arg):
     CityFactory.create_batch(arg)
Esempio n. 23
0
    def handle(self, *args, **options):  # noqa

        optional_arguments = 0

        for item in list(OPTIONS_AND_FINCTIONS):
            if options[item]:
                optional_arguments += 1
                with factory.Faker.override_default_locale("ru_RU"):
                    OPTIONS_AND_FINCTIONS[item](options[item][0])
                    self.stdout.write(
                        self.style.SUCCESS(
                            f"{options[item][0]} {item} created successfully"
                        )
                    )

        if optional_arguments == 0:
            try:
                if City.objects.count() > len(CITIES):
                    raise MyException()

                with factory.Faker.override_default_locale("ru_RU"):
                    for city_name in CITIES:
                        CityFactory(name=city_name)

                    CityFactory.create_batch(10)

                    EventFactory.create_batch(200)

                    CuratorFactory.create_batch(15)

                    RightTagFactory.create_batch(10)

                    for _ in range(70):
                        num_tags = random.randint(1, 5)
                        RightFactory(tags__num=num_tags)

                    for _ in range(70):
                        num_events = random.randint(0, 5)
                        UserFactory(num_events=num_events)

                    QuestionTagFactory.create_batch(15)

                    for _ in range(70):
                        num_tags = random.randint(1, 5)
                        QuestionFactory.create(tags=num_tags)

                    QuestionFactory.create_batch(5)

                    QuestionFactoryWithoutAnswer.create_batch(5)

                    PlacesTagFactory.create_batch(15)

                    for _ in range(70):
                        num_tags = random.randint(1, 5)
                        PlaceFactory.create(tags__num=num_tags)

                    GuideFactory.create_batch(70)

                    MovieTagFactory.create_batch(10)

                    for link in link_movie_list:
                        num_tags = random.randint(1, 5)
                        MovieFactory.create(link=link, tags__num=num_tags)

                    MeetingFactory.create_batch(50)

                    ArticleFactory.create_batch(70)

                    BookTagFactory.create(
                        name="Художественные",
                        slug="hudozhestvennye",
                        color="#C8D1FF",
                    )
                    BookTagFactory.create(
                        name="Научные", slug="nauchnye", color="#FC8585"
                    )
                    BookFactory.create_batch(50)

                    VideoTagFactory.create_batch(15)

                    for link in link_video_list:
                        num_tags = random.randint(1, 5)
                        VideoFactory.create(link=link, tags__num=num_tags)

                    StoryFactory.create_batch(30)

                    StoryImageFactory.create_batch(100)

                    MainFactory.create()

                self.stdout.write(
                    self.style.SUCCESS("The database is filled with test data")
                )
            except MyException:
                self.stdout.write(
                    self.style.ERROR(
                        "The database is already filled with standard test "
                        "data. To top up individual tables, use the arguments."
                    )
                )
Esempio n. 24
0
 def setUpClass(cls) -> None:
     super().setUpClass()
     cls.city = CityFactory(name="Учтюпинск")
     cls.tag = PlacesTagFactory(name="test")
     cls.place = PlaceFactory(tags=[cls.tag])