Skip to content

Commit f841bb7

Browse files
🧪 moved create_zip to __init__.py
1 parent fb6981e commit f841bb7

File tree

3 files changed

+32
-23
lines changed

3 files changed

+32
-23
lines changed

tests/__init__.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,30 @@
1+
import io
12
import os
3+
import zipfile
24

35
from dotenv import load_dotenv
46

57
import squarecloud
68

79
load_dotenv()
810
client = squarecloud.Client(os.getenv('KEY'))
11+
12+
13+
def create_zip(include_squarecloud_app: bool = True):
14+
buffer = io.BytesIO()
15+
16+
with zipfile.ZipFile(buffer, 'w') as zip_file:
17+
zip_file.write(
18+
r'tests\test_upload\requirements.txt', 'requirements.txt'
19+
)
20+
21+
zip_file.write(r'tests\test_upload\main.py', 'main.py')
22+
23+
if include_squarecloud_app:
24+
zip_file.write(
25+
r'tests\test_upload\squarecloud.app', 'squarecloud.app'
26+
)
27+
28+
buffer.seek(0)
29+
30+
return buffer.getvalue()

tests/test_request_listeners.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import pytest
2+
import squarecloud
23

34
from squarecloud import Endpoint, File
45
from squarecloud.data import UploadData
56
from squarecloud.http import Response
67

7-
from . import client
8+
from . import client, create_zip
89

910

1011
@pytest.mark.asyncio
@@ -16,8 +17,14 @@ async def test_upload(self):
1617
async def test(response: Response):
1718
assert isinstance(response, Response)
1819

20+
squarecloud.create_config_file(
21+
r'tests\test_upload',
22+
display_name='normal_test',
23+
main='main.py',
24+
memory=100,
25+
)
1926
upload_data: UploadData = await client.upload_app(
20-
File('tests/test_upload/test_normal_upload.zip')
27+
File(create_zip(), filename='file.zip')
2128
)
2229
TestRequestListeners.APP_ID = upload_data.id
2330

tests/test_upload_app.py

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,7 @@
88
from squarecloud import File, errors
99
from squarecloud.data import UploadData
1010

11-
from . import client
12-
13-
14-
def create_zip(include_squarecloud_app: bool = True):
15-
buffer = io.BytesIO()
16-
17-
with zipfile.ZipFile(buffer, 'w') as zip_file:
18-
zip_file.write(
19-
r'tests\test_upload\requirements.txt', 'requirements.txt'
20-
)
21-
22-
zip_file.write(r'tests\test_upload\main.py', 'main.py')
23-
24-
if include_squarecloud_app:
25-
zip_file.write(
26-
r'tests\test_upload\squarecloud.app', 'squarecloud.app'
27-
)
28-
29-
buffer.seek(0)
30-
31-
return buffer.getvalue()
11+
from . import client, create_zip
3212

3313

3414
@pytest.mark.asyncio

0 commit comments

Comments
 (0)