Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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))
Ejemplo n.º 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))
Ejemplo n.º 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))
Ejemplo n.º 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))
Ejemplo n.º 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))
Ejemplo n.º 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))
Ejemplo n.º 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))
Ejemplo n.º 10
0
Archivo: tests.py Proyecto: 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)
Ejemplo n.º 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
Ejemplo n.º 12
0
Archivo: tests.py Proyecto: 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)
Ejemplo n.º 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)
Ejemplo n.º 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()
Ejemplo n.º 15
0
    def test_get_post_id(self):

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

        self.assertIsNotNone(test_id)
Ejemplo n.º 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())
Ejemplo n.º 17
0
    def test_make_public(self):

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

        self.assertEqual(test_post.visibility, "PUBLIC")
Ejemplo n.º 18
0
    def test_parent(self):

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

        self.assertEquals(test_comment.get_parent(), test_post)
Ejemplo n.º 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")
Ejemplo n.º 20
0
    def test_post_date(self):

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

        self.assertIsNotNone(test_post.get_post_date())