Пример #1
0
 def event(self):
     obj = hikari_test_helpers.unslot_class(
         channel_events.WebhookUpdateEvent)(app=mock.AsyncMock(),
                                            shard=None,
                                            channel_id=123,
                                            guild_id=456)
     return obj
Пример #2
0
 async def test_gc_calls_do_pass(self):
     with hikari_test_helpers.unslot_class(
             buckets.RESTBucketManager)() as mgr:
         mgr.do_gc_pass = mock.Mock()
         mgr.start(0.01, 33)
         try:
             await hikari_test_helpers.idle()
             mgr.do_gc_pass.assert_called_with(33)
         finally:
             mgr.gc_task.cancel()
Пример #3
0
 def test_compile_to_file_calls_compile(self, format, size):
     with mock.patch.object(files, "URL", autospec=files.URL):
         route = hikari_test_helpers.unslot_class(routes.CDNRoute)(
             "/hello/world", {"png", "jpg"}, sizable=True)
         route.compile = mock.Mock(spec_set=route.compile)
         route.compile_to_file("https://blep.com",
                               file_format=format,
                               size=size,
                               boop="oyy lumo",
                               nya="weeb")
         route.compile.assert_called_once_with("https://blep.com",
                                               file_format=format,
                                               size=size,
                                               boop="oyy lumo",
                                               nya="weeb")
Пример #4
0
    async def test_do_gc_pass_any_buckets_that_are_not_empty_are_kept_alive(
            self):
        with hikari_test_helpers.unslot_class(
                buckets.RESTBucketManager)() as mgr:
            bucket = mock.Mock()
            bucket.is_empty = False
            bucket.is_unknown = True
            bucket.reset_at = time.perf_counter()

            mgr.real_hashes_to_buckets["foobar"] = bucket

            mgr.do_gc_pass(0)

            assert "foobar" in mgr.real_hashes_to_buckets
            bucket.close.assert_not_called()
Пример #5
0
    async def test_do_gc_pass_any_buckets_that_are_empty_but_not_rate_limited_and_expired_are_closed(
            self):
        with hikari_test_helpers.unslot_class(
                buckets.RESTBucketManager)() as mgr:
            bucket = mock.Mock()
            bucket.is_empty = True
            bucket.is_unknown = False
            bucket.reset_at = time.perf_counter() - 999999999999999999999999999

            mgr.real_hashes_to_buckets["foobar"] = bucket

            mgr.do_gc_pass(0)

            assert "foobar" not in mgr.real_hashes_to_buckets
            bucket.close.assert_called_once()
Пример #6
0
    def test_compile_to_file_passes_compile_result_to_URL_and_returns_constructed_url(
            self):
        resultant_url_str = "http://blep.com/hello/world/weeb/oyy%20lumo"
        resultant_url = files.URL(
            "http://blep.com/hello/world/weeb/oyy%20lumo")
        with mock.patch.object(files,
                               "URL",
                               autospec=files.URL,
                               return_value=resultant_url) as URL:
            route = hikari_test_helpers.unslot_class(routes.CDNRoute)(
                "/hello/world/{nya}/{boop}", {"png", "jpg"}, sizable=True)
            route.compile = mock.Mock(spec_set=route.compile,
                                      return_value=resultant_url_str)
            result = route.compile_to_file("https://blep.com",
                                           file_format="png",
                                           size=64,
                                           boop="oyy lumo",
                                           nya="weeb")

        URL.assert_called_once_with(resultant_url_str)
        assert result is resultant_url
Пример #7
0
 def event_manager(self, app):
     obj = hikari_test_helpers.unslot_class(
         stateless_event_manager.StatelessEventManagerImpl)(app, object())
     obj.dispatch = mock.AsyncMock()
     return obj
Пример #8
0
 def unslotted_client_type(self):
     return hikari_test_helpers.unslot_class(shard.GatewayShardImpl)
Пример #9
0
 def model(self):
     klass = hikari_test_helpers.unslot_class(applications.Team)
     return hikari_test_helpers.stub_class(klass,
                                           id=123,
                                           icon_hash="ahashicon")
Пример #10
0
 def model(self):
     klass = hikari_test_helpers.unslot_class(applications.Application)
     return hikari_test_helpers.stub_class(klass,
                                           id=123,
                                           icon_hash="ahashicon",
                                           cover_image_hash="ahashcover")