Exemplo n.º 1
0
    def test_create_public_community(self):
        """
        should be able to create a public community and return 201
        """
        user = make_user()
        headers = make_authentication_headers_for_user(user)

        community_name = fake.user_name()
        community_title = fake.name_male()
        community_description = fake.text(
            max_nb_chars=settings.COMMUNITY_DESCRIPTION_MAX_LENGTH)
        community_rules = fake.text(
            max_nb_chars=settings.COMMUNITY_RULES_MAX_LENGTH)
        community_user_adjective = make_community_user_adjective()
        community_users_adjective = make_community_users_adjective()
        community_color = fake.hex_color()
        community_categories = []
        community_type = 'P'

        for i in range(0, settings.COMMUNITY_CATEGORIES_MAX_AMOUNT):
            category = make_category()
            community_categories.append(category.name)

        data = {
            'name': community_name,
            'type': community_type,
            'title': community_title,
            'description': community_description,
            'rules': community_rules,
            'user_adjective': community_user_adjective,
            'users_adjective': community_users_adjective,
            'color': community_color,
            'categories': community_categories
        }

        url = self._get_url()

        response = self.client.put(url, data, **headers, format='multipart')

        self.assertEqual(response.status_code, status.HTTP_201_CREATED)

        self.assertTrue(
            Community.objects.filter(name=community_name,
                                     title=community_title,
                                     description=community_description,
                                     rules=community_rules,
                                     user_adjective=community_user_adjective,
                                     users_adjective=community_users_adjective,
                                     color=community_color,
                                     type=community_type).count() == 1)
Exemplo n.º 2
0
    def test_can_update_administrated_community_users_adjective(self):
        """
        should be able to update an administrated community users_adjective
        """
        user = make_user()
        headers = make_authentication_headers_for_user(user)

        community = make_community(creator=user)
        new_community_users_adjective = make_community_users_adjective()

        data = {'users_adjective': new_community_users_adjective}

        url = self._get_url(community_name=community.name)

        response = self.client.patch(url, data, **headers)

        self.assertEqual(response.status_code, status.HTTP_200_OK)

        community.refresh_from_db()

        self.assertEqual(community.users_adjective,
                         new_community_users_adjective)