def test_can_update_administrated_community_cover(self): """ should be able to update the cover of an administrated community and return 200 """ user = make_user() headers = make_authentication_headers_for_user(user) community = make_community(creator=user) community.cover = None community.save() new_cover = make_community_cover() data = { 'cover': new_cover } url = self._get_url(community_name=community.name) response = self.client.put(url, data, **headers, format='multipart') self.assertEqual(response.status_code, status.HTTP_200_OK) user.refresh_from_db() self.assertIsNotNone(community.cover)
def test_create_community_with_cover(self): """ should be able to create a community with a cover 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 = fake.word() community_users_adjective = fake.word() community_cover = make_community_cover() community_color = fake.hex_color() community_categories = [] for i in range(0, settings.COMMUNITY_CATEGORIES_MAX_AMOUNT): category = make_category() community_categories.append(category.name) data = { 'name': community_name, 'type': 'P', '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, 'cover': community_cover } url = self._get_url() response = self.client.put(url, data, **headers, format='multipart') self.assertEqual(response.status_code, status.HTTP_201_CREATED) community = Community.objects.get(name=community_name) self.assertTrue(hasattr(community, 'cover'))
def test_can_delete_administrated_community_cover(self): """ should be able to delete the cover of an administrated community and return 200 """ user = make_user() headers = make_authentication_headers_for_user(user) community = make_community(creator=user) community.cover.save('cover.jpg', File(make_community_cover())) url = self._get_url(community_name=community.name) response = self.client.delete(url, **headers, format='multipart') self.assertEqual(response.status_code, status.HTTP_200_OK) community.refresh_from_db() self.assertTrue(not community.cover)