def test_put_with_conversion_uses_return_value(self): def convert(_): return "yeah, i got called" mapping = data_binding.StringMapBuilder() mapping.put("blep", "meow", conversion=convert) assert dict(mapping) == {"blep": "yeah, i got called"}
def test_put_with_conversion_passes_raw_input_to_converter(self): mapping = data_binding.StringMapBuilder() convert = mock.Mock() expect = object() mapping.put("yaskjgakljglak", expect, conversion=convert) convert.assert_called_once_with(expect)
def compile(self, **kwargs: typing.Any) -> CompiledRoute: """Generate a formatted `CompiledRoute` for this route. This takes into account any URL parameters that have been passed. Parameters ---------- **kwargs : typing.Any Any parameters to interpolate into the route path. Returns ------- CompiledRoute The compiled route. """ data = data_binding.StringMapBuilder() for k, v in kwargs.items(): data.put(k, v) return CompiledRoute( route=self, compiled_path=self.path_template.format_map(data), major_param_hash=data[self.major_param] if self.major_param is not None else "-", )
def test_put_py_singleton_conversion_runs_before_check(self): def convert(_): return True mapping = data_binding.StringMapBuilder() mapping.put("im hungry", "yo", conversion=convert) assert dict(mapping) == {"im hungry": "true"}
def test_duplicate_puts_stores_values_as_sequence(self): m1 = mock.Mock() m2 = mock.Mock() mapping = data_binding.StringMapBuilder() mapping.put("foo", m1) mapping.put("foo", m2) assert mapping.getall("foo") == [m1.__str__(), m2.__str__()] assert list(mapping.keys()) == ["foo", "foo"]
async def _next_chunk( self ) -> typing.Optional[typing.Generator[users.User, typing.Any, None]]: query = data_binding.StringMapBuilder() query.put("after", self._first_id) query.put("limit", 100) raw_chunk = await self._request_call(compiled_route=self._route, query=query) chunk = typing.cast(data_binding.JSONArray, raw_chunk) if not chunk: return None self._first_id = chunk[-1]["id"] return (self._entity_factory.deserialize_user(u) for u in chunk)
async def __anext__(self) -> audit_logs.AuditLog: query = data_binding.StringMapBuilder() query.put("limit", 100) query.put("user_id", self._user) query.put("event_type", self._action_type) query.put("before", self._first_id) raw_response = await self._request_call(compiled_route=self._route, query=query) response = typing.cast(data_binding.JSONObject, raw_response) if not response["audit_log_entries"]: raise StopAsyncIteration log = self._entity_factory.deserialize_audit_log(response) self._first_id = str(min(log.entries.keys())) return log
async def _next_chunk( self ) -> typing.Optional[typing.Generator[applications.OwnGuild, typing.Any, None]]: query = data_binding.StringMapBuilder() query.put("before" if self._newest_first else "after", self._first_id) query.put("limit", 100) raw_chunk = await self._request_call(compiled_route=self._route, query=query) chunk = typing.cast(data_binding.JSONArray, raw_chunk) if not chunk: return None self._first_id = chunk[-1]["id"] return (self._entity_factory.deserialize_own_guild(g) for g in chunk)
async def _next_chunk( self ) -> typing.Optional[typing.Generator[messages.Message, typing.Any, None]]: query = data_binding.StringMapBuilder() query.put(self._direction, self._first_id) query.put("limit", 100) raw_chunk = await self._request_call(compiled_route=self._route, query=query) chunk = typing.cast(data_binding.JSONArray, raw_chunk) if not chunk: return None if self._direction == "after": chunk.reverse() self._first_id = chunk[-1]["id"] return (self._entity_factory.deserialize_message(m) for m in chunk)
def test_put_int(self): mapping = data_binding.StringMapBuilder() mapping.put("yeet", 420_69) assert dict(mapping) == {"yeet": "42069"}
def test_is_multidict(self): assert isinstance(data_binding.StringMapBuilder(), multidict.MultiDict)
def test_starts_empty(self): mapping = data_binding.StringMapBuilder() assert mapping == {}
def test_put_undefined(self): mapping = data_binding.StringMapBuilder() mapping.put("foo", undefined.UNDEFINED) assert dict(mapping) == {}
def test_put_general_value_casts_to_str(self): m = mock.Mock() mapping = data_binding.StringMapBuilder() mapping.put("foo", m) assert dict(mapping) == {"foo": m.__str__()}
def test_put_py_singleton(self, name, input_val, expect): mapping = data_binding.StringMapBuilder() mapping.put(name, input_val) assert dict(mapping) == {name: expect}
def test_is_mapping(self): assert isinstance(data_binding.StringMapBuilder(), typing.Mapping)
def test_put_Unique(self): mapping = data_binding.StringMapBuilder() mapping.put("myunique", MyUnique(123)) assert dict(mapping) == {"myunique": "123"}