示例#1
0
    def test_register_get(self):
        raise SkipTest('"Rating register get" functionality is not implemented')
        rating1 = model.Rating(user_ip_address='1.2.3.4',
                               package=self.anna,
                               rating=4.0)
        rating2 = model.Rating(user=model.User.by_name(u'annafan'),
                               package=self.anna,
                               rating=2.0)
        model.Session.add_all((rating1, rating2))
        model.repo.commit_and_remove()

        offset = self.rating_offset()
        res = self.app.get(offset, status=[200])
示例#2
0
    def test_entity_get(self):
        raise SkipTest('"Rating entity get" functionality is not implemented')
        rating = model.Rating(user_ip_address='1.2.3.4',
                              package=self.anna,
                              rating=4.0)
        model.Session.add(rating)
        model.repo.commit_and_remove()

        offset = self.rating_offset(self.anna.name)
        res = self.app.get(offset, status=[200])
        assert_equal(res, rating_opts['rating'])
示例#3
0
    # but the commit happens in this one. (TODO leave caller to commit.)
    user = None
    if isinstance(user_or_ip, model.User):
        user = user_or_ip
        rating_query = model.Session.query(model.Rating).filter_by(
            package=package, user=user)
    else:
        ip = user_or_ip
        rating_query = model.Session.query(model.Rating).filter_by(
            package=package, user_ip_address=ip)

    try:
        rating = float(rating)
    except TypeError, ValueError:
        raise RatingValueException
    if rating > MAX_RATING or rating < MIN_RATING:
        raise RatingValueException

    if rating_query.count():
        rating_obj = rating_query.first()
        rating_obj.rating = rating
    elif user:
        rating = model.Rating(package=package, user=user, rating=rating)
        model.Session.add(rating)
    else:
        rating = model.Rating(package=package,
                              user_ip_address=ip,
                              rating=rating)
        model.Session.add(rating)
    model.repo.commit_and_remove()