示例#1
0
 def test_ServerViewAcces_false(self):
     author1 = Author(host="https://newpee.herokuapp.com/")
     author2 = Author(host="testhost")
     author1.save()
     author2.save()
     test_post = Post(author=author1)
     test_post.save()
     self.assertFalse(test_post.ServerViewAcces(author2))
示例#2
0
 def test_FriendServerViewAcess_false_not_friend_same_server(self):
     author1 = Author(host="https://newpee.herokuapp.com/")
     author2 = Author(host="https://newpee.herokuapp.com/")
     author1.save()
     author2.save()
     test_post = Post(author=author1)
     test_post.save()
     self.assertFalse(test_post.FriendServerViewAcess(author2))
示例#3
0
 def test_privateViewAccess_true(self):
     author1 = Author()
     author2 = Author()
     author1.save()
     author2.save()
     test_post = Post(author=author1)
     test_post.set_visible_to(author2)
     test_post.save()
     self.assertTrue(test_post.privateViewAccess(author2))
示例#4
0
 def test_FriendServerViewAcess_true(self):
     author1 = Author(host="https://newpee.herokuapp.com/")
     author2 = Author(host="https://newpee.herokuapp.com/")
     author1.save()
     author2.save()
     author1.friends.add(author2)
     author2.friends.add(author1)
     test_post = Post(author=author1)
     test_post.save()
     self.assertTrue(test_post.FriendServerViewAcess(author2))
示例#5
0
 def test_friendViewAccess_true(self):
     author1 = Author()
     author2 = Author()
     author1.save()
     author2.save()
     author1.friends.add(author2)
     author2.friends.add(author1)
     test_post = Post(author=author1)
     test_post.save()
     self.assertTrue(test_post.friendViewAccess(author2))
示例#6
0
 def test_set_visible_to(self):
     author1 = Author()
     author2 = Author()
     author1.save()
     author2.save()
     test_post = Post(author=author1)
     #setting testpost to be visible to author2
     test_post.set_visible_to(author2)
     test_post.save()
     self.assertEqual(test_post.visible_to.all()[0], author2)
示例#7
0
def createPost(id):
    user = User.query.filter_by(id=id).first()
    if user is None:
        return jsonify("no user exists with id {}".format(id)), 400
    else:
        input = request.json
        post = Post(body=input['body'], author=user, title=input['title'])
        db.session.add(post)
        db.session.commit()
    return jsonify('Created Post for username {}'.format(
        post.author.username)), 201
示例#8
0
 def test_FOAFViewAccess_false(self):
     author1 = Author()
     author2 = Author()
     author3 = Author()
     author1.save()
     author2.save()
     author3.save()
     #author 1 is frineds with 2
     author1.friends.add(author2)
     author2.friends.add(author1)
     test_post = Post(author=author1)
     test_post.save()
     self.assertFalse(test_post.FOAFViewAccess(author3))
def insert_dummy_data():
    # users data
    with open('Users/users.json') as file:
        data = json.load(file)
    file.close()
    for user_item in data:
        user = User(username=user_item['username'])
        user.email = user_item['email']
        user.hash_password(user_item['password'])
        db.session.add(user)
        db.session.commit()
    # posts data
    with open('Posts/posts.json') as file:
        data = json.load(file)
        for post_item in data:
            post = Post()
            post.id = post_item['id']
            post.body = post_item['body']
            post.user_id = post_item['userId']
            post.title = post_item['title']
            db.session.add(post)
            db.session.commit()
示例#10
0
    def test_make_private_to_me(self):

        test_author = Author()
        test_post = Post(author=test_author, visibility="PRIVATE")

        self.assertEqual(test_post.visibility, "PRIVATE")
示例#11
0
    def test_post_date(self):

        test_post = Post(published=datetime.datetime.now())

        self.assertIsNotNone(test_post.get_post_date())
示例#12
0
    def test_parent(self):

        test_post = Post()
        test_comment = Comment(parent=test_post)

        self.assertEquals(test_comment.get_parent(), test_post)
示例#13
0
    def test_make_public(self):

        test_author = Author()
        test_post = Post(author=test_author)

        self.assertEqual(test_post.visibility, "PUBLIC")
示例#14
0
 def test_unlisted_true(self):
     author1 = Author(host="http://newpee.herokuapp.com/")
     author1.save()
     test_post = Post(author=author1, unlisted=True)
     test_post.save()
     self.assertTrue(test_post.getUnlisted())
示例#15
0
    def test_get_post_id(self):

        test_post = Post()
        test_id = test_post.get_id()

        self.assertIsNotNone(test_id)