Exemple #1
0
def get_record():
    id = int(request.values.get('id'))
    pic_file = db.get_pic_file(id)
    if not pic_file:
        return json.dumps({"status": -1})
    folder, name = parse_file(pic_file)
    return json.dumps(dict(status=0, id=id, folder=folder, name=name))
Exemple #2
0
def test_multiple_valid_customers():
    file_path = TEST_INPUT % "multiple_valid_customers"
    main(file_path, TEST_OUTPUT_DIR)

    result = parse_file(TEST_OUTPUT_DIR)
    expected = 5
    assert len(result) == expected

    for c in result:
        assert c['distance_km'] <= MAX_RADIUS_KM

    expected = [{
        "user_id": 4,
        "name": "Ian Kehoe",
        "distance_km": 10.56693628851016
    }, {
        "user_id": 6,
        "name": "Theresa Enright",
        "distance_km": 24.085360018691215
    }, {
        "user_id": 13,
        "name": "Olive Ahearn",
        "distance_km": 62.23170226288675
    }, {
        "user_id": 17,
        "name": "Patricia Cahill",
        "distance_km": 96.07859923628895
    }, {
        "user_id": 26,
        "name": "Stephen McArdle",
        "distance_km": 98.87459926457565
    }]
    assert result == expected
    os.remove(TEST_OUTPUT_DIR)
def test_output_type():
    result = parse_file('example.txt')

    assert isinstance(result, List)

    if result:
        assert isinstance(result[0], dict)
    else:
        assert result == []
Exemple #4
0
def test_no_customers():
    file_path = TEST_INPUT % "no_customers"
    main(file_path, TEST_OUTPUT_DIR)

    result = parse_file(TEST_OUTPUT_DIR)
    expected = 0
    assert len(result) == expected

    expected = []
    assert result == expected
    os.remove(TEST_OUTPUT_DIR)
Exemple #5
0
def test_one_valid_customer():
    file_path = TEST_INPUT % "one_valid_customer"
    main(file_path, TEST_OUTPUT_DIR)

    result = parse_file(TEST_OUTPUT_DIR)
    expected = 1
    assert len(result) == expected

    assert result[0]['distance_km'] <= MAX_RADIUS_KM

    expected = {
        "user_id": 4,
        "name": "Ian Kehoe",
        "distance_km": 10.56693628851016
    }
    assert result[0] == expected
    os.remove(TEST_OUTPUT_DIR)
Exemple #6
0
    def test_parse_file(self):
        tournament = parse_file(self.file_path)
        self.assertEqual(len(tournament.matches), 2)

        match1 = tournament.get_match(1)
        match2 = tournament.get_match(2)

        # match's set score
        self.assertEqual(match1.get_set(1).get_winner(), match1.player2)
        self.assertEqual(match1.get_set(2).get_winner(), match1.player2)

        self.assertEqual(match1.set_score1, 0)
        self.assertEqual(match1.set_score2, 2)

        # winner
        self.assertEqual(match2.get_set(1).get_winner(), match2.player2)
        self.assertEqual(match2.get_set(2).get_winner(), match2.player1)
        self.assertEqual(match2.get_set(3).get_winner(), match2.player2)

        # set result
        self.assertEqual(match2.set_score1, 1)
        self.assertEqual(match2.set_score2, 2)
        self.assertEqual(match1.set_count, 2)
        self.assertEqual(str(match1.get_set(1)), "0 - 6")
        self.assertEqual(str(match1.get_set(2)), "0 - 6")
        self.assertEqual(match1.get_set(3), None)

        # match result
        self.assertEqual(str(match1), "Person A vs Person B: 0 - 6, 0 - 6")
        self.assertEqual(match1.get_winner(), "Person B")
        self.assertEqual(match2.set_count, 3)
        self.assertEqual(str(match2), "Person A vs Person C: 6 - 7, 6 - 0, 6 - 8")
        self.assertTrue(match2.get_set(3).is_deciding)  # deciding set
        self.assertEqual(match2.get_set(4), None)

        # get player point
        self.assertEqual(match1.get_player_point(match1.player1), (0, 48))
        self.assertEqual(match1.get_player_point(match1.player2), (48, 0))
        self.assertEqual(tournament.get_player_point(match1.player1), (80, 114))
        self.assertEqual(tournament.get_player_point(match2.player2), (66, 80))
        self.assertEqual(tournament.get_player_point('Not exist player'), (None, None))
 def test_userStory42(self):
     r = parse_file('us40-test.ged')
     expect = []
     self.assertEqual(expect, userStory42(r))