Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
website
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Video AG Infrastruktur
website
Commits
3214cd4b
Unverified
Commit
3214cd4b
authored
6 years ago
by
Andreas Valder
Browse files
Options
Downloads
Patches
Plain Diff
added tests for the sorter
parent
9259d4e5
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
jobs.py
+8
-0
8 additions, 0 deletions
jobs.py
sorter.py
+4
-10
4 additions, 10 deletions
sorter.py
tests/test_sorter.py
+40
-3
40 additions, 3 deletions
tests/test_sorter.py
with
52 additions
and
13 deletions
jobs.py
+
8
−
0
View file @
3214cd4b
...
...
@@ -114,3 +114,11 @@ def jobs_schedule(hostname):
return
'
no jobs
'
,
503
return
Response
(
json
.
dumps
(
job
,
default
=
date_json_handler
),
mimetype
=
'
application/json
'
)
@app.route
(
'
/internal/jobs/add/thumbnail
'
,
methods
=
[
'
GET
'
,
'
POST
'
])
@mod_required
@csrf_protect
@handle_errors
(
'
jobs_overview
'
,
'
Zu dieser Veranstaltung existieren keine Videos!
'
,
404
,
IndexError
)
def
add_thumbnail_job
():
schedule_thumbnail
(
request
.
values
[
'
lectureid
'
])
return
redirect
(
request
.
values
.
get
(
'
ref
'
,
url_for
(
'
jobs_overview
'
)))
This diff is collapsed.
Click to expand it.
sorter.py
+
4
−
10
View file @
3214cd4b
...
...
@@ -39,14 +39,6 @@ def update_video_metadata(jobid, jobtype, data, state, status):
modify
(
'
UPDATE videos_data SET hash = ?, file_size = ?, duration = ? WHERE id = ?
'
,
status
[
'
hash
'
],
status
[
'
filesize
'
],
status
[
'
duration
'
],
data
[
'
video_id
'
])
@app.route
(
'
/internal/jobs/add/thumbnail
'
,
methods
=
[
'
GET
'
,
'
POST
'
])
@mod_required
@csrf_protect
@handle_errors
(
'
jobs_overview
'
,
'
Zu dieser Veranstaltung existieren keine Videos!
'
,
404
,
IndexError
)
def
add_thumbnail_job
():
schedule_thumbnail
(
request
.
values
[
'
lectureid
'
])
return
redirect
(
request
.
values
.
get
(
'
ref
'
,
url_for
(
'
jobs_overview
'
)))
def
insert_video
(
lectureid
,
dbfilepath
,
fileformatid
,
hash
=
""
,
filesize
=-
1
,
duration
=-
1
,
sourceid
=
None
):
visible
=
query
(
'
SELECT courses.autovisible FROM courses JOIN lectures ON lectures.course_id = courses.id WHERE lectures.id = ?
'
,
lectureid
)[
0
][
'
autovisible
'
]
video_id
=
modify
(
'''
INSERT INTO videos_data
...
...
@@ -116,8 +108,10 @@ def filter_lectures_by_keywords(lectures, keywords):
for
lecture
in
lectures
:
for
keyword
in
keywords
:
# first test for exact match, else make it asci and try substring test
if
(
keyword
==
lecture
[
field
])
or
\
(
str
(
keyword
).
lower
()
in
str
(
to_ascii
(
lecture
[
field
]).
lower
())):
if
(
field
in
lecture
)
and
(
(
keyword
==
lecture
[
field
])
or
(
to_ascii
(
str
(
keyword
).
lower
())
in
str
(
to_ascii
(
lecture
[
field
]).
lower
()))
):
return
[
lecture
]
return
[]
...
...
This diff is collapsed.
Click to expand it.
tests/test_sorter.py
+
40
−
3
View file @
3214cd4b
...
...
@@ -19,7 +19,7 @@ class SorterTestCase(FlaskTestCase):
result
=
sorter
.
split_filename
(
test
[
'
filename
'
])
assert
result
==
test
[
'
chunks
'
],
'
result was {}, should be {}
'
.
format
(
result
,
test
)
def
extract_format_keyword_from_filename
(
self
):
def
test_
extract_format_keyword_from_filename
(
self
):
testdata
=
[
{
'
chunks
'
:
[
''
,
''
],
'
format
'
:
''
},
{
'
chunks
'
:
[
'
asd
'
,
'
720p
'
],
'
format
'
:
'
720p
'
},
...
...
@@ -56,10 +56,47 @@ class SorterTestCase(FlaskTestCase):
assert
result
==
test
[
'
data
'
],
'
result was {}, should be {}
'
.
format
(
result
,
test
[
'
data
'
])
def
test_filter_lectures_by_keywords
(
self
):
pass
testdata
=
[
{
'
lectures
'
:
[],
'
keywords
'
:
[]},
{
'
lectures
'
:
[{
'
title
'
:
'
a
'
,
'
result
'
:
True
},
{
'
title
'
:
'
b:
'
,
'
result
'
:
False
}],
'
keywords
'
:
[
'
a
'
]},
{
'
lectures
'
:
[{
'
speaker
'
:
'
aca
'
,
'
result
'
:
True
},
{
'
comment
'
:
'
bbd:
'
,
'
result
'
:
False
}],
'
keywords
'
:
[
'
c
'
]},
{
'
lectures
'
:
[{
'
internal
'
:
'
apäöa
'
,
'
result
'
:
False
},
{
'
comment
'
:
'
bbd:
'
,
'
result
'
:
False
}],
'
keywords
'
:
[
'
c
'
]},
{
'
lectures
'
:
[{
'
internal
'
:
'
alll
'
,
'
result
'
:
False
},
{
'
comment
'
:
'
bbdäo
'
,
'
result
'
:
True
}],
'
keywords
'
:
[
'
ä
'
]},
]
for
test
in
testdata
:
result
=
sorter
.
filter_lectures_by_keywords
(
test
[
'
lectures
'
],
test
[
'
keywords
'
])
for
i
in
result
:
assert
i
.
get
(
'
result
'
)
for
i
in
test
.
get
(
'
lectures
'
,
[]):
assert
(
not
i
.
get
(
'
result
'
))
or
(
i
in
result
)
def
test_filter_lectures_by_datetime
(
self
):
testdata
=
[
{
'
lectures
'
:
[],
'
date
'
:
None
,
'
time
'
:
None
},
{
'
lectures
'
:
[{
'
time
'
:
datetime
(
year
=
2000
,
month
=
1
,
day
=
1
),
'
result
'
:
True
}],
'
date
'
:
None
,
'
time
'
:
time
(
hour
=
0
,
minute
=
0
)},
{
'
lectures
'
:
[{
'
time
'
:
datetime
(
year
=
2000
,
month
=
1
,
day
=
1
),
'
result
'
:
False
}],
'
date
'
:
None
,
'
time
'
:
time
(
hour
=
0
,
minute
=
1
)},
{
'
lectures
'
:
[{
'
result
'
:
False
}],
'
date
'
:
None
,
'
time
'
:
time
(
hour
=
0
,
minute
=
1
)},
# TODO: add more testdata
]
for
test
in
testdata
:
result
=
sorter
.
filter_lectures_by_datetime
(
test
[
'
lectures
'
],
test
.
get
(
'
date
'
),
test
.
get
(
'
time
'
))
for
i
in
result
:
assert
i
.
get
(
'
result
'
)
for
i
in
test
.
get
(
'
lectures
'
,
[]):
assert
(
not
i
.
get
(
'
result
'
))
or
(
i
in
result
)
pass
def
test_filter_formats_by_filename
(
self
):
pass
def
test_sort_file
(
self
):
pass
testdata
=
[
{
'
filename
'
:
'
08ws-swt-081118.mp4
'
,
'
match
'
:
[
104
],
'
fmt
'
:
0
},
{
'
filename
'
:
'
15ss-zkk-extremale-codes-1080p.mp4
'
,
'
match
'
:
[
6095
],
'
fmt
'
:
4
},
{
'
filename
'
:
'
15ws-afi-151027-720p.mp4
'
,
'
match
'
:
[
6326
],
'
fmt
'
:
5
},
]
with
self
.
requestContext
:
for
test
in
testdata
:
match
,
fmt
=
sorter
.
sort_file
(
test
[
'
filename
'
])
assert
len
(
match
)
==
len
(
test
[
'
match
'
])
for
i
in
match
:
assert
i
[
'
id
'
]
in
test
[
'
match
'
],
'
{} is not supposed to match, only {} is
'
.
format
(
i
[
'
id
'
],
test
[
'
match
'
])
assert
fmt
==
test
[
'
fmt
'
],
'
format id {} is wronge, it is supposed to be {}
'
.
format
(
fmt
,
test
[
'
fmt
'
])
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment