-
-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
164 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,7 @@ config.log | |
autobackup.json | ||
Makefile | ||
oshino | ||
|
||
__pycache__/ | ||
.pytest_cache/ | ||
*.py[cod] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
pytest | ||
pytest-redis | ||
requests | ||
factory_boy |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import factory | ||
import os | ||
import zipfile | ||
|
||
from factories.models.archives import Archive | ||
|
||
def generate_file(obj): | ||
logo_path = "/lanraragi/public/img/logo.png" | ||
content_path = "/lanraragi/content/test" | ||
|
||
if not os.path.exists(content_path): | ||
os.makedirs(content_path) | ||
|
||
zip_path = os.path.join(content_path, f"{obj.name}.zip") | ||
|
||
with zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) as zipf: | ||
file_name = os.path.basename(logo_path) | ||
zipf.write(logo_path, file_name) | ||
|
||
return "/home/koyomi"+zip_path | ||
|
||
class ArchiveFactory(factory.Factory): | ||
class Meta: | ||
model = Archive | ||
|
||
name = factory.Faker("first_name") | ||
tags = "date_added:1736124197" | ||
summary = "" | ||
arcsize = "16532135" | ||
file = factory.LazyAttribute(lambda p: '/home/koyomi/lanraragi/content/test/{}.zip'.format(p.name)) | ||
title = factory.LazyAttribute(lambda p: p.name) | ||
isnew = "true" | ||
pagecount = "30" | ||
thumbhash = "ec2a0ca3a3da67a9390889f0910fe494241faa9a" | ||
|
||
@factory.post_generation | ||
def generate_file(obj, create, extracted, **kwargs): | ||
if not create: | ||
return | ||
|
||
logo_path = "/lanraragi/public/img/logo.png" | ||
content_path = "/lanraragi/content/test" | ||
|
||
if not os.path.exists(content_path): | ||
os.makedirs(content_path) | ||
|
||
zip_path = os.path.join(content_path, f"{obj.name}.zip") | ||
|
||
with zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) as zipf: | ||
file_name = os.path.basename(logo_path) | ||
zipf.write(logo_path, file_name) | ||
|
||
return "/home/koyomi"+zip_path |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from dataclasses import dataclass | ||
|
||
@dataclass | ||
class Archive: | ||
name: str | ||
tags: str | ||
summary: str | ||
arcsize: str | ||
file: str | ||
title: str | ||
isnew: str | ||
pagecount: str | ||
thumbhash: str |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import unittest | ||
import requests | ||
import redis | ||
import shutil | ||
from utils.utils import generate_archive_id | ||
from factories.archivefactory import ArchiveFactory | ||
|
||
class ArchiveAPITestCase(unittest.TestCase): | ||
def setUp(self): | ||
self.redis_client = redis.Redis(host='redis', port=6379) | ||
self.archivefactory = ArchiveFactory | ||
|
||
def tearDown(self): | ||
shutil.rmtree('/lanraragi/content/test') | ||
self.redis_client.flushall() | ||
|
||
def test_archives_list(self): | ||
arcid = "28697b96f0ac5858be2614ed10ca47742c9522fd" #generate_archive_id() | ||
archive = self.archivefactory.create() | ||
print(archive.__dict__) | ||
print(arcid) | ||
self.redis_client.hset(arcid, mapping=archive.__dict__) | ||
|
||
response = requests.get('http://lanraragi:3000/api/archives') | ||
data = response.json() | ||
print(data) | ||
|
||
self.assertEqual(response.status_code, 200) | ||
self.assertEqual(data[0]["arcid"], arcid) | ||
self.assertEqual(data[0]["filename"], archive.name) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import uuid | ||
import hashlib | ||
|
||
def generate_archive_id(): | ||
base_id = uuid.uuid4().hex | ||
hashid = hashlib.sha1(base_id.encode()).hexdigest() | ||
|
||
return hashid |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
FROM python:3.8 | ||
|
||
COPY requirements.txt /tests/ | ||
RUN pip install -r /tests/requirements.txt | ||
|
||
WORKDIR /tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
--- | ||
# Docker compose file for dev environments. | ||
services: | ||
lanraragi: | ||
build: | ||
dockerfile: tools/build/docker/Dockerfile-dev | ||
context: ../../.. | ||
volumes: | ||
- ../../../:/home/koyomi/lanraragi | ||
ports: | ||
- "3000:3000" | ||
environment: | ||
- "LRR_REDIS_ADDRESS=redis:6379" | ||
networks: | ||
- lrr | ||
|
||
redis: | ||
image: "docker.io/redis:7" | ||
volumes: | ||
- redis_test_data:/data | ||
networks: | ||
- lrr | ||
|
||
python-tests: | ||
build: | ||
dockerfile: tools/build/docker/Dockerfile-python | ||
context: ../../.. | ||
volumes: | ||
- ../../../tests/python:/tests | ||
- ../../../:/lanraragi | ||
working_dir: /tests | ||
networks: | ||
- lrr | ||
depends_on: | ||
- lanraragi | ||
- redis | ||
command: ["tail", "-F", "Anything"] | ||
|
||
networks: | ||
lrr: | ||
|
||
volumes: | ||
redis_test_data: |