Beispiel #1
0
    def test_make_large_image_url_when_no_hash(self):
        asset = presences.ActivityAssets(
            application_id=None,
            large_image=None,
            large_text=None,
            small_image=None,
            small_text=None,
        )

        assert asset.make_large_image_url() is None
Beispiel #2
0
    def test_make_small_image_url_when_unknown_dynamic_url(self):
        asset = presences.ActivityAssets(
            application_id=None,
            large_image=None,
            large_text=None,
            small_image="meow:nyaa",
            small_text=None,
        )

        with pytest.raises(RuntimeError, match="Unknown asset type"):
            asset.make_small_image_url()
Beispiel #3
0
    def test_make_small_image_url_when_dynamic_url(self, asset_hash: str,
                                                   expected: str):
        asset = presences.ActivityAssets(
            application_id=None,
            large_image=None,
            large_text=None,
            small_image=asset_hash,
            small_text=None,
        )

        assert asset.make_small_image_url() == files.URL(expected)
Beispiel #4
0
    def test_large_image_url_property(self):
        asset = presences.ActivityAssets(
            application_id=None,
            large_image=None,
            large_text=None,
            small_image=None,
            small_text=None,
        )

        with mock.patch.object(presences.ActivityAssets,
                               "make_large_image_url") as make_large_image_url:
            result = asset.large_image_url

        assert result is make_large_image_url.return_value
        make_large_image_url.assert_called_once_with()
Beispiel #5
0
    def test_large_image_url_property_when_runtime_error(self):
        asset = presences.ActivityAssets(
            application_id=None,
            large_image=None,
            large_text=None,
            small_image=None,
            small_text=None,
        )

        with mock.patch.object(
                presences.ActivityAssets,
                "make_large_image_url",
                side_effect=RuntimeError) as make_large_image_url:
            result = asset.large_image_url

        assert result is None
        make_large_image_url.assert_called_once_with()
Beispiel #6
0
    def test_make_large_image_url(self):
        asset = presences.ActivityAssets(
            application_id=45123123,
            large_image="541sdfasdasd",
            large_text=None,
            small_image=None,
            small_text=None,
        )

        with mock.patch.object(routes, "CDN_APPLICATION_ASSET") as route:
            assert asset.make_large_image_url(
                ext="fa", size=3121) is route.compile_to_file.return_value

        route.compile_to_file.assert_called_once_with(
            urls.CDN_URL,
            application_id=45123123,
            hash="541sdfasdasd",
            size=3121,
            file_format="fa",
        )
Beispiel #7
0
    def test_make_small_image_url(self):
        asset = presences.ActivityAssets(
            application_id=123321,
            large_image=None,
            large_text=None,
            small_image="aseqwsdas",
            small_text=None,
        )

        with mock.patch.object(routes, "CDN_APPLICATION_ASSET") as route:
            assert asset.make_small_image_url(
                ext="eat", size=123312) is route.compile_to_file.return_value

        route.compile_to_file.assert_called_once_with(
            urls.CDN_URL,
            application_id=123321,
            hash="aseqwsdas",
            size=123312,
            file_format="eat",
        )