forked from theriverman/django-minio-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request theriverman#18 from theriverman/gh-adding-tests
Adding GH workflow config + Django unit tests
- Loading branch information
Showing
11 changed files
with
184 additions
and
30 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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
name: Django Unit Tests | ||
|
||
on: | ||
push: | ||
branches: | ||
- '**' | ||
|
||
jobs: | ||
job-run-django-app-tests: | ||
name: Deploy DjangoExampleProject and run its integrated tests | ||
runs-on: ubuntu-latest | ||
steps: | ||
# Checkout the repository | ||
- uses: actions/checkout@v2 | ||
# Start the minIO container | ||
- name: Start the minIO container | ||
run: docker run --name miniotest -p 9000:9000 -d minio/minio server /data | ||
# Setup Python | ||
- name: Set up Python 3.8 | ||
uses: actions/setup-python@v1 | ||
with: | ||
python-version: 3.8 | ||
# Install Dependencies | ||
- name: Install pypa/build | ||
run: >- | ||
python -m | ||
pip install | ||
-r | ||
requirements.txt | ||
# Setup Django | ||
- name: Deploy DjangoExampleProject | ||
run: python manage.py migrate | ||
# Run Django Tests | ||
- name: Run Django unit tests | ||
run: python manage.py test |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
name: publish-py-dist-to-pypi | ||
name: PyPI Publish | ||
|
||
on: | ||
push: | ||
|
35 changes: 35 additions & 0 deletions
35
DjangoExampleApplication/migrations/0002_auto_20210313_1049.py
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,35 @@ | ||
# Generated by Django 3.1.3 on 2021-03-13 10:49 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('contenttypes', '0002_remove_content_type_name'), | ||
('DjangoExampleApplication', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='privateattachment', | ||
name='content_type', | ||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='contenttypes.contenttype', verbose_name='Content Type'), | ||
), | ||
migrations.AlterField( | ||
model_name='privateattachment', | ||
name='object_id', | ||
field=models.PositiveIntegerField(blank=True, null=True, verbose_name="Related Object's ID"), | ||
), | ||
migrations.AlterField( | ||
model_name='publicattachment', | ||
name='content_type', | ||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='contenttypes.contenttype', verbose_name='Content Type'), | ||
), | ||
migrations.AlterField( | ||
model_name='publicattachment', | ||
name='object_id', | ||
field=models.PositiveIntegerField(blank=True, null=True, verbose_name="Related Object's ID"), | ||
), | ||
] |
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
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,88 @@ | ||
import time | ||
from pathlib import Path | ||
from django.conf import settings | ||
from django.core.files import File | ||
from django.contrib.contenttypes.models import ContentType | ||
from django.test import TestCase | ||
from django.core.validators import URLValidator | ||
|
||
from DjangoExampleApplication.models import Image, PublicAttachment, PrivateAttachment | ||
|
||
|
||
test_file_path = Path(settings.BASE_DIR) / "DjangoExampleApplication" / "assets" / "audience-868074_1920.jpg" | ||
test_file_size = 339085 | ||
|
||
|
||
class ImageTestCase(TestCase): | ||
obj: Image = None | ||
|
||
def setUp(self): | ||
# Open a test file from disk and upload to minIO as an image | ||
with open(test_file_path, 'rb') as f: | ||
self.obj = Image.objects.create() | ||
self.obj.image.save(name='audience-868074_1920.jpg', content=f) | ||
|
||
def tearDown(self): | ||
# Remove uploaded file from minIO and remove the Image entry from Django's database | ||
self.obj.delete() # deletes from both locations | ||
|
||
def test_url_generation_works(self): | ||
"""Accessing the value of obj.image.url""" | ||
val = URLValidator() | ||
val(self.obj.image.url) # 1st make sure it's an URL | ||
self.assertTrue('audience-868074_1920' in self.obj.image.url) # 2nd make sure our filename matches | ||
|
||
def test_read_image_size(self): | ||
self.assertEqual(self.obj.image.size, test_file_size) | ||
|
||
|
||
class PublicAttachmentTestCase(TestCase): | ||
obj: PublicAttachment = None | ||
filename = f'public_audience-868074_1920_{int(time.time())}.jpg' # adding unix time makes our filename unique | ||
|
||
def setUp(self): | ||
ct = ContentType.objects.get(app_label='auth', model='user') # PublicAttachment is generic so this is needed | ||
with open(test_file_path, 'rb') as f: | ||
# noinspection PyUnresolvedReferences | ||
self.obj = PublicAttachment.objects.create() | ||
self.obj.ct = ct | ||
self.obj.object_id = 1 # we associate this uploaded file to user with pk=1 | ||
self.obj.file.save(name=self.filename, content=File(f), save=True) | ||
|
||
def test_url_generation_works(self): | ||
"""Accessing the value of obj.file.url""" | ||
val = URLValidator() | ||
val(self.obj.file.url) # 1st make sure it's an URL | ||
self.assertTrue('public_audience-868074_1920' in self.obj.file.url) # 2nd make sure our filename matches | ||
|
||
def test_read_file_size(self): | ||
self.assertEqual(self.obj.file_size, test_file_size) | ||
|
||
def test_read_file_name(self): | ||
self.assertEqual(self.obj.file_name, self.filename) | ||
|
||
|
||
class PrivateAttachmentTestCase(TestCase): | ||
obj: PrivateAttachment = None | ||
filename = f'private_audience-868074_1920_{int(time.time())}.jpg' # adding unix time makes our filename unique | ||
|
||
def setUp(self): | ||
ct = ContentType.objects.get(app_label='auth', model='user') # PublicAttachment is generic so this is needed | ||
with open(test_file_path, 'rb') as f: | ||
# noinspection PyUnresolvedReferences | ||
self.obj = PublicAttachment.objects.create() | ||
self.obj.ct = ct | ||
self.obj.object_id = 1 # we associate this uploaded file to user with pk=1 | ||
self.obj.file.save(name=self.filename, content=File(f), save=True) | ||
|
||
def test_url_generation_works(self): | ||
"""Accessing the value of obj.file.url""" | ||
val = URLValidator() | ||
val(self.obj.file.url) # 1st make sure it's an URL | ||
self.assertTrue('private_audience-868074_1920' in self.obj.file.url) # 2nd make sure our filename matches | ||
|
||
def test_read_file_size(self): | ||
self.assertEqual(self.obj.file_size, test_file_size) | ||
|
||
def test_read_file_name(self): | ||
self.assertEqual(self.obj.file_name, self.filename) |
Empty file.
This file was deleted.
Oops, something went wrong.
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
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
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
Django>=2.2.2 | ||
minio>=7.0.0 | ||
minio>=7.0.2 | ||
Pillow | ||
setuptools |
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 |
---|---|---|
|
@@ -25,7 +25,7 @@ | |
author_email='[email protected]', | ||
install_requires=[ | ||
'Django>=2.2.2', | ||
'minio>=7.0.0' | ||
'minio>=7.0.2' | ||
], | ||
classifiers=[ | ||
'Environment :: Web Environment', | ||
|