diff --git a/.docker/api/Dockerfile b/.docker/api/Dockerfile index a36e0a33aa12c309451a79d4bbfcf2e187123bd4..73aa51c5d74913b2efc76ccb8a71b7ad846655c3 100644 --- a/.docker/api/Dockerfile +++ b/.docker/api/Dockerfile @@ -1,4 +1,5 @@ FROM python:3.9.12 +ENV PYTHONUNBUFFERED 1 RUN apt-get -y update && apt-get -y upgrade && apt-get install -y ffmpeg diff --git a/openbook/settings.py b/openbook/settings.py index 0c7798fc32b43db348aff3b7ed3a419715bf17db..695ffbef39faac6e026a5dab4d6a5172b891fd6c 100644 --- a/openbook/settings.py +++ b/openbook/settings.py @@ -44,9 +44,17 @@ logging.config.dictConfig({ 'loggers': { # root logger '': { - 'level': 'INFO', + 'level': 'DEBUG', + 'handlers': ['console'], + }, + 'django.db': { + 'level': 'DEBUG', 'handlers': ['console'], }, + 'django.db.backends.schema': { + 'level': 'INFO', + 'handlers': ['console'], + } }, }) @@ -478,7 +486,7 @@ POST_MAX_LENGTH = int(os.environ.get('POST_MAX_LENGTH', '5000')) POST_MAX_HASHTAGS = int(os.environ.get('POST_MAX_HASHTAGS', '3')) POST_COMMENT_MAX_HASHTAGS = int(os.environ.get('POST_COMMENT_MAX_HASHTAGS', '3')) POST_COMMENT_MAX_LENGTH = int(os.environ.get('POST_MAX_LENGTH', '1500')) -POST_MEDIA_MAX_SIZE = int(os.environ.get('POST_MEDIA_MAX_SIZE', '10485760')) +POST_MEDIA_MAX_SIZE = int(os.environ.get('POST_MEDIA_MAX_SIZE', '30485760')) POST_LINK_MAX_DOMAIN_LENGTH = int(os.environ.get('POST_LINK_MAX_DOMAIN_LENGTH', '126')) POST_MEDIA_MAX_ITEMS = int(os.environ.get('POST_MEDIA_MAX_ITEMS', '1')) PASSWORD_MIN_LENGTH = 10 diff --git a/openbook_auth/models.py b/openbook_auth/models.py index 8fedf7b3943c7c678d21345d77caf5f27becc163..c0cf170e26b016c389fc2644df763bf05c263ec5 100644 --- a/openbook_auth/models.py +++ b/openbook_auth/models.py @@ -1,3 +1,4 @@ +import logging import secrets from datetime import datetime, timedelta import re @@ -3573,6 +3574,8 @@ class User(AbstractUser): def _make_get_post_with_id_query_for_user(self, user, post_id): posts_query = self._make_get_posts_query_for_user(user) posts_query.add(Q(id=post_id), Q.AND) + logger = logging.getLogger("openbook_auth/models") + logger.info('posts_query=%s', str(posts_query)) return posts_query def _make_get_posts_query_for_user(self, user, max_id=None): @@ -3585,17 +3588,17 @@ class User(AbstractUser): posts_circles_query = Q(circles__id=world_circle_id) - posts_circles_query.add(Q(circles__connections__target_user_id=self.pk, - circles__connections__target_connection__circles__isnull=False), Q.OR) + #posts_circles_query.add(Q(circles__connections__target_user_id=self.pk, + # circles__connections__target_connection__circles__isnull=False), Q.OR) posts_query.add(posts_circles_query, Q.AND) - posts_query.add(~Q(Q(creator__blocked_by_users__blocker_id=self.pk) | Q( - creator__user_blocks__blocked_user_id=self.pk)), Q.AND) + #posts_query.add(~Q(Q(creator__blocked_by_users__blocker_id=self.pk) | Q( + # creator__user_blocks__blocked_user_id=self.pk)), Q.AND) - if max_id: - posts_query.add(Q(id__lt=max_id), Q.AND) + #if max_id: + # posts_query.add(Q(id__lt=max_id), Q.AND) - posts_query.add(~Q(moderated_object__reports__reporter_id=self.pk), Q.AND) + #posts_query.add(~Q(moderated_object__reports__reporter_id=self.pk), Q.AND) return posts_query @@ -3636,11 +3639,20 @@ class User(AbstractUser): algorithm=settings.JWT_ALGORITHM).decode('utf-8') def _can_see_post(self, post): + logger = logging.getLogger("openbook_auth/models") + logger.info('post=%s', post.__dict__) post_query = self._make_get_post_with_id_query_for_user(post.creator, post_id=post.pk) Post = get_post_model() profile_posts = Post.objects.filter(post_query) + Circle = get_circle_model() + circles = Circle.objects.all() + for circle in circles: + logger.info(' circle=%s', circle.__dict__) + for circle_post in circle.posts.all(): + logger.info(' circle_post=%s', circle_post.__dict__) + return profile_posts.exists() def _can_see_community_post(self, community, post): diff --git a/openbook_posts/tests/views/test_post_media.py b/openbook_posts/tests/views/test_post_media.py index 25dd7524a72f9a7ce689958d2c14d81514e73e99..df16a519cd38e06f46dc4d106ad0953474f6c85a 100644 --- a/openbook_posts/tests/views/test_post_media.py +++ b/openbook_posts/tests/views/test_post_media.py @@ -1,6 +1,7 @@ # Create your tests here. import json import tempfile +import time from PIL import Image from django.conf import settings @@ -224,8 +225,10 @@ class PostMediaAPITests(OpenbookAPITestCase): user = make_user() headers = make_authentication_headers_for_user(user=user) + # contains "medium"-sized images (~20 MB) so make sure the API accepts this size for test_image in get_test_images(): with open(test_image['path'], 'rb') as file: + logger.info('test_image=%s', test_image['path']) post = user.create_public_post(is_draft=True) data = { @@ -236,7 +239,7 @@ class PostMediaAPITests(OpenbookAPITestCase): response = self.client.put(url, data, **headers, format='multipart') - self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.status_code, status.HTTP_200_OK, 'response.content='+str(response.content)) post.refresh_from_db() @@ -376,6 +379,7 @@ class PostMediaAPITests(OpenbookAPITestCase): test_image = get_test_image() with open(test_image['path'], 'rb') as file: + logger.info('test_image=%s', test_image['path']) file = File(file) post = foreign_user.create_public_post(image=file) @@ -385,7 +389,7 @@ class PostMediaAPITests(OpenbookAPITestCase): response = self.client.get(url, **headers, format='multipart') - self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.status_code, status.HTTP_200_OK, 'response.content='+str(response.content)) response_media = json.loads(response.content) @@ -395,6 +399,23 @@ class PostMediaAPITests(OpenbookAPITestCase): self._compare_response_media_with_post_media(post_media=post_media, response_media=response_media) + # adopted from https://stackoverflow.com/a/2785908/1242529 + @staticmethod + def wait_until(some_predicate, timeout_seconds, period_seconds=0.25, *args, **kwargs): + must_end = time.time() + timeout_seconds + while time.time() < must_end: + if some_predicate(*args, **kwargs): + return True + time.sleep(period_seconds) + return False + + def await_published(self, post): + def is_post_published(): + logger.info('checking publishing status') + post.refresh_from_db() + return post.status == Post.STATUS_PUBLISHED + return self.wait_until(is_post_published, 5) + def test_can_retrieve_foreign_user_post_media_video(self): """ should be able to retrieve an foreign_user post media video @@ -407,8 +428,10 @@ class PostMediaAPITests(OpenbookAPITestCase): test_video = get_test_video() with open(test_video['path'], 'rb') as file: + logger.info('test_image=%s', test_video['path']) file = File(file) post = foreign_user.create_public_post(video=file) + self.await_published(post) get_worker('high', worker_class=SimpleWorker).work(burst=True) @@ -416,7 +439,7 @@ class PostMediaAPITests(OpenbookAPITestCase): response = self.client.get(url, **headers, format='multipart') - self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.status_code, status.HTTP_200_OK, 'response.content='+str(response.content)) response_media = json.loads(response.content) @@ -440,6 +463,7 @@ class PostMediaAPITests(OpenbookAPITestCase): test_image = get_test_image() with open(test_image['path'], 'rb') as file: + logger.info('test_image=%s', test_image['path']) file = File(file) post = following_user.create_public_post(image=file) @@ -449,7 +473,7 @@ class PostMediaAPITests(OpenbookAPITestCase): response = self.client.get(url, **headers, format='multipart') - self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.status_code, status.HTTP_200_OK, 'response.content='+str(response.content)) response_media = json.loads(response.content) @@ -473,6 +497,7 @@ class PostMediaAPITests(OpenbookAPITestCase): test_video = get_test_video() with open(test_video['path'], 'rb') as file: + logger.info('test_image=%s', test_video['path']) file = File(file) post = following_user.create_public_post(video=file) @@ -482,7 +507,7 @@ class PostMediaAPITests(OpenbookAPITestCase): response = self.client.get(url, **headers, format='multipart') - self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.status_code, status.HTTP_200_OK, 'response.content='+str(response.content)) response_media = json.loads(response.content) @@ -506,6 +531,7 @@ class PostMediaAPITests(OpenbookAPITestCase): test_image = get_test_image() with open(test_image['path'], 'rb') as file: + logger.info('test_image=%s', test_image['path']) file = File(file) post = follower_user.create_public_post(image=file) @@ -515,7 +541,7 @@ class PostMediaAPITests(OpenbookAPITestCase): response = self.client.get(url, **headers, format='multipart') - self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.status_code, status.HTTP_200_OK, 'response.content='+str(response.content)) response_media = json.loads(response.content) @@ -539,6 +565,7 @@ class PostMediaAPITests(OpenbookAPITestCase): test_video = get_test_video() with open(test_video['path'], 'rb') as file: + logger.info('test_image=%s', test_video['path']) file = File(file) post = follower_user.create_public_post(video=file) @@ -548,7 +575,7 @@ class PostMediaAPITests(OpenbookAPITestCase): response = self.client.get(url, **headers, format='multipart') - self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.status_code, status.HTTP_200_OK, 'response.content='+str(response.content)) response_media = json.loads(response.content) @@ -574,6 +601,7 @@ class PostMediaAPITests(OpenbookAPITestCase): test_image = get_test_image() with open(test_image['path'], 'rb') as file: + logger.info('test_image=%s', test_image['path']) file = File(file) post = connected_user.create_encircled_post(image=file, circles_ids=[circle.pk]) @@ -581,9 +609,10 @@ class PostMediaAPITests(OpenbookAPITestCase): url = self._get_url(post=post) + time.sleep(5) response = self.client.get(url, **headers, format='multipart') - self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.status_code, status.HTTP_200_OK, 'response.content='+str(response.content)) response_media = json.loads(response.content) @@ -610,6 +639,7 @@ class PostMediaAPITests(OpenbookAPITestCase): test_video = get_test_video() with open(test_video['path'], 'rb') as file: + logger.info('test_image=%s', test_video['path']) file = File(file) post = connected_user.create_encircled_post(video=file, circles_ids=[circle.pk]) @@ -619,7 +649,7 @@ class PostMediaAPITests(OpenbookAPITestCase): response = self.client.get(url, **headers, format='multipart') - self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.status_code, status.HTTP_200_OK, 'response.content='+str(response.content)) response_media = json.loads(response.content) @@ -696,6 +726,7 @@ class PostMediaAPITests(OpenbookAPITestCase): test_image = get_test_image() with open(test_image['path'], 'rb') as file: + logger.info('test_image=%s', test_image['path']) file = File(file) post = community_member.create_community_post(image=file, community_name=public_community.name) @@ -705,7 +736,7 @@ class PostMediaAPITests(OpenbookAPITestCase): response = self.client.get(url, **headers, format='multipart') - self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.status_code, status.HTTP_200_OK, 'response.content='+str(response.content)) response_media = json.loads(response.content) @@ -730,6 +761,7 @@ class PostMediaAPITests(OpenbookAPITestCase): test_video = get_test_video() with open(test_video['path'], 'rb') as file: + logger.info('test_image=%s', test_video['path']) file = File(file) post = community_member.create_community_post(video=file, community_name=public_community.name) @@ -739,7 +771,7 @@ class PostMediaAPITests(OpenbookAPITestCase): response = self.client.get(url, **headers, format='multipart') - self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.status_code, status.HTTP_200_OK, 'response.content='+str(response.content)) response_media = json.loads(response.content) @@ -766,6 +798,7 @@ class PostMediaAPITests(OpenbookAPITestCase): test_image = get_test_image() with open(test_image['path'], 'rb') as file: + logger.info('test_image=%s', test_image['path']) file = File(file) post = community_creator.create_community_post(image=file, community_name=private_community.name) @@ -775,7 +808,7 @@ class PostMediaAPITests(OpenbookAPITestCase): response = self.client.get(url, **headers, format='multipart') - self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.status_code, status.HTTP_200_OK, 'response.content='+str(response.content)) response_media = json.loads(response.content) @@ -802,6 +835,7 @@ class PostMediaAPITests(OpenbookAPITestCase): test_video = get_test_video() with open(test_video['path'], 'rb') as file: + logger.info('test_image=%s', test_video['path']) file = File(file) post = community_creator.create_community_post(video=file, community_name=private_community.name) @@ -811,7 +845,7 @@ class PostMediaAPITests(OpenbookAPITestCase): response = self.client.get(url, **headers, format='multipart') - self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.status_code, status.HTTP_200_OK, 'response.content='+str(response.content)) response_media = json.loads(response.content)