def test_find_lunchmates_new_user(self):
        store = {"USER_LIST": SAMPLE_USERLIST}
        result = lunchtime_matching.find_lunchmates(store, "newguy")

        self.assertTrue("newguy" in store)
        self.assertTrue(3 <= len(result) <= 5)
        self.assertTrue(len(store["newguy"]["lunch_matches"]) == len(result))
    def test_find_lunchmates_not_enough_users(self):
        store = {
            "USER_LIST": ["john", "dave"],
            "john": {
                "coffee_matches": [],
                "lunch_matches": []
            }
        }
        result = lunchtime_matching.find_lunchmates(store, "john")

        self.assertEqual(result, [])
    def test_find_lunchmates_full_matchlist(self):
        store = {
            "USER_LIST": SAMPLE_USERLIST,
            "john": {
                "coffee_matches": [],
                "lunch_matches": [v for v in SAMPLE_USERLIST]
            }
        }
        result = lunchtime_matching.find_lunchmates(store, "john")

        self.assertEqual(len(result), len(store["john"]["lunch_matches"]))
    def test_find_lunchmates_existing_user(self):
        store = {
            "USER_LIST": SAMPLE_USERLIST,
            "john": {
                "coffee_matches": [],
                "lunch_matches": ["dave", "test", "blue"]
            }
        }
        result = lunchtime_matching.find_lunchmates(store, "john")

        self.assertFalse("john" in result)
        self.assertTrue(len(store["john"]["lunch_matches"]) == len(result) + 3)
예제 #5
0
def lunchtime():
    """
    route to handle users lunch/coffee choice
    - responds with the result being their matched user(s)
    - expected request body:
    {
        user: string,
        meetup_type: string
    }
    - expected response body:
    {
        result: string
    }
    """
    user = request.json.get('user', '')
    meetup_type = request.json.get('meetup_type', '')

    result = ""

    if user and meetup_type and meetup_type in ['lunch', 'coffee']:
        if meetup_type == 'coffee':
            matched_user = lunchtime_matching.find_coffeemate(
                app_data_store, user)
            if not matched_user:
                result = "You've matched with everyone, no more coffee for you :("
            else:
                result = "Get coffee with %s!" % matched_user
        else:
            matched_users = lunchtime_matching.find_lunchmates(
                app_data_store, user)
            if len(matched_users):
                result = "Grab lunch with %s!" % ', '.join(matched_users)
            else:
                result = "Not enough people to grab lunch with :("
    else:
        result = "missing required info (user, lunch or coffee)"

    return jsonify({"result": result})