Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 34e92058 authored by Robin Tissot's avatar Robin Tissot
Browse files

Update failing tests.

parent 0cd3fa71
No related branches found
No related tags found
No related merge requests found
......@@ -73,7 +73,7 @@ class PartViewSetTestCase(TestCase):
self.client.force_login(self.user)
uri = reverse('api:part-list',
kwargs={'document_pk': self.part.document.pk})
with self.assertNumQueries(5):
with self.assertNumQueries(7):
img = self.factory.make_image_file()
resp = self.client.post(uri, {
'image': SimpleUploadedFile(
......
......@@ -3,7 +3,7 @@ from ftplib import FTP
from django.conf import settings
from django.core.management.base import BaseCommand, CommandError
from core.models import Document, DocumentPart, document_images_path
from core.models import Document, DocumentPart, Line, Transcription, LineTranscription, document_images_path
class Command(BaseCommand):
......@@ -16,35 +16,53 @@ class Command(BaseCommand):
parser.add_argument('-u', '--user', type=str)
parser.add_argument('-p', '--password', type=str)
parser.add_argument('-l', '--limit', type=int, default=0)
parser.add_argument('-c', '--csv', type=str)
def grab(self, ftp, filename):
print('Fetching %s' % filename)
fpath = 'documents/%d/%s' % (self.document.pk, filename)
fullpath = os.path.join(settings.MEDIA_ROOT, fpath)
if not os.path.exists(os.path.dirname(fullpath)):
try:
os.makedirs(os.path.dirname(fullpath))
except OSError as exc:
if exc.errno != errno.EEXIST:
raise
with open(fullpath, 'wb+') as fh:
ftp.retrbinary('RETR ' + filename, fh.write, 1024)
part = DocumentPart.objects.create(image=fpath, document=self.document)
return part
def handle(self, *args, **options):
document = Document.objects.get(pk=options['document_id'])
self.document = Document.objects.get(pk=options['document_id'])
# ftp://149.202.76.5/Latin_manuscripts/Bamberg78new/Msc.Class.78/
ftp = FTP(options['host'])
ftp.login(user=options['user'], passwd=options['password'])
ftp.cwd(options['dir'])
files = []
if options['csv']:
file_ = None
trans = Transcription.objects.create(name='CSV import', document=self.document)
part = None
with open(options['csv'], 'r') as fh:
for line in fh.readlines()[1:]:
p,rc,gtc,gtl,x1,y1,x2,y2,x3,y3,x4,y4,sp,fn,ld,fr,sr,cor = line.split('\t')
if fn != file_:
part = self.grab(ftp, fn.replace('.jpg', '.tif'))
file_ = fn
l = Line.objects.create(document_part=part, box=(x1,y1,x2,y4))
LineTranscription.objects.create(line=l, transcription=trans, content=cor)
else:
files = []
def list_img(filename):
if os.path.splitext(filename)[1] in ['.tif', '.jpg', '.jpeg', '.png']:
files.append(filename.split()[-1])
def list_img(filename):
if os.path.splitext(filename)[1] in ['.tif', '.jpg', '.jpeg', '.png']:
files.append(filename.split()[-1])
ftp.dir(lambda a: list_img(a))
for filename in files[:options['limit']]:
self.grab(ftp, filename)
ftp.dir(lambda a: list_img(a))
for filename in files[:options['limit']]:
print('Fetching %s' % filename)
fpath = 'documents/%d/%s' % (document.pk, filename)
fullpath = os.path.join(settings.MEDIA_ROOT, fpath)
if not os.path.exists(os.path.dirname(fullpath)):
try:
os.makedirs(os.path.dirname(fullpath))
except OSError as exc:
if exc.errno != errno.EEXIST:
raise
with open(fullpath, 'wb+') as fh:
ftp.retrbinary('RETR ' + filename, fh.write, 1024)
DocumentPart.objects.create(image=fpath, document=document)
ftp.quit()
......@@ -15,9 +15,10 @@ class TasksTestCase(TestCase):
factory.make_part(document=self.part.document)
def test_workflow(self):
self.assertEqual(self.part.workflow_state,
self.part.WORKFLOW_STATE_CREATED)
self.part.compress()
# done automatically when creating
# self.assertEqual(self.part.workflow_state,
# self.part.WORKFLOW_STATE_CREATED)
# self.part.compress()
self.assertEqual(self.part.workflow_state,
self.part.WORKFLOW_STATE_COMPRESSED)
......@@ -36,7 +37,6 @@ class TasksTestCase(TestCase):
self.assertEqual(self.part.workflow_state,
self.part.WORKFLOW_STATE_TRANSCRIBING)
@override_settings(CELERY_TASK_ALWAYS_EAGER=True, USE_CELERY=False)
def test_post(self):
self.client.force_login(self.part.document.owner)
uri = reverse('document-parts-process', kwargs={
......
from escriptorium.settings import *
DEBUG=True
DATABASES = {
'default': {
'ENGINE': os.getenv('SQL_ENGINE', 'django.db.backends.postgresql'),
'NAME': os.getenv('SQL_DATABASE', 'escriptorium'),
}
}
INSTALLED_APPS += ['debug_toolbar', 'django_extensions']
MIDDLEWARE += ['debug_toolbar.middleware.DebugToolbarMiddleware',]
INTERNAL_IPS = ['127.0.0.1',]
# only needed in developement
EMAIL_BACKEND = 'django.core.mail.backends.filebased.EmailBackend'
EMAIL_FILE_PATH = '/tmp/django-emails'
DEBUG_TOOLBAR_PANELS = [
'debug_toolbar.panels.versions.VersionsPanel',
'debug_toolbar.panels.timer.TimerPanel',
'debug_toolbar.panels.settings.SettingsPanel',
'debug_toolbar.panels.headers.HeadersPanel',
'debug_toolbar.panels.request.RequestPanel',
'debug_toolbar.panels.sql.SQLPanel',
# 'debug_toolbar.panels.staticfiles.StaticFilesPanel',
'debug_toolbar.panels.templates.TemplatesPanel',
'debug_toolbar.panels.cache.CachePanel',
'debug_toolbar.panels.signals.SignalsPanel',
'debug_toolbar.panels.logging.LoggingPanel',
'debug_toolbar.panels.redirects.RedirectsPanel',
]
# USE_CELERY = False
......@@ -194,12 +194,4 @@ REST_FRAMEWORK = {
}
if 'test' in sys.argv:
class DisableMigrations(object):
def __contains__(self, item):
return True
def __getitem__(self, item):
return None
MIGRATION_MODULES = DisableMigrations()
from escriptorium.test_settings import *
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment