Skip to content

Commit

Permalink
Merge pull request #55 from KOSASIH/deepsource-transform-1b7365f2
Browse files Browse the repository at this point in the history
style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf
  • Loading branch information
KOSASIH committed May 11, 2024
2 parents 466ea63 + 4a19072 commit 6e87d4f
Showing 1 changed file with 25 additions and 20 deletions.
45 changes: 25 additions & 20 deletions tests/test_api.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
# API test file
import os
import tempfile
import shutil
import tempfile
import unittest

from app import app, db
from app.models import User, File
from app.models import File, User
from app.services.encryption import encrypt_file


class TestAPI(unittest.TestCase):
def setUp(self):
app.config['TESTING'] = True
app.config['WTF_CSRF_ENABLED'] = False
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite://'
app.config["TESTING"] = True
app.config["WTF_CSRF_ENABLED"] = False
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite://"
self.client = app.test_client()
db.create_all()

Expand All @@ -21,34 +23,37 @@ def tearDown(self):

def test_upload_file(self):
with tempfile.TemporaryDirectory() as temp_dir:
file_path = os.path.join(temp_dir, 'test_file.txt')
with open(file_path, 'w') as f:
f.write('Test file content')
with open(file_path, 'rb') as f:
file_path = os.path.join(temp_dir, "test_file.txt")
with open(file_path, "w") as f:
f.write("Test file content")
with open(file_path, "rb") as f:
file = f.read()
encrypted_file = encrypt_file(file)
response = self.client.post('/files', data={
'username': 'test_user',
'file': (file_path, 'test_file.txt')
})
response = self.client.post(
"/files",
data={"username": "test_user", "file": (file_path, "test_file.txt")},
)
self.assertEqual(response.status_code, 200)
self.assertTrue(File.query.count() > 0)

def test_download_file(self):
with tempfile.TemporaryDirectory() as temp_dir:
file_path = os.path.join(temp_dir, 'test_file.txt')
with open(file_path, 'w') as f:
f.write('Test file content')
with open(file_path, 'rb') as f:
file_path = os.path.join(temp_dir, "test_file.txt")
with open(file_path, "w") as f:
f.write("Test file content")
with open(file_path, "rb") as f:
file = f.read()
encrypted_file = encrypt_file(file)
ipfs_hash = IPFS.add(encrypted_file)
file = File(name='test_file.txt', content=ipfs_hash, user=User(username='test_user'))
file = File(
name="test_file.txt", content=ipfs_hash, user=User(username="test_user")
)
db.session.add(file)
db.session.commit()
response = self.client.get(f'/files/{ipfs_hash}')
response = self.client.get(f"/files/{ipfs_hash}")
self.assertEqual(response.status_code, 200)
self.assertTrue(response.content)

if __name__ == '__main__':

if __name__ == "__main__":
unittest.main()

0 comments on commit 6e87d4f

Please sign in to comment.