-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added PluginInvalid class model to track invalid plugins
- Loading branch information
suman
committed
Jun 20, 2021
1 parent
743c6e2
commit 53f67f0
Showing
5 changed files
with
128 additions
and
3 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
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,24 @@ | ||
# Generated by Django 2.2.18 on 2021-06-20 10:00 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
import plugins.models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('plugins', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='PluginInvalid', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('validated_version', plugins.models.VersionField(db_index=True, max_length=32, verbose_name='Version')), | ||
('validated_at', models.DateTimeField(auto_now_add=True, verbose_name='Validated at')), | ||
('plugin', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='plugins.Plugin')), | ||
], | ||
), | ||
] |
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,70 @@ | ||
import os | ||
|
||
from django.contrib.auth.models import User | ||
from django.core.files.uploadedfile import InMemoryUploadedFile | ||
from django.test import TestCase, override_settings | ||
|
||
from plugins.models import PluginVersion, Plugin, PluginInvalid | ||
|
||
TESTFILE_DIR = os.path.abspath( | ||
os.path.join(os.path.dirname(__file__), 'testfiles')) | ||
|
||
|
||
@override_settings(MEDIA_ROOT='plugins/tests/testfiles/') | ||
@override_settings(MEDIA_URL='plugins/tests/testfiles/') | ||
class TestPluginInvalidModel(TestCase): | ||
|
||
def setUp(self) -> None: | ||
self.creator = User.objects.create( | ||
username='usertest_creator', | ||
first_name="first_name", | ||
last_name="last_name", | ||
email="[email protected]", | ||
password="passwordtest", | ||
is_active=True) | ||
self.author = User.objects.create( | ||
username='usertest_author', | ||
first_name="author", | ||
last_name="last_name", | ||
email="[email protected]", | ||
password="passwordtest", | ||
is_active=True) | ||
|
||
invalid_plugin = os.path.join( | ||
TESTFILE_DIR, "web_not_exist.zip") | ||
self.invalid_plugin = open(invalid_plugin, 'rb') | ||
|
||
uploaded_zipfile = InMemoryUploadedFile( | ||
self.invalid_plugin, | ||
field_name='tempfile', | ||
name='testfile.zip', | ||
content_type='application/zip', | ||
size=39889, | ||
charset='utf8') | ||
|
||
self.plugin = Plugin.objects.create( | ||
created_by=self.creator, | ||
name='test_plugin', | ||
package_name='test_plugin' | ||
) | ||
|
||
self.version = PluginVersion.objects.create( | ||
plugin=self.plugin, | ||
created_by=self.creator, | ||
version='0.1', | ||
package=uploaded_zipfile, | ||
min_qg_version='3.10', | ||
max_qg_version='3.18' | ||
) | ||
|
||
def tearDown(self) -> None: | ||
self.invalid_plugin.close() | ||
os.remove(self.version.package.url) | ||
|
||
def test_create_PluginInvalid_instance(self): | ||
invalid_plugin = PluginInvalid.objects.create( | ||
plugin=self.plugin, | ||
validated_version=self.plugin.pluginversion_set.get().version | ||
) | ||
self.assertEqual(invalid_plugin.validated_version, '0.1') | ||
self.assertIsNotNone(invalid_plugin.validated_at) |
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