-
Notifications
You must be signed in to change notification settings - Fork 4
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
1 parent
106e0d9
commit 1f16809
Showing
10 changed files
with
2,315 additions
and
5 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
Empty file.
1,054 changes: 1,054 additions & 0 deletions
1,054
moonsheep/importers/tests/http_listings/index_dirs.html
Large diffs are not rendered by default.
Oops, something went wrong.
1,108 changes: 1,108 additions & 0 deletions
1,108
moonsheep/importers/tests/http_listings/index_files.html
Large diffs are not rendered by default.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import os | ||
import unittest | ||
|
||
from moonsheep.importers import HttpDocumentImporter | ||
from django.core import management | ||
|
||
class TestHttpImporter(unittest.TestCase): | ||
@staticmethod | ||
def load_file(path: str): | ||
path = os.path.join(os.path.dirname(os.path.abspath(__file__)), path) | ||
with open(path, 'r') as content_file: | ||
return content_file.read() | ||
|
||
def test_load_dirs(self): | ||
print(__file__) | ||
print(os.path.abspath(__file__)) | ||
content = self.load_file('http_listings/index_dirs.html') | ||
entries = HttpDocumentImporter.listdir(content) | ||
|
||
self.assertIn("http://debian.mirror.ac.za/debian/pool/main/t/t-code/", entries) | ||
self.assertIn("http://debian.mirror.ac.za/debian/pool/main/t/tzsetup/", entries) | ||
self.assertIn("http://debian.mirror.ac.za/debian/pool/main/t/tryton-modules-stock-supply-production/", entries) | ||
|
||
self.assertNotIn("http://debian.mirror.ac.za/debian/pool/main/", entries, "Parent dir should not be returned") | ||
self.assertNotIn("http://debian.mirror.ac.za/debian/pool/main", entries, "Parent dir should not be returned") | ||
self.assertNotIn("http://debian.mirror.ac.za/debian/pool/main/t/", entries, | ||
"Current dir should not be returned") | ||
self.assertNotIn("http://debian.mirror.ac.za/debian/pool/main/t", entries, "Current dir should not be returned") | ||
|
||
def load_files(self): | ||
content = self.load_file('http_listings/index_files.html') | ||
entries = HttpDocumentImporter.listdir(content) | ||
|
||
# Encoded url | ||
self.assertIn( | ||
"http://debian.mirror.ac.za/debian/pool/main/t/tasksel/task-albanian-desktop_3.31%2Bdeb8u1_all.deb", | ||
entries) | ||
self.assertIn("http://debian.mirror.ac.za/debian/pool/main/t/tasksel/tasksel_3.56_all.deb", entries) | ||
|
||
self.assertNotIn("http://debian.mirror.ac.za/debian/pool/main/t/", entries, "Parent dir should not be returned") | ||
self.assertNotIn("http://debian.mirror.ac.za/debian/pool/main/t", entries, "Parent dir should not be returned") | ||
self.assertNotIn("http://debian.mirror.ac.za/debian/pool/main/t/taskel", entries, | ||
"Current dir should not be returned") | ||
self.assertNotIn("http://debian.mirror.ac.za/debian/pool/main/t/taskel", entries, | ||
"Current dir should not be returned") | ||
|
||
|
||
# class TestHttpImporterCommand(unittest.TestCase): | ||
# # TODO @patch and assert HttpDocumentImporter.find_urls | ||
# def host_with_multiple_paths(self): | ||
# management.call_command('moonsheep_import_http', '-W -h http://user@host/root dir1 dir2/file1') | ||
# # TODO then what? | ||
# | ||
# | ||
# def one_path(self): | ||
# management.call_command('moonsheep_import_http', 'http://user@host/root/dir1') | ||
# | ||
# | ||
# def file_pattern(self): | ||
# management.call_command('moonsheep_import_http', 'http://user@host/root/dir1 -f *.pdf') | ||
|
||
|
||
|
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,27 @@ | ||
from django.core.management.base import BaseCommand, CommandError | ||
|
||
from moonsheep.importers.http import HttpDocumentImporter | ||
|
||
|
||
class Command(BaseCommand): | ||
help = 'Imports documents published on http server with Index List enabled' | ||
|
||
def add_arguments(self, parser): | ||
parser.add_argument('paths', type=str, nargs='+', metavar='path', help='Paths to be imported') | ||
# parser.add_argument('-W', dest='ask_for_password', type=bool, nargs='?', default=False, const=True, | ||
help='Ask for password instead of specifying it on the command line') | ||
parser.add_argument('--host', dest='host', type=str, help="Host to be used if multiple paths are provided") | ||
parser.add_argument('-f', dest='pattern', type=str, | ||
help="*-wildcarded pattern of the file names to be included, ie. -f *.pdf") | ||
parser.add_argument('--dry-run', dest='dry_run', type=bool, nargs='?', default=False, const=True, | ||
help='Dry run to see what would get imported without actually importing it') | ||
|
||
def handle(self, *args, **options): | ||
host = options['host'] | ||
# TODO if not host | ||
paths = options['paths'] | ||
# TODO dry_run | ||
|
||
for path in HttpDocumentImporter.find_urls(host=host, paths=paths, pattern=options['pattern']): | ||
print(f"\t{path}") | ||
# TODO actually import them into Moonsheep unless dry_run |
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 |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
|
||
INSTALLED_APPS = [ | ||
"moonsheep", | ||
'django.contrib.auth', | ||
'django.contrib.contenttypes', | ||
] | ||
|
||
DATABASES = { | ||
|
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,3 @@ | ||
[pytest] | ||
DJANGO_SETTINGS_MODULE = moonsheep.tests.test_settings | ||
python_files = tests.py test_*.py *_tests.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