示例#1
0
    def test_rating_messages(self):

        # for creating a post to like
        location = {'latitude': 43.0100431, 'longitude': -78.8012356}
        username = "******"
        msg = "this is a rating test post"
        place_id = "ChIJwe_oGNJz04kRDxhd61f1WiQ"
        es = timezone("US/Eastern")
        time = str(datetime.now().astimezone(es) + timedelta(days=7))
        # for liking
        rel = "LIKED"

        #add user to database first
        pwd = "admin"
        email = "*****@*****.**"
        fn = "Darren"
        ln = "Matthew"
        password_hash = authenticate.generate_hash(username, pwd)

        user = User(username, fn, ln, email, password_hash)

        self.assertTrue(neo4j.add_user(user))

        # create a test post to add a like to
        post_id = neo4j.post_message(username, location, msg, time, place_id)
        # add like to the post
        success = neo4j.rate_post(post_id, rel, username)

        # delete test post
        neo4j.delete_post(post_id)
        # delete user
        neo4j.delete_user(username, password_hash)
        self.assertTrue(success)
示例#2
0
    def test_posting_messages(self):

        # get location, username, msg, and expiration time from client
        location = {'latitude': 43.0100431, 'longitude': -78.8012356}
        username = "******"
        msg = "this is a neo4j test post"
        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))
        # post a message with the above information
        post_id = neo4j.post_message(username, location, msg, exp_time,
                                     place_id)
        print(post_id)
        self.assertNotEqual(post_id, None)
        #delete user
        self.assertTrue(neo4j.delete_user(username, password_hash))
示例#3
0
    def test_get_message_history(self):

        # get location, username, msg, and expiration time from client
        user_location = {'latitude': 13.0100431, 'longitude': -8.8012356}
        location1 = {'latitude': 43.0100431, 'longitude': -78.8012356}
        location2 = {'latitude': 139.0100, 'longitude': -20.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 test post"
        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)))

        # get number of posts returned
        messages_json = neo4j.get_posts(user_location, 20)
        before_num = len(messages_json)

        # neither of theses messages would be visible normally, but would show up in a user's history
        id1 = neo4j.post_message(username, location1, msg, exp_time, place_id)
        id2 = neo4j.post_message(username, location2, msg, exp_time, place_id)

        # get number of posts returned after
        messages_json = neo4j.get_user_post_history(username)
        after_num = len(messages_json)

        # delete messages created for test
        neo4j.delete_post(id1)
        neo4j.delete_post(id2)
        # delete user
        neo4j.delete_user(username, password_hash)
        self.assertGreater(after_num, before_num)
示例#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 test_delete_message(self):

        # get location and distance from client
        location = {'latitude': 43.0100431, 'longitude': -78.8012356}
        distance = 30  # radius in meters
        es = timezone("US/Eastern")
        time = str(datetime.now().astimezone(es) + timedelta(days=7))
        placeId = '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
        remove_id = neo4j.post_message(uname, location,
                                       "unit test post to be removed", time,
                                       placeId)
        print(remove_id)

        # get total number of posts
        messages_json = neo4j.get_posts(location, distance)
        before_num = len(json.loads(messages_json))

        # remove the added post
        neo4j.delete_post(remove_id)

        # get number of posts returned after removing
        messages_json = neo4j.get_posts(location, distance)
        after_num = len(json.loads(messages_json))

        self.assertLess(after_num, before_num)
        # delete user
        neo4j.delete_user(uname, password_hash)
示例#6
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)
示例#7
0
def message():
    # USED FOR RETRIEVING MESSAGES
    if request.method == 'GET':

        lat = float(request.args.get('lat'))
        lon = float(request.args.get('long'))
        dist = int(request.args.get('distance'))
        location_json = {"latitude": lat, "longitude": lon}
        return neo4j.get_posts(location_json, dist)

    # USED TO POST MESSAGES
    elif request.method == 'POST':
        username = request.json['username']
        location = request.json['location']
        msg = request.json['message']
        expire_time = request.json['expireTime']
        place_id = request.json['placeId']
        return str(
            neo4j.post_message(username, location, msg, expire_time, place_id))

    # USED TO DELETE MESSAGES
    else:
        post_id = request.json['postId']
        return str(neo4j.delete_post(post_id))
示例#8
0
 def setUp(self):
     # add username and password to database to signup
     self.uname = "admin"
     self.pwd = "admin"
     self.email = "*****@*****.**"
     self.fn = "Darren"
     self.ln = "Matthew"
     self.brd = "2000/1/1"
     self.hometown = "buffalo"
     self.msg = "this is a neo4j test reply"
     self.place_id = "ChIJwe_oGNJz04kRDxhd61f1WiQ"
     self.radius = 10000
     # get current time for time of post
     es = timezone("US/Eastern")
     self.location = {'latitude': 43.0100431, 'longitude': -78.8012356}
     self.exp_time = str(
         (datetime.now().astimezone(es) + timedelta(days=7)))
     self.password_hash = authenticate.generate_hash(self.uname, self.pwd)
     user = User(self.uname, self.fn, self.ln, self.email,
                 self.password_hash, self.brd, self.hometown)
     neo4j.delete_user(self.uname, self.password_hash)
     neo4j.add_user(user)
     self.post_id = neo4j.post_message(self.uname, self.location, self.msg,
                                       self.exp_time, self.place_id)