Skip to content

Commit 8164afb

Browse files
🧪 added upload tests
1 parent 0a313ac commit 8164afb

File tree

1 file changed

+175
-0
lines changed

1 file changed

+175
-0
lines changed

tests/test_upload_app.py

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
import asyncio
2+
import io
3+
import zipfile
4+
5+
import pytest
6+
7+
import squarecloud
8+
from squarecloud import File, errors
9+
from squarecloud.data import UploadData
10+
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()
32+
33+
34+
@pytest.mark.asyncio
35+
class TestRequestListeners:
36+
async def test_normal_upload(self):
37+
squarecloud.create_config_file(
38+
r'tests\test_upload',
39+
display_name='normal_test',
40+
main='main.py',
41+
memory=100,
42+
)
43+
await asyncio.sleep(10)
44+
upload_data: UploadData = await client.upload_app(
45+
File(create_zip(), filename='file.zip')
46+
)
47+
await client.delete_app(upload_data.id)
48+
49+
async def test_invalid_main_upload(self):
50+
squarecloud.create_config_file(
51+
r'tests\test_upload',
52+
display_name='invalid_main',
53+
main='index.js',
54+
memory=100,
55+
)
56+
with pytest.raises(errors.InvalidMain):
57+
await asyncio.sleep(10)
58+
upload_data: UploadData = await client.upload_app(
59+
File(create_zip(), filename='file.zip')
60+
)
61+
await client.delete_app(upload_data.id)
62+
63+
async def test_missing_main_upload(self):
64+
squarecloud.create_config_file(
65+
r'tests\test_upload',
66+
display_name='missing_main',
67+
main='',
68+
memory=100,
69+
)
70+
with pytest.raises(errors.MissingMainFile):
71+
await asyncio.sleep(10)
72+
upload_data: UploadData = await client.upload_app(
73+
File(create_zip(), filename='file.zip')
74+
)
75+
await client.delete_app(upload_data.id)
76+
77+
async def test_few_memory_upload(self):
78+
squarecloud.create_config_file(
79+
r'tests\test_upload',
80+
display_name='few_memory_test',
81+
main='main.py',
82+
memory=3999,
83+
)
84+
with pytest.raises(errors.FewMemory):
85+
await asyncio.sleep(10)
86+
upload_data: UploadData = await client.upload_app(
87+
File(create_zip(), filename='file.zip')
88+
)
89+
await client.delete_app(upload_data.id)
90+
91+
async def test_invalid_display_name_upload(self):
92+
squarecloud.create_config_file(
93+
r'tests\test_upload',
94+
display_name='test_' * 200,
95+
main='main.py',
96+
memory=100,
97+
)
98+
with pytest.raises(errors.InvalidDisplayName):
99+
await asyncio.sleep(10)
100+
upload_data: UploadData = await client.upload_app(
101+
File(create_zip(), filename='file.zip')
102+
)
103+
await client.delete_app(upload_data.id)
104+
105+
async def test_missing_display_name_upload(self):
106+
squarecloud.create_config_file(
107+
r'tests\test_upload',
108+
display_name='',
109+
main='main.py',
110+
memory=100,
111+
)
112+
with pytest.raises(errors.MissingDisplayName):
113+
await asyncio.sleep(10)
114+
upload_data: UploadData = await client.upload_app(
115+
File(create_zip(), filename='file.zip')
116+
)
117+
await client.delete_app(upload_data.id)
118+
119+
async def test_bad_memory_upload(self):
120+
squarecloud.create_config_file(
121+
r'tests\test_upload',
122+
display_name='memory_test',
123+
main='main.py',
124+
memory=1,
125+
)
126+
with pytest.raises(errors.BadMemory):
127+
await asyncio.sleep(10)
128+
upload_data: UploadData = await client.upload_app(
129+
File(create_zip(), filename='file.zip')
130+
)
131+
await client.delete_app(upload_data.id)
132+
133+
async def test_missing_memory_upload(self):
134+
squarecloud.create_config_file(
135+
r'tests\test_upload',
136+
display_name='memory_test',
137+
main='main.py',
138+
memory='', # type: ignore
139+
)
140+
with pytest.raises(errors.MissingMemory):
141+
await asyncio.sleep(10)
142+
upload_data: UploadData = await client.upload_app(
143+
File(create_zip(), filename='file.zip')
144+
)
145+
await client.delete_app(upload_data.id)
146+
147+
async def test_invalid_version_upload(self):
148+
squarecloud.create_config_file(
149+
r'tests\test_upload',
150+
display_name='version_test',
151+
main='main.py',
152+
memory=100,
153+
version='invalid_version', # type: ignore
154+
)
155+
with pytest.raises(errors.InvalidVersion):
156+
await asyncio.sleep(10)
157+
upload_data: UploadData = await client.upload_app(
158+
File(create_zip(), filename='file.zip')
159+
)
160+
await client.delete_app(upload_data.id)
161+
162+
async def test_missing_version_upload(self):
163+
squarecloud.create_config_file(
164+
r'tests\test_upload',
165+
display_name='version_test',
166+
main='main.py',
167+
memory=100,
168+
version='', # type: ignore
169+
)
170+
with pytest.raises(errors.MissingVersion):
171+
await asyncio.sleep(10)
172+
upload_data: UploadData = await client.upload_app(
173+
File(create_zip(), filename='file.zip')
174+
)
175+
await client.delete_app(upload_data.id)

0 commit comments

Comments
 (0)