def test_see_friend_posts(self): a1password = "******" a1name = "test_see_friend_posts_user1" author1 = setupUser(a1name, a1password) author2 = setupUser("test_see_friend_posts_user2") self.client.login(username=a1name, password=a1password) numPublicPosts = Posts.objects.all().filter( visibility__in=["PUBLIC"]).count() resp = self.client.get("/author/posts/").data self.assertEqual( numPublicPosts, resp["count"]) # no friends yet, so nothing should be different # add a post by author 2 createPostForAuthor(author2, "test_see_friend_posts user2's friends posts", "FRIENDS") resp = self.client.get("/author/posts/").data self.assertEqual( numPublicPosts, resp["count"]) # no friends yet, so nothing should be different makeFriends(author1, author2) # Should be an extra post returned because they're friends :) resp = self.client.get("/author/posts/").data self.assertEqual(numPublicPosts + 1, resp["count"]) self.client.logout()
def test_get_author_unlisted(self): author = setupUser("test_get_author_unlisted_user") aName = "test_get_author_unlisted_user2" aPassword = "******" author2 = setupUser(aName, aPassword) url = getAuthorPostUrl(author) # all posts are unlisted createPostForAuthor(author, "public content", "PUBLIC", unlisted=True) createPostForAuthor(author, "server content", "SERVERONLY", unlisted=True) createPostForAuthor(author, "friend content", "FRIENDS", unlisted=True) createPostForAuthor(author, "foaf content", "FOAF", unlisted=True) createPostForAuthor(author, "private content", "PRIVATE", unlisted=True) # none of the posts should be visible (anon) resp = self.client.get(url).data self.assertEqual(0, resp["count"]) self.client.login(username=aName, password=aPassword) # none of the posts should be visible (logged in) resp = self.client.get(url).data self.assertEqual(0, resp["count"]) makeFriends(author, author2) # none of the posts should be visible (regardless of friendship) resp = self.client.get(url).data self.assertEqual(0, resp["count"])
def test_unlisted(self): aName = "test_unlisted_user" aPassword = "******" author = setupUser("test_unlisted_user2") author2 = setupUser(aName, aPassword) numPublicPosts = Posts.objects.all().filter( visibility__in=["PUBLIC", "SERVERONLY"]).count() createPostForAuthor(author, "public content", "PUBLIC", unlisted=True) createPostForAuthor(author, "server content", "SERVERONLY", unlisted=True) createPostForAuthor(author, "friend content", "FRIENDS", unlisted=True) createPostForAuthor(author, "foaf content", "FOAF", unlisted=True) createPostForAuthor(author, "private content", "PRIVATE", unlisted=True) createPostForAuthor(author2, "public content", "PUBLIC", unlisted=True) createPostForAuthor(author2, "server content", "SERVERONLY", unlisted=True) createPostForAuthor(author2, "friend content", "FRIENDS", unlisted=True) createPostForAuthor(author2, "foaf content", "FOAF", unlisted=True) createPostForAuthor(author2, "private content", "PRIVATE", unlisted=True) resp = self.client.get("/author/posts/").data for post in resp["posts"]: print(post) self.assertEqual( numPublicPosts, resp["count"]) # nothing should have changed (all unlisted) self.client.login(username=aName, password=aPassword) resp = self.client.get("/author/posts/").data self.assertEqual( numPublicPosts, resp["count"]) # nothing should have changed (all unlisted) # check if making friends changes anything makeFriends(author, author2) resp = self.client.get("/author/posts/").data self.assertEqual( numPublicPosts, resp["count"]) # nothing should have changed (all unlisted) self.client.logout()
def test_author_friend(self): author = setupUser("test_author_friend_user") aName = "test_author_friend_user2" aPassword = "******" author2 = setupUser(aName, aPassword) url = getAuthorPostUrl(author) self.client.login(username=aName, password=aPassword) createPostForAuthor(author, "friend content", "FRIENDS") createPostForAuthor(author, "foaf content", "FOAF") createPostForAuthor(author, "private content", "PRIVATE") # none of the posts should be visible (they aren't friends yet) resp = self.client.get(url).data self.assertEqual(0, resp["count"]) makeFriends(author, author2) # two posts (foaf, friends) should be visible (they're friends now) resp = self.client.get(url).data self.assertEqual(2, resp["count"])
def test_author_foaf(self): author = setupUser("test_author_foaf_user") aName = "test_author_foaf_user2" aPassword = "******" author2 = setupUser(aName, aPassword) middleAuthor = setupUser("middleman_test_author_foaf") url = getAuthorPostUrl(author) self.client.login(username=aName, password=aPassword) createPostForAuthor(author, "friend content", "FRIENDS") createPostForAuthor(author, "foaf content", "FOAF") createPostForAuthor(author, "private content", "PRIVATE") # none of the posts should be visible (they aren't foafs yet) resp = self.client.get(url).data self.assertEqual(0, resp["count"]) makeFriends(middleAuthor, author2) makeFriends(middleAuthor, author) # only the foaf post should be visible resp = self.client.get(url).data self.assertEqual(1, resp["count"])
def test_foafing_posts(self): a1password = "******" a1name = "test_foafing_posts_user1" A = setupUser(a1name, a1password) B = setupUser("test_foafing_posts_user2") C = setupUser("test_foafing_posts_user3") D = setupUser("test_foafing_posts_user4") self.client.login(username=a1name, password=a1password) # login to user A numPublicPosts = Posts.objects.all().filter( visibility__in=["PUBLIC"]).count() # Add a FOAF post for B createPostForAuthor(B, "a FOAF post from user B", "FOAF") # Add a FOAF post for C createPostForAuthor(C, "a FOAF post from user C", "FOAF") # Add a FOAF post for D createPostForAuthor(D, "a FOAF post from user D", "FOAF") resp = self.client.get("/author/posts/").data self.assertEqual( numPublicPosts, resp["count"]) # no friends yet, so nothing should be different makeFriends(A, B) resp = self.client.get("/author/posts/").data self.assertEqual(numPublicPosts + 1, resp["count"]) # we should see B's 1 FOAF post makeFriends(B, C) resp = self.client.get("/author/posts/").data self.assertEqual(numPublicPosts + 2, resp["count"]) # we should see C's 1 FOAF post makeFriends(C, D) resp = self.client.get("/author/posts/").data self.assertEqual( numPublicPosts + 2, resp["count"] ) # we shouldn't see third degree posts (# stays the same last time) # Add a Friends post for C createPostForAuthor(C, "a FRIENDS post from user C", "FRIENDS") resp = self.client.get("/author/posts/").data self.assertEqual( numPublicPosts + 2, resp["count"] ) # we shouldn't see FOAF Friend posts (# stays the same last time) self.client.logout()
def test_author_only(self): author = setupUser("test_author_only") aName = "test_author_only_reader" aPassword = "******" reader = setupUser(aName, aPassword) url = getAuthorPostUrl(author) noisemaker1 = setupUser("noisy1") noisemaker2 = setupUser("noisy2") noisemaker3 = setupUser("noisy3") createPostForAuthor(noisemaker1, "here's a public post") createPostForAuthor(noisemaker1, "I ate mac and cheese for lunch") createPostForAuthor(noisemaker1, "I love my mom") createPostForAuthor(noisemaker1, "I love my friends more, sorry mom", "FRIENDS") createPostForAuthor( noisemaker2, "Why would anyone try to tackle Twitter and Mastodon?") createPostForAuthor(noisemaker3, "@noisy2, I think this is a school project") createPostForAuthor(noisemaker2, "Am I even real then?") createPostForAuthor(noisemaker2, "Dear Diary, I'm having an existential crisis...", "PRIVATE") createPostForAuthor( noisemaker3, "If you have no friends, this post is the same as a private one :)", "FRIENDS") createPostForAuthor(noisemaker1, "@noisy3 do you like my mac and cheese?") createPostForAuthor(reader, "I enjoy reading but I also enjoy posting") createPostForAuthor( noisemaker2, "Can you review my new book 'Getting Out of Here', I'll send you an email with it.", "PRIVATE", makeVisibleTo=[get_author_url(str(reader.pk))]) createPostForAuthor( reader, "@noisy2 Sorry, I can't read your book, it's just frantic scribbling." ) createPostForAuthor(noisemaker2, "@test_author_only_reader DON'T TELL THEM HERE") self.client.login(username=aName, password=aPassword) # the author we are tracking hasn't made any posts resp = self.client.get(url).data self.assertEqual(0, resp["count"]) makeFriends(author, noisemaker1) makeFriends(author, noisemaker2) makeFriends(noisemaker3, noisemaker2) makeFriends(noisemaker3, reader) makeFriends(author, reader) # the author we are tracking hasn't made any posts resp = self.client.get(url).data self.assertEqual(0, resp["count"]) createPostForAuthor( author, "Hello I read your book and I have some questions", "PRIVATE", makeVisibleTo=[get_author_url(str(noisemaker2.pk))]) createPostForAuthor( author, "this is kind of meta since my variable name is also author", "PRIVATE") # the author we are tracking hasn't made any (public) posts resp = self.client.get(url).data self.assertEqual(0, resp["count"])