示例#1
0
    def test_6_get_user_ratings(self):
        payload = {'username': self.uname}
        url = 'http://127.0.0.1:5000/history/ratings'

        relation = "LIKED"
        self.msg = "This message for a reply"

        neo4j.rate_post(self.post_id, relation, self.uname)

        r = requests.get(url, params=payload)
        self.assertEqual(r.status_code, 200)
        print("CSE-111/Getting user rating: \n" + str(r.text) + "\n")
        self.assertTrue(r.text)
示例#2
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)
示例#3
0
    def test_7_check_If_user_didrare(self):

        payload = {'postId': self.post_id, 'username': self.uname}

        relation = "DISLIKED"
        self.msg = "This message for a rating"

        neo4j.rate_post(self.post_id, relation, self.uname)

        url = 'http://127.0.0.1:5000/didrate'
        r = requests.get(url, params=payload)

        self.assertEqual(r.status_code, 200)
        print("CSE-118/Checking if user did rate a post: \n" + str(r.text) +
              "\n")
        self.assertTrue(r.text)
示例#4
0
def rating():
    # USED TO RETRIEVE THE LIKES/DISLIKES ON A POST
    if request.method == 'GET':
        post_id = request.args.get('postId')

        return neo4j.get_ratings(post_id)

    # USED FOR LIKING OR DISLIKING A POST
    else:
        post_id = request.json['postId']
        p_rating = request.json['rating']
        username = request.json['username']

        # PARSE RATING (true is a like, false is a dislike)
        if p_rating:
            relation = "LIKED"
        else:
            relation = "DISLIKED"

        return str(neo4j.rate_post(post_id, relation, username))