|
| 1 | +import pytest |
| 2 | +import requests |
1 | 3 | from assets.plugins.generators.test_generator_returns_bytes import TEST_BYTES_STRING |
2 | 4 | from steamship_tests import PLUGINS_PATH, TEST_ASSETS_PATH |
3 | 5 | from steamship_tests.utils.deployables import deploy_plugin |
4 | 6 | from steamship_tests.utils.fixtures import get_steamship_client |
5 | 7 |
|
6 | | -from steamship import Block, File, MimeTypes, PluginInstance |
| 8 | +from steamship import Block, File, MimeTypes, PluginInstance, Steamship |
7 | 9 |
|
8 | 10 |
|
9 | 11 | def test_e2e_generator(): |
@@ -173,3 +175,46 @@ def test_e2e_generate_returning_bytes(): |
173 | 175 | assert persisted_block.file_id is not None |
174 | 176 | persisted_block_content = persisted_block.raw() |
175 | 177 | assert persisted_block_content == TEST_BYTES_STRING.encode("utf-8") |
| 178 | + |
| 179 | + |
| 180 | +@pytest.mark.usefixtures("client") |
| 181 | +def test_generate_block_public_data(client: Steamship): |
| 182 | + client = get_steamship_client() |
| 183 | + plugin_instance = PluginInstance.create(client, plugin_handle="test-image-generator") |
| 184 | + generate_task = plugin_instance.generate( |
| 185 | + text="This won't be used", append_output_to_file=True, make_output_public=True |
| 186 | + ) |
| 187 | + |
| 188 | + blocks = generate_task.wait().blocks |
| 189 | + assert blocks is not None |
| 190 | + assert blocks[0].public_data |
| 191 | + |
| 192 | + # Intentionally no API key |
| 193 | + response = requests.get(blocks[0].raw_data_url) |
| 194 | + |
| 195 | + assert response.text == "PRETEND THIS IS THE DATA OF AN IMAGE" |
| 196 | + assert response.headers["content-type"] == MimeTypes.PNG |
| 197 | + |
| 198 | + |
| 199 | +@pytest.mark.usefixtures("client") |
| 200 | +def test_generate_block_private_data(client: Steamship): |
| 201 | + client = get_steamship_client() |
| 202 | + plugin_instance = PluginInstance.create(client, plugin_handle="test-image-generator") |
| 203 | + generate_task = plugin_instance.generate(text="This won't be used", append_output_to_file=True) |
| 204 | + |
| 205 | + blocks = generate_task.wait().blocks |
| 206 | + assert blocks is not None |
| 207 | + assert not blocks[0].public_data |
| 208 | + |
| 209 | + # Intentionally no API key |
| 210 | + failed_response = requests.get(blocks[0].raw_data_url) |
| 211 | + assert not failed_response.ok |
| 212 | + |
| 213 | + # Should still be able to get with API key |
| 214 | + response = requests.get( |
| 215 | + blocks[0].raw_data_url, |
| 216 | + headers={"Authorization": f"Bearer {client.config.api_key.get_secret_value()}"}, |
| 217 | + ) |
| 218 | + |
| 219 | + assert response.text == "PRETEND THIS IS THE DATA OF AN IMAGE" |
| 220 | + assert response.headers["content-type"] == MimeTypes.PNG |
0 commit comments