예제 #1
0
    def test_get_author(self):

        test_author = Author()
        test_post = Post(author=test_author)
        test_fetch_author = test_post.get_author()

        self.assertEqual(test_author, test_fetch_author)
예제 #2
0
    def test_time_linear(self):

        test_post = Post(published=datetime.datetime.now() -
                         datetime.timedelta(days=1))
        later_time = datetime.datetime.now()

        self.assertLess(test_post.get_post_date(), later_time)
예제 #3
0
 def test_friendViewAccess_false(self):
     author1 = Author()
     author2 = Author()
     author1.save()
     author2.save()
     test_post = Post(author=author1)
     test_post.save()
     self.assertFalse(test_post.friendViewAccess(author2))
예제 #4
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))
예제 #5
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))
예제 #6
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))
예제 #7
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))
예제 #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))
예제 #9
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))
예제 #10
0
파일: tests.py 프로젝트: tbtz/kwoots
    def test_user_is_no_spammer(self):
        print('### Expect to be no spammer\n')

        create_test_post('Post 1', 200, self.test_user)
        create_test_post('Post 2', 180, self.test_user)
        create_test_post('Post 3', 160, self.test_user)
        create_test_post('Post 4', 140, self.test_user)

        result = Post.author_is_spammer(self.test_user.username)

        self.assertFalse(result)
예제 #11
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
예제 #12
0
파일: tests.py 프로젝트: tbtz/kwoots
    def test_user_is_spammer(self):
        print('### Expect to be a spammer\n')

        create_test_post('Post 1', 90, self.test_user)
        create_test_post('Post 2', 80, self.test_user)
        create_test_post('Post 3', 10, self.test_user)
        create_test_post('Post 4', 5, self.test_user)

        result = Post.author_is_spammer(self.test_user.username)

        self.assertTrue(result)
예제 #13
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)
예제 #14
0
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()
예제 #15
0
    def test_get_post_id(self):

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

        self.assertIsNotNone(test_id)
예제 #16
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())
예제 #17
0
    def test_make_public(self):

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

        self.assertEqual(test_post.visibility, "PUBLIC")
예제 #18
0
    def test_parent(self):

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

        self.assertEquals(test_comment.get_parent(), test_post)
예제 #19
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")
예제 #20
0
    def test_post_date(self):

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

        self.assertIsNotNone(test_post.get_post_date())