def test_get_reward_count(self):
        queries.add_reward(Reward('pizza'))
        queries.add_reward(Reward('cake'))
        queries.add_reward(Reward('pizza'))

        rewards = self.app.get('/api/reward/all{}'.format(token)).json
        self.assertEqual(3, len(rewards))
    def test_use_reward(self):
        queries.add_reward(Reward('cake'))
        queries.add_reward(Reward('pizza'))
        queries.add_reward(Reward('pizza'))

        self.app.put('/api/reward/use/pizza{}'.format(token))
        rewards = self.app.get('api/reward/all{}'.format(token)).json
        count = 0
        for r in rewards:
            if r['used_reward']:
                count += 1
        self.assertEqual(1, count)
Beispiel #3
0
def add_reward():
    r = request.get_json()

    if r is None or 'reward_type' not in r:
        abort(400)

    if 'date' not in r:
        reward = Reward(r['reward_type'].lower())
    else:
        reward = Reward(r['reward_type'].lower(), r['date'])
    if 'used_reward' in r:
        reward.used_reward = r['used_reward']
    queries.add_reward(reward)
    return format_rewards([reward])
    def test_get_pair_after_reward(self):
        pair = {'person1': 'test1', 'person2': 'test3'}
        self.app.post('/api/pair/add{}'.format(token),
                      data=json.dumps(pair),
                      content_type='application/json')
        date = math.floor(datetime.datetime.now().timestamp() * 1000)

        queries.add_reward(Reward('pizza'))

        rv = self.app.get(
            '/api/pair/all/after_last_reward/pizza{}'.format(token))
        pairs = rv.json
        self.assertEqual(1, len(pairs))

        pair = {'date': date, 'person1': 'test1', 'person2': 'test3'}
        self.app.post('/api/pair/add{}'.format(token),
                      data=json.dumps(pair),
                      content_type='application/json')

        rv = self.app.get(
            'api/pair/all/after_last_reward/pizza{}'.format(token))
        pairs = rv.json
        self.assertEqual(2, len(pairs))

        self.app.put('/api/reward/use/pizza{}'.format(token))
        rv = self.app.get(
            'api/pair/all/after_last_reward/pizza{}'.format(token))
        pairs = rv.json
        self.assertEqual(1, len(pairs))
Beispiel #5
0
def check_for_reward():
    thresholds = queries.get_all_thresholds()
    for t in thresholds:
        if t.threshold == len(
                queries.get_pairs_since_last_reward(t.reward_type)):
            queries.add_reward(Reward(t.reward_type))