예제 #1
0
 def test_bind_interfaces(self, interfaces):
     interfaces.NotSubClass = type(str("NotSubClass"), (), {})
     interface.not_a_class = None
     api = interface.API(interfaces=interfaces)
     assert isinstance(api["TestInterface"], interface.BaseInterface)
     with pytest.raises(KeyError):
         api["NotSubClass"]
예제 #2
0
 def test_versions(self, interfaces):
     api = interface.API(interfaces=interfaces)
     ifoo = mock.MagicMock()
     ifoo.name = "ifoo"
     ifoo_meths = [mock.Mock(version=1), mock.Mock(version=2)]
     ifoo_meths[0].name = "eggs"
     ifoo_meths[1].name = "spam"
     ifoo.__iter__ = lambda i: iter(ifoo_meths)
     ibar = mock.MagicMock()
     ibar.name = "ibar"
     ibar_meths = [mock.Mock(version=1)]
     ibar_meths[0].name = "method"
     ibar.__iter__ = lambda i: iter(ibar_meths)
     api._interfaces = {
         "ifoo": ifoo,
         "ibar": ibar,
     }
     assert api.versions() == {
         "ifoo": {
             "eggs": 1,
             "spam": 2
         },
         "ibar": {
             "method": 1
         },
     }
예제 #3
0
 def test_request_unknown_format(self, interfaces):
     api = interface.API(interfaces=interfaces)
     api._session = mock.Mock()
     api.format = mock.Mock(format="invalid")
     request = api._session.request
     raw_response = request.return_value
     with pytest.raises(ValueError):
         api.request("GET", "interface", "method", 1)
예제 #4
0
 def test_iter(self, interfaces):
     api = interface.API(interfaces=interfaces)
     foo = object()
     bar = object()
     api._interfaces = {"foo": foo, "bar": bar}
     list_ = list(api)
     assert len(list_) == 2
     assert foo in list_
     assert bar in list_
예제 #5
0
 def test_inherit_interfaces(self, monkeypatch):
     monkeypatch.setattr(interface, "make_interfaces", mock.Mock())
     monkeypatch.setattr(interface.API, "_bind_interfaces", mock.Mock())
     monkeypatch.setattr(interface.API, "request", mock.Mock())
     interfaces = types.ModuleType(str("test"))
     api = interface.API(interfaces=interfaces)
     assert api._interfaces_module == interfaces
     assert not interface.make_interfaces.called
     assert api._bind_interfaces.called
     assert not api.request.called
예제 #6
0
 def test_formats(self, monkeypatch, format_name, format_func):
     monkeypatch.setattr(interface, "make_interfaces", mock.Mock())
     monkeypatch.setattr(interface.API, "_bind_interfaces", mock.Mock())
     monkeypatch.setattr(interface.API, "request", mock.Mock())
     api = interface.API(format=format_name)
     assert api.format is format_func
     assert interface.make_interfaces.called
     assert (interface.make_interfaces.call_args[0][0] is
             api.request.return_value)
     assert interface.make_interfaces.call_args[0][1] == {}
     assert api.request.called
     assert api.request.call_args[0][0] == "GET"
     assert api.request.call_args[0][1] == "ISteamWebAPIUtil"
     assert api.request.call_args[0][2] == "GetSupportedAPIList"
     assert api.request.call_args[0][3] == 1
     assert api.request.call_args[1]["format"] is interface.json_format
     assert api._bind_interfaces.called
예제 #7
0
 def test_request(self, interfaces):
     api = interface.API(interfaces=interfaces)
     api._session = mock.Mock()
     api.format = mock.Mock(format="json")
     request = api._session.request
     raw_response = request.return_value
     response = api.request("GET",
                            "interface",
                            "method",
                            1,
                            params={
                                "key": "test",
                                "foo": "bar"
                            })
     assert api.format.called
     assert api.format.call_args[0][0] is raw_response.text
     assert request.call_args[0][0] == "GET"
     assert request.call_args[0][1] == api.api_root + "interface/method/v1/"
     assert request.call_args[0][2] == {"format": "json", "foo": "bar"}
예제 #8
0
 def test_getitem(self):
     api = interface.API(interfaces=types.ModuleType(str("test")))
     api._interfaces = mock.MagicMock()
     assert api["Test"] is api._interfaces.__getitem__.return_value
     assert api._interfaces.__getitem__.call_args[0][0] == "Test"
예제 #9
0
 async def initialize(self):
     """Should be called straight after cog instantiation."""
     self.apikeys = await self.bot.db.api_tokens.get_raw("steam", default={"web": None})
     self.steam = interface.API(key=self.apikeys["web"])