def test_db_filled(self):
     # Verify that all users have been added to the db
     rv = self.app.get('/api/user/all{}'.format(token))
     self.assertEqual(5, len(rv.json))
     thres = queries.get_threshold('cake')
     self.assertEqual(1, thres.threshold)
     thres = queries.get_threshold('pizza')
     self.assertEqual(2, thres.threshold)
예제 #2
0
def status_data():
    status = {
        "cake_count": len(queries.get_pairs_since_last_used_reward("cake")),
        "pizza_count": len(queries.get_pairs_since_last_used_reward("pizza")),
        "pizza_thres": queries.get_threshold("pizza").threshold,
        "cake_thres": queries.get_threshold("cake").threshold,
    }
    pairs = queries.get_pair_history()
    if len(pairs) > 0:
        last_pair = pairs[-1]
        status['last_pair'] = [last_pair.person1, last_pair.person2]
    return jsonify(status)
예제 #3
0
def status_data():
    return jsonify({
        "cake_count":
        len(queries.get_pair_since_last_reward("cake")),
        "pizza_count":
        len(queries.get_pair_since_last_reward("pizza")),
        "pizza_thres":
        queries.get_threshold("pizza").threshold,
        "cake_thres":
        queries.get_threshold("cake").threshold,
        "unused_cake":
        queries.get_unused_rewards_count_by_type("cake"),
        "unused_pizza":
        queries.get_unused_rewards_count_by_type("pizza"),
        "last_pair": ["esog", "mleik"]
    })
예제 #4
0
def get_threshold(reward_type):
    threshold = queries.get_threshold(reward_type)
    if threshold is None:
        return jsonify([])
    return jsonify([{
        'reward_type': threshold.reward_type,
        'threshold': threshold.threshold
    }])
예제 #5
0
def update_threshold(reward_type, threshold):
    thresh = queries.get_threshold(reward_type)
    thresh.threshold = threshold
    queries.update_threshold(thresh)
    return jsonify({
        'reward_type': thresh.reward_type,
        'threshold': thresh.threshold
    })
예제 #6
0
def update_threshold(reward_type):
    thres_json = request.get_json()

    if thres_json is None or 'threshold' not in thres_json:
        abort(400)

    threshold = queries.get_threshold(reward_type)
    threshold.threshold = thres_json['threshold']
    queries.update_threshold(threshold)
    return jsonify({
        'reward_type': threshold.reward_type,
        'threshold': threshold.threshold
    })
 def test_update_threshold(self):
     self.app.put('/api/threshold/update/pizza/42{}'.format(token))
     threshold = queries.get_threshold('pizza')
     self.assertEqual(42, threshold.threshold)