Example #1
0
 def test_webfinger_responds_200_on_known_user(self, client):
     UserFactory(username="******")
     Profile.objects.filter(user__username="******").update(
         rsa_public_key="fooobar")
     response = client.get("{url}?q=foobar%40socialhome.local".format(
         url=reverse("federate:webfinger")))
     assert response.status_code == 200
     response = client.get(
         "{url}?q=acct%3Afoobar%40socialhome.local".format(
             url=reverse("federate:webfinger")))
     assert response.status_code == 200
Example #2
0
 def setUpTestData(cls):
     super().setUpTestData()
     author = UserFactory()
     Profile.objects.filter(id=author.profile.id).update(
         rsa_private_key=get_dummy_private_key().exportKey().decode(
             "utf-8"))
     cls.limited_content = ContentFactory(visibility=Visibility.LIMITED,
                                          author=author.profile)
     cls.public_content = ContentFactory(visibility=Visibility.PUBLIC,
                                         author=author.profile)
     cls.remote_content = ContentFactory(visibility=Visibility.PUBLIC)
Example #3
0
 def test_local_content_with_parent_sent_as_reply(self, mock_send):
     user = UserFactory()
     parent = ContentFactory(author=user.profile)
     mock_send.reset_mock()
     content = ContentFactory(author=user.profile, parent=parent)
     self.assertTrue(content.local)
     call_args = [
         call(send_reply_notifications, content.id),
         call(send_reply, content.id),
     ]
     self.assertEqual(mock_send.call_args_list, call_args)
Example #4
0
 def test_signal_creates_a_profile(self, settings):
     settings.SOCIALHOME_GENERATE_USER_RSA_KEYS_ON_SAVE = True
     user = UserFactory()
     profile = user.profile
     assert profile.user == user
     assert profile.name == user.name
     assert profile.email == user.email
     assert profile.rsa_private_key
     assert profile.rsa_public_key
     assert profile.handle == "%s@%s" % (user.username,
                                         settings.SOCIALHOME_DOMAIN)
     assert profile.guid
Example #5
0
 def setUpTestData(cls):
     super().setUpTestData()
     cls.create_local_and_remote_user()
     cls.local_user = UserFactory()
     cls.create_content_set()
     cls.tagged_foobar = PublicContentFactory(text="#foobar", author=cls.profile)
     cls.tagged_foobar2 = SiteContentFactory(text="#foobar", author=cls.profile)
     cls.tagged_spam = PublicContentFactory(text="#spam", author=cls.profile)
     cls.tagged_spam2 = SiteContentFactory(text="#spam", author=cls.profile)
     cls.tag_foobar = Tag.objects.get(name="foobar")
     cls.tag_spam = Tag.objects.get(name="spam")
     cls.user.profile.followed_tags.add(cls.tag_spam)
Example #6
0
 def test_user_post_save_creates_a_profile(self, mock_init):
     user = UserFactory()
     profile = user.profile
     assert profile.user == user
     assert profile.name == user.name
     assert profile.email == user.email
     assert profile.rsa_private_key
     assert profile.rsa_public_key
     assert profile.handle == "%s@%s" % (user.username,
                                         settings.SOCIALHOME_DOMAIN)
     assert profile.guid
     self.assertEqual(mock_init.call_count, 2)
Example #7
0
 def test_get_last_name(self):
     user = UserFactory()
     profile = user.profile
     user.last_name = "foo"
     assert profile.get_last_name() == "foo"
     profile.user = None
     profile.name = "foo bar"
     assert profile.get_last_name() == "bar"
     profile.name = "foo"
     assert profile.get_last_name() == ""
     profile.name = ""
     assert profile.get_last_name() == ""
Example #8
0
 def test_forwards_relayable_if_local_content(self, mock_rq):
     user = UserFactory()
     self.content.author = user.profile
     self.content.save()
     self.content.refresh_from_db()
     mock_rq.reset_mock()
     process_entity_comment(self.comment, ProfileFactory())
     Content.objects.get(guid=self.comment.guid, parent=self.content)
     call_args = [
         call(forward_relayable, self.comment, self.content.id),
     ]
     self.assertEqual(mock_rq.call_args_list, call_args)
Example #9
0
 def setUpTestData(cls):
     super().setUpTestData()
     cls.user = UserFactory()
     cls.profile = cls.user.profile
     cls.follower = PublicProfileFactory()
     cls.follower2 = PublicProfileFactory()
     cls.profile.following.add(cls.follower)
     cls.profile.following.add(cls.follower2)
     cls.content = ContentFactory(author=cls.profile)
     cls.content2 = ContentFactory(author=cls.follower)
     cls.reply = ContentFactory(author=cls.profile, parent=cls.content2, content_type=ContentType.REPLY)
     cls.share = ContentFactory(author=cls.profile, share_of=cls.content2, content_type=ContentType.SHARE)
Example #10
0
 def setUpTestData(cls):
     super().setUpTestData()
     user = UserFactory()
     not_related_user = UserFactory()
     replying_user = UserFactory()
     replying_user2 = UserFactory()
     sharing_user = UserFactory()
     replying_user3 = UserFactory()
     cls.content = ContentFactory(author=user.profile)
     cls.not_related_content = ContentFactory(
         author=not_related_user.profile)
     cls.reply = ContentFactory(author=replying_user.profile,
                                parent=cls.content)
     cls.reply2 = ContentFactory(author=replying_user2.profile,
                                 parent=cls.content)
     cls.share = ContentFactory(author=sharing_user.profile,
                                share_of=cls.content)
     cls.reply3 = ContentFactory(author=replying_user3.profile,
                                 parent=cls.share)
     cls.content_url = "http://127.0.0.1:8000%s" % reverse(
         "content:view-by-slug",
         kwargs={
             "pk": cls.content.id,
             "slug": cls.content.slug
         })
     cls.participant_emails = [
         user.email,
         replying_user.email,
         sharing_user.email,
         replying_user3.email,
     ]
Example #11
0
 def test_local_content_gets_sent(self, mock_update, mock_send):
     user = UserFactory()
     mock_send.reset_mock()
     content = ContentFactory(author=user.profile)
     self.assertTrue(content.local)
     self.assertEqual(mock_send.call_count, 1)
     args, kwargs = mock_send.call_args_list[0]
     self.assertEqual(args[0], send_content)
     self.assertEqual(args[1], content.id)
     self.assertEqual(kwargs, {'recipient_id': None})
     activity = content.activities.first()
     self.assertEqual(args[2], activity.fid)
     self.assertEqual(activity.type, ActivityType.CREATE)
Example #12
0
 def test_visible_to_public_profile(self, admin_client):
     admin = User.objects.get(username="******")
     Profile.objects.filter(user__username="******").update(visibility=Visibility.PUBLIC)
     user = UserFactory(username="******")
     Profile.objects.filter(user__username="******").update(visibility=Visibility.PUBLIC)
     response = admin_client.get("/u/admin/")
     assert response.status_code == 200
     response = admin_client.get("/u/foobar/")
     assert response.status_code == 200
     response = admin_client.get("/p/%s/" % admin.profile.uuid)
     assert response.status_code == 200
     response = admin_client.get("/p/%s/" % user.profile.uuid)
     assert response.status_code == 200
Example #13
0
 def setUpTestData(cls):
     super().setUpTestData()
     author = UserFactory()
     author.profile.rsa_private_key = get_dummy_private_key().exportKey()
     author.profile.save()
     cls.public_content = PublicContentFactory(author=author.profile)
     cls.remote_reply = PublicContentFactory(parent=cls.public_content, author=ProfileFactory())
     cls.reply = PublicContentFactory(parent=cls.public_content)
     cls.share = PublicContentFactory(share_of=cls.public_content)
     cls.share_reply = PublicContentFactory(parent=cls.share)
     cls.limited_content = LimitedContentFactory(author=author.profile)
     cls.limited_reply = LimitedContentFactory(parent=cls.limited_content)
     cls.remote_limited_reply = LimitedContentFactory(parent=cls.limited_content)
     cls.limited_content.limited_visibilities.set((cls.limited_reply.author, cls.remote_limited_reply.author))
Example #14
0
 def test_visible_for_user_authenticated_user(self):
     user = UserFactory()
     self.assertTrue(
         self.public_content.visible_for_user(
             Mock(is_authenticated=True, profile=user.profile)))
     self.assertTrue(
         self.site_content.visible_for_user(
             Mock(is_authenticated=True, profile=user.profile)))
     self.assertFalse(
         self.self_content.visible_for_user(
             Mock(is_authenticated=True, profile=user.profile)))
     self.assertFalse(
         self.limited_content.visible_for_user(
             Mock(is_authenticated=True, profile=user.profile)))
Example #15
0
 def test_local_content_with_parent_sent_as_reply(self, mock_send):
     user = UserFactory()
     parent = ContentFactory(author=user.profile)
     mock_send.reset_mock()
     content = ContentFactory(author=user.profile, parent=parent)
     self.assertTrue(content.local)
     args, kwargs = mock_send.call_args_list[0]
     self.assertEqual(args, (send_reply_notifications, content.id))
     args, kwargs = mock_send.call_args_list[1]
     self.assertEqual(args[0], send_reply)
     self.assertEqual(args[1], content.id)
     activity = content.activities.first()
     self.assertEqual(args[2], activity.fid)
     self.assertEqual(activity.type, ActivityType.CREATE)
 def setUpTestData(cls):
     super().setUpTestData()
     cls.create_local_and_remote_user()
     cls.local_user = UserFactory()
     cls.create_content_set()
     cls.public_tagged = PublicContentFactory(text="#foobar",
                                              author=cls.profile)
     cls.site_tagged = SiteContentFactory(text="#foobar",
                                          author=cls.profile)
     cls.self_tagged = SelfContentFactory(text="#foobar",
                                          author=cls.profile)
     cls.limited_tagged = LimitedContentFactory(text="#foobar",
                                                author=cls.profile)
     cls.tag = cls.public_tagged.tags.first()
Example #17
0
 def setUpTestData(cls):
     super().setUpTestData()
     author = UserFactory()
     Profile.objects.filter(id=author.profile.id).update(
         rsa_private_key=get_dummy_private_key().exportKey())
     cls.public_content = ContentFactory(author=author.profile,
                                         visibility=Visibility.PUBLIC)
     cls.remote_content = ContentFactory(visibility=Visibility.PUBLIC)
     cls.remote_reply = ContentFactory(parent=cls.public_content,
                                       author=ProfileFactory())
     cls.reply = ContentFactory(parent=cls.public_content,
                                author=author.profile)
     cls.reply2 = ContentFactory(parent=cls.remote_content,
                                 author=author.profile)
Example #18
0
 def setUpTestData(cls):
     super().setUpTestData()
     cls.profile = ProfileFactory()
     cls.profile_with_handle = ProfileFactory(
         fid="https://example.com/randomremote",
         handle="*****@*****.**",
     )
     cls.profile_without_handle = ProfileFactory(
         fid="https://example.com/randomremote2",
     )
     cls.profile_without_handle.handle = None
     cls.profile_without_handle.save()
     cls.user = UserFactory(
         username="******",
     )
Example #19
0
 def test_local_content_update_gets_sent(self, mock_update, mock_send):
     user = UserFactory()
     content = ContentFactory(author=user.profile)
     self.assertTrue(content.local)
     mock_send.reset_mock()
     content.text = "foobar edit"
     content.save()
     self.assertEqual(mock_send.call_count, 1)
     args, kwargs = mock_send.call_args_list[0]
     self.assertEqual(args[0], send_content)
     self.assertEqual(args[1], content.id)
     self.assertEqual(kwargs, {'recipient_id': None})
     activity = content.activities.order_by('-created').first()
     self.assertEqual(args[2], activity.fid)
     self.assertEqual(activity.type, ActivityType.UPDATE)
Example #20
0
    def test_content_saved_in_correct_order(self):
        user = UserFactory()
        pinned_content_1 = ContentFactory(pinned=True,
                                          text="foobar",
                                          author=user.profile)
        pinned_content_2 = ContentFactory(pinned=True,
                                          text="foobar",
                                          author=user.profile)
        pinned_content_3 = ContentFactory(pinned=True,
                                          text="foobar",
                                          author=user.profile)

        self.assertEqual([
            pinned_content_1.order, pinned_content_2.order,
            pinned_content_3.order
        ], [1, 2, 3])
Example #21
0
 def setUpTestData(cls):
     super().setUpTestData()
     author = UserFactory()
     private_key = get_dummy_private_key().exportKey().decode("utf-8")
     Profile.objects.filter(id=author.profile.id).update(rsa_private_key=private_key)
     author.profile.refresh_from_db()
     cls.public_content = ContentFactory(author=author.profile, visibility=Visibility.PUBLIC)
     cls.remote_content = ContentFactory(visibility=Visibility.PUBLIC)
     cls.remote_profile = ProfileFactory(with_key=True)
     cls.remote_reply = ContentFactory(parent=cls.public_content, author=cls.remote_profile)
     cls.reply = ContentFactory(parent=cls.public_content, author=author.profile)
     cls.reply2 = ContentFactory(parent=cls.remote_content, author=author.profile)
     cls.limited_content = LimitedContentFactory(author=cls.remote_profile)
     cls.limited_local_content = LimitedContentFactory(author=author.profile)
     cls.limited_reply = LimitedContentFactory(author=author.profile, parent=cls.limited_content)
     cls.limited_local_reply = LimitedContentFactory(author=author.profile, parent=cls.limited_local_content)
     cls.limited_local_reply.limited_visibilities.add(cls.remote_profile)
Example #22
0
 def test_local_content_with_parent_sent_as_reply(self, mock_send):
     user = UserFactory()
     parent = ContentFactory(author=user.profile)
     mock_send.reset_mock()
     content = ContentFactory(author=user.profile, parent=parent)
     print(mock_send.call_args_list)
     self.assertTrue(content.local)
     activity = content.activities.first()
     send_reply_notifications_found = send_reply_found = False
     for args, kwargs in mock_send.call_args_list:
         if args == (send_reply_notifications, content.id):
             send_reply_notifications_found = True
         elif args[0] == send_reply and args[1] == content.id and args[
                 2] == activity.fid:
             send_reply_found = True
     if not all([send_reply_notifications_found, send_reply_found]):
         self.fail()
     self.assertEqual(activity.type, ActivityType.CREATE)
Example #23
0
 def _get_request_view_and_content(self, rf, create_content=True):
     request = rf.get("/")
     request.user = UserFactory()
     profile = request.user.profile
     profile.visibility = Visibility.PUBLIC
     profile.save()
     contents = []
     if create_content:
         contents.extend([
             ContentFactory(author=profile, order=3, pinned=True),
             ContentFactory(author=profile, order=2, pinned=True),
             ContentFactory(author=profile, order=1, pinned=True),
         ])
     view = ProfileDetailView(request=request,
                              kwargs={"guid": profile.guid})
     view.object = profile
     view.target_profile = profile
     return request, view, contents, profile
Example #24
0
 def setUpTestData(cls):
     super().setUpTestData()
     cls.user = UserFactory()
     cls.profile = ProfileFactory(visibility=Visibility.PUBLIC,
                                  handle='*****@*****.**',
                                  fid=None)
     cls.profile2 = ProfileFactory(visibility=Visibility.SITE,
                                   handle='*****@*****.**')
     cls.profile3 = ProfileFactory(visibility=Visibility.PUBLIC,
                                   fid='https://example.com/profile3')
     cls.profile4 = ProfileFactory(visibility=Visibility.PUBLIC,
                                   fid='https://example.com/profile/1234')
     cls.self_profile = ProfileFactory(visibility=Visibility.SELF,
                                       handle="*****@*****.**")
     cls.content = PublicContentFactory()
     cls.limited_content = LimitedContentFactory(author=cls.user.profile)
     cls.limited_content.limited_visibilities.set(
         (cls.profile, cls.profile2))
     cls.user.profile.following.add(cls.profile2)
Example #25
0
    def _get_request_view_and_content(self, rf, create_content=True):
        request = rf.get("/")
        request.user = UserFactory()
        profile = request.user.profile
        profile.visibility = Visibility.PUBLIC
        profile.save()

        contents = []
        if create_content:
            contents.extend([
                ContentFactory(author=profile, order=3, pinned=True),
                ContentFactory(author=profile, order=2, pinned=True),
                ContentFactory(author=profile, order=1, pinned=True),
            ])
            Content.objects.filter(id=contents[0].id).update(order=3)
            Content.objects.filter(id=contents[1].id).update(order=2)
            Content.objects.filter(id=contents[2].id).update(order=1)
        view = OrganizeContentProfileDetailView(request=request)
        view.object = profile
        view.target_profile = profile
        view.kwargs = {"guid": profile.guid}
        return request, view, contents, profile
Example #26
0
 def setUpTestData(cls):
     super().setUpTestData()
     cls.user = UserFactory()
     cls.user2 = AnonymousUser()
     cls.profile = cls.user.profile
     cls.public_content = ContentFactory(
         visibility=Visibility.PUBLIC, text="**Foobar**", author=cls.profile,
     )
     cls.site_content = ContentFactory(
         visibility=Visibility.SITE, text="_Foobar_"
     )
     cls.limited_content = ContentFactory(visibility=Visibility.LIMITED)
     cls.self_content = ContentFactory(visibility=Visibility.SELF)
     cls.remote_content = ContentFactory(
         visibility=Visibility.PUBLIC, remote_created=make_aware(datetime.datetime(2015, 1, 1))
     )
     cls.ids = [
         cls.public_content.id, cls.site_content.id, cls.limited_content.id, cls.self_content.id
     ]
     cls.set = {
         cls.public_content, cls.site_content, cls.limited_content, cls.self_content
     }
Example #27
0
 def setUpTestData(cls):
     super().setUpTestData()
     cls.create_local_and_remote_user()
     cls.user2 = AnonymousUser()
     cls.local_user = UserFactory()
     cls.public_content = ContentFactory(
         visibility=Visibility.PUBLIC,
         text="**Foobar**",
         author=cls.profile,
     )
     cls.site_content = ContentFactory(visibility=Visibility.SITE,
                                       text="_Foobar_")
     cls.limited_content = ContentFactory(visibility=Visibility.LIMITED)
     cls.self_content = ContentFactory(visibility=Visibility.SELF)
     cls.remote_content = ContentFactory(
         visibility=Visibility.PUBLIC,
         remote_created=make_aware(datetime.datetime(2015, 1, 1)),
         author=cls.remote_profile,
     )
     cls.ids = [
         cls.public_content.id, cls.site_content.id, cls.limited_content.id,
         cls.self_content.id
     ]
     cls.set = {
         cls.public_content, cls.site_content, cls.limited_content,
         cls.self_content
     }
     cls.content_with_twitter_oembed = ContentFactory(
         text='class="twitter-tweet"')
     cls.content_with_mentions = ContentFactory(
         text="foo @{bar; %s} bar @{foo; %s}" %
         (cls.user.profile.handle, cls.remote_profile.handle),
         author=cls.local_user.profile,
     )
     cls.content_with_url = ContentFactory(
         text="<p>https://example.com/foobar yay</p>",
         author=cls.local_user.profile,
     )
 def setUpTestData(cls):
     super().setUpTestData()
     cls.create_local_and_remote_user()
     cls.anonymous_user = AnonymousUser()
     cls.other_user = PublicUserFactory()
     cls.create_content_set()
     cls.public_share = PublicContentFactory(share_of=cls.public_content,
                                             author=cls.other_user.profile)
     cls.public_share2 = PublicContentFactory(share_of=cls.public_content)
     cls.limited_share = LimitedContentFactory(
         share_of=cls.limited_content, author=cls.other_user.profile)
     cls.self_share = SelfContentFactory(share_of=cls.self_content,
                                         author=cls.other_user.profile)
     cls.site_share = SiteContentFactory(share_of=cls.site_content,
                                         author=cls.other_user.profile)
     cls.other_user.profile.following.add(cls.public_content.author,
                                          cls.profile)
     cls.limited_content_user = UserFactory()
     cls.limited_content_profile = cls.limited_content_user.profile
     cls.limited_share.limited_visibilities.add(cls.limited_content_profile)
     cls.limited_content.limited_visibilities.add(
         cls.limited_content_profile)
     cls.limited_content_profile.following.add(cls.other_user.profile)
Example #29
0
 def setUpTestData(cls):
     super().setUpTestData()
     cls.create_local_and_remote_user()
     cls.user2 = AnonymousUser()
     cls.local_user = UserFactory()
     cls.public_content = ContentFactory(
         visibility=Visibility.PUBLIC, text="**Foobar**", author=cls.profile,
     )
     cls.site_content = ContentFactory(
         visibility=Visibility.SITE, text="_Foobar_"
     )
     cls.limited_content = ContentFactory(visibility=Visibility.LIMITED)
     cls.self_content = ContentFactory(visibility=Visibility.SELF)
     cls.remote_content = ContentFactory(
         visibility=Visibility.PUBLIC, remote_created=make_aware(datetime.datetime(2015, 1, 1)),
         author=cls.remote_profile,
     )
     cls.ids = [
         cls.public_content.id, cls.site_content.id, cls.limited_content.id, cls.self_content.id
     ]
     cls.set = {
         cls.public_content, cls.site_content, cls.limited_content, cls.self_content
     }
     cls.content_with_twitter_oembed = ContentFactory(text='class="twitter-tweet"')
Example #30
0
 def setUpTestData(cls):
     super().setUpTestData()
     cls.user = UserFactory()