示例#1
0
    def test_posting_replies(self):

        # get msg, username, and post_id from client
        location = {'latitude': 43.0100431, 'longitude': -78.8012356}
        username = "******"
        msg = "this is a neo4j test reply"
        place_id = "ChIJwe_oGNJz04kRDxhd61f1WiQ"

        # get current time for time of post
        es = timezone("US/Eastern")
        exp_time = str((datetime.now().astimezone(es) + timedelta(days=7)))
        # add username and password to database to signup
        pwd = "admin"
        email = "*****@*****.**"
        fn = "Darren"
        ln = "Matthew"
        password_hash = authenticate.generate_hash(username, pwd)
        user = User(username, fn, ln, email, password_hash)
        # test adding user
        self.assertTrue(neo4j.add_user(user))
        # create a test post to reply to
        post_id = neo4j.post_message(username, location, msg, exp_time,place_id)
        print(post_id)

        self.assertTrue(neo4j.reply_to_post(msg, post_id, username))

        # delete test post
        neo4j.delete_post(post_id)
        # delete user
        self.assertTrue(neo4j.delete_user(username, password_hash))
示例#2
0
    def test_getting_replies(self):
        # set initial vars
        location = {'latitude': 43.0100431, 'longitude': -78.8012356}

        # get current time for time of post
        es = timezone("US/Eastern")
        exp_time = str((datetime.now().astimezone(es) + timedelta(days=7)))
        place_id = "ChIJwe_oGNJz04kRDxhd61f1WiQ"
        # add username and password to database to signup
        uname = "admin"
        pwd = "admin"
        email = "*****@*****.**"
        fn = "Darren"
        ln = "Matthew"
        password_hash = authenticate.generate_hash(uname, pwd)

        # delete user if already exists
        neo4j.delete_user(uname, password_hash)

        user = User(uname, fn, ln, email, password_hash)
        # test adding user
        self.assertTrue(neo4j.add_user(user))

        # add a post to the database in case there isn't one
        post_id = neo4j.post_message(uname, location,
                                     "unit test post for getting replies",
                                     exp_time, place_id)

        # get number of replies before posting one
        replies_json = neo4j.get_post_replies(post_id)
        before_num = len(replies_json)

        # add a reply to the post
        neo4j.reply_to_post("unit test reply", post_id, uname)

        # get number of replies returned after posting one
        replies_json = neo4j.get_post_replies(post_id)
        after_num = len(replies_json)

        # delete the post created for the test (also deletes replies)
        neo4j.delete_post(post_id)
        # delete user
        neo4j.delete_user(uname, password_hash)
        self.assertGreater(after_num, before_num)
示例#3
0
    def test_8_get_user_reply_history(self):
        payload = {'username': self.uname}
        url = 'http://127.0.0.1:5000/history/replies'

        self.msg = "This is a second reply"

        self.assertTrue(neo4j.reply_to_post(self.msg, self.post_id,
                                            self.uname))

        r = requests.get(url, params=payload)
        self.assertEqual(r.status_code, 200)
        print("CSE-111/Getting user reply history: \n" + str(r.text) + "\n")
        self.assertTrue(r.text)
示例#4
0
    def test_delete_reply(self):

        # get msg, username, and post_id from client
        location = {'latitude': 43.0100431, 'longitude': -78.8012356}
        username = "******"
        pwd = "admin"
        email = "*****@*****.**"
        fn = "Darren"
        ln = "Matthew"
        password_hash = authenticate.generate_hash(username, pwd)

        # delete user if already exists
        neo4j.delete_user(username, password_hash)

        user = User(username, fn, ln, email, password_hash)
        # test adding user
        self.assertTrue(neo4j.add_user(user))
        msg = "this is a neo4j deletion test reply"
        placeId = 'ChIJwe_oGNJz04kRDxhd61f1WiQ'

        # get current time for time of post
        es = timezone("US/Eastern")
        exp_time = str((datetime.now().astimezone(es) + timedelta(days=7)))

        # create a test post to reply to
        post_id = neo4j.post_message(username, location, msg, exp_time,
                                     placeId)
        print(post_id)

        # make a reply to the post
        reply_id = neo4j.reply_to_post(msg, post_id, username)

        # get number of replies returned before removing
        replies_json = neo4j.get_post_replies(post_id)
        before_num = len(json.loads(replies_json))

        # delete test reply
        neo4j.delete_reply(reply_id)

        # get number of replies returned after removing
        replies_json = neo4j.get_post_replies(post_id)
        after_num = len(json.loads(replies_json))

        self.assertLess(after_num, before_num)

        # delete test post
        neo4j.delete_post(post_id)
        # delete user
        neo4j.delete_user(username, password_hash)
示例#5
0
def replies():
    # USED FOR RETRIEVING A POST'S REPLIES
    if request.method == 'GET':
        post_id = request.args.get('postId')
        return neo4j.get_post_replies(post_id)

    # USED FOR REPLYING TO A POST
    elif request.method == 'POST':
        post_id = request.json['postId']
        username = request.json['username']
        reply_text = request.json['replyText']
        return str(neo4j.reply_to_post(reply_text, post_id, username))

    # USED FOR DELETING A REPLY
    else:
        reply_id = request.json['replyId']
        return str(neo4j.delete_reply(reply_id))