summaryrefslogtreecommitdiff
path: root/tests/gamelocker_test.py
blob: f142ea8af32ee158f2b9faae9305c905be31d319 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/usr/bin/python

import os
import pytest
import requests
import gamelocker
import datetime

class TestGamelocker:
    @pytest.fixture
    def api(self):
        return gamelocker.Gamelocker(os.environ["GAMELOCKER_APIKEY"]).Vainglory()

    def test_req(self, api):
        with pytest.raises(requests.exceptions.HTTPError):
            assert api._req("foobar")
        assert type(api._req("status")) is dict

        assert api.status()["data"]["attributes"]["version"]

    def test_map(self):
        assert gamelocker.datatypes.modulemap()["match"] is gamelocker.datatypes.Match

    def test_match(self, api):
        match = api.match("2245af82-b66c-11e7-95d2-0667892d829e")
        assert isinstance(match.gameMode, str)
        assert isinstance(match.rosters[0], gamelocker.datatypes.Roster)
        assert isinstance(match.rosters[0].participants[0], gamelocker.datatypes.Participant)
        assert isinstance(match.rosters[0].participants[0].player, gamelocker.datatypes.Player)
        assert isinstance(match.rosters[0].participants[0].player.name, str)
        assert isinstance(match.rosters[0].participants[0].actor, str)
        assert isinstance(match.rosters[0].stats["acesEarned"], int)
        assert isinstance(match.rosters[0].participants[0].stats["items"][0], str)

    def test_matches(self, api):
        matches = api.matches(params={
           "filter[createdAt-start]": "2017-09-12T00:00:00Z",
           "filter[createdAt-end]": "2017-09-26T00:00:00Z",
           "filter[playerNames]": "Kraken"
        })
        assert len(matches) > 0
        assert isinstance(matches[0], gamelocker.datatypes.Match)
        assert matches[0].duration > 0

    def test_asset(self, api):
        match = api.match(elid="1b178a8c-b66c-11e7-9757-0206eb3a2f5b",
                          region="eu")
        assert isinstance(match.assets[0].url, str)

    def test_region(self, api):
        assert len(api.matches(region="na",
                               params={
                                   "filter[createdAt-start]": "2017-09-12T00:00:00Z",
                                   "filter[createdAt-end]": "2017-09-26T00:00:00Z",
                                   "filter[playerNames]": "Kraken"
                               })) > 0
        assert len(api.matches(region="eu",
                               params={
                                   "filter[createdAt-start]": "2017-09-12T00:00:00Z",
                                   "filter[createdAt-end]": "2017-09-26T00:00:00Z",
                                   "filter[playerNames]": "shutterfly"
                               })) > 0
        assert len(api.matches(region="sg",
                               params={
                                   "filter[createdAt-start]": "2017-09-12T00:00:00Z",
                                   "filter[createdAt-end]": "2017-09-26T00:00:00Z",
                                   "filter[playerNames]": "idmonfish"
                               })) > 0

    def test_matchesfilters(self, api):
        matches1 = api.matches({
            "filter[createdAt-start]": "2017-09-01T00:00:00Z",
            "filter[createdAt-end]": "2017-09-28T00:00:00Z",
            "filter[playerNames]": "Kraken",
            "page[limit]": 3
        })
        assert len(matches1) == 3
        matches2 = api.matches({
            "filter[createdAt-start]": "2017-09-01T00:00:00Z",
            "filter[createdAt-end]": "2017-09-28T00:00:00Z",
            "filter[playerNames]": "Kraken",
            "page[limit]": 3,
            "page[offset]": 1
        })

        commons = 0  # 3 matches each, offset 1 -> 2 overlap
        for match1 in matches1:
            for match2 in matches2:
                if match1.id == match2.id:
                    commons += 1
        assert commons == 2

        assert len(api.matches(region="eu", params={
            "filter[createdAt-start]": "2017-09-01T00:00:00Z",
            "filter[createdAt-end]": "2017-09-28T00:00:00Z",
            "filter[playerNames]": "shutterfly",
            "page[limit]": 9
        })) == 9

        def fromiso(s):
            return datetime.datetime.strptime(s, "%Y-%m-%dT%H:%M:%SZ")

        start = "2017-09-01T02:25:00Z"
        end = "2017-09-28T02:30:00Z"
        matches = api.matches({
            "filter[playerNames]": "Kraken",
            "filter[createdAt-start]": start,
            "filter[createdAt-end]": end
        })
        for match in matches:
            assert fromiso(end) >= fromiso(match.createdAt) >= fromiso(start)

        nick = "MMotooks123"
        matches = api.matches({
            "filter[createdAt-start]": "2017-09-01T00:00:00Z",
            "filter[createdAt-end]": "2017-09-28T00:00:00Z",
            "page[limit]": 5,
            "filter[playerNames]": nick
        })
        for match in matches:
            success = False
            for roster in match.rosters:
                for participant in roster.participants:
                    if participant.player.name == nick:
                        success = True
                        break
            assert success

        team = "3TB3"
        matches = api.matches(region="na", params={
            "filter[createdAt-start]": "2017-09-01T00:00:00Z",
            "filter[createdAt-end]": "2017-09-28T00:00:00Z",
            "page[limit]": 5,
            "filter[teamNames]": team
        })
        for match in matches:
            success = False
            for roster in match.rosters:
                if roster.team:
                    if roster.team.name == team:
                        success = True
                        break
            assert success

    def test_player(self, api):
        assert api.player("57342aac-7ff5-11e5-98bf-0628b69bf6d1").name == "oldchoas"
        assert "lossStreak" in api.player("57342aac-7ff5-11e5-98bf-0628b69bf6d1").stats