def test_can_update_administrated_community_avatar(self): """ should be able to update the avatar of an administrated community and return 200 """ user = make_user() headers = make_authentication_headers_for_user(user) community = make_community(creator=user) community.avatar = None community.save() new_avatar = make_community_avatar() data = { 'avatar': new_avatar } 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.avatar)
def test_create_community_with_avatar(self): """ should be able to create a community with an avatar 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_avatar = make_community_avatar() 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, 'avatar': community_avatar } 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, 'avatar'))
def test_can_delete_administrated_community_avatar(self): """ should be able to delete the avatar of an administrated community and return 200 """ user = make_user() headers = make_authentication_headers_for_user(user) community = make_community(creator=user) community.avatar.save('avatar.jpg', File(make_community_avatar())) 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.avatar)