Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
djrandom-py
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
ale
djrandom-py
Commits
d033cf24
Commit
d033cf24
authored
13 years ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
add more safety around the bwlimit; more tests
parent
b28d12fa
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
client/djrandom_client/client.py
+11
-6
11 additions, 6 deletions
client/djrandom_client/client.py
client/djrandom_client/test/test_client.py
+54
-9
54 additions, 9 deletions
client/djrandom_client/test/test_client.py
with
65 additions
and
15 deletions
client/djrandom_client/client.py
+
11
−
6
View file @
d033cf24
...
...
@@ -52,8 +52,12 @@ class FullScan(threading.Thread):
def
run_client
(
server_url
,
music_dir
,
api_key
,
run_once
,
bwlimit
,
enable_watcher
):
if
bwlimit
:
throttle
.
set_rate_limit
(
int
(
bwlimit
))
# Warn if we're running without a bandwidth limit.
bwlimit
=
int
(
bwlimit
)
if
bwlimit
<=
0
:
log
.
warn
(
'
Running without a bandwidth limit!
'
)
else
:
throttle
.
set_rate_limit
(
bwlimit
)
# Warn on this condition, but don't die -- the directory might exist later!
if
not
os
.
path
.
isdir
(
music_dir
):
...
...
@@ -123,15 +127,16 @@ def main():
parser
.
add_option
(
'
--server_url
'
,
default
=
'
https://djrandom.incal.net/receiver
'
,
help
=
'
URL to the API endpoint
'
)
parser
.
add_option
(
'
--bwlimit
'
,
type
=
'
int
'
,
help
=
'
Bandwidth limit (in KBps, default unlimited)
'
)
parser
.
add_option
(
'
--bwlimit
'
,
type
=
'
int
'
,
default
=
0
,
help
=
'
Upload bandwidth limit, kilobytes/s (default:
'
'
unlimited)
'
)
parser
.
add_option
(
'
--no_realtime_watch
'
,
action
=
'
store_true
'
,
help
=
'
Monitor music_dir in realtime
'
)
daemonize
.
add_standard_options
(
parser
)
utils
.
read_config_defaults
(
parser
,
os
.
path
.
join
(
os
.
getenv
(
'
HOME
'
),
'
.djrandom.conf
'
))
parser
,
os
.
path
.
expanduser
(
'
~/
.djrandom.conf
'
))
parser
.
set_default
(
'
pidfile
'
,
os
.
path
.
join
(
os
.
getenv
(
'
HOME
'
),
'
.djrandom.pid
'
))
'
pidfile
'
,
os
.
path
.
expanduser
(
'
~/
.djrandom.pid
'
))
opts
,
args
=
parser
.
parse_args
()
if
not
opts
.
api_key
:
parser
.
error
(
'
You must specify an API Key
'
)
...
...
This diff is collapsed.
Click to expand it.
client/djrandom_client/test/test_client.py
+
54
−
9
View file @
d033cf24
import
mox
import
os
import
unittest
import
shutil
import
sys
import
tempfile
import
time
import
Queue
from
djrandom_client
import
client
...
...
@@ -65,14 +68,7 @@ class FullScanTest(mox.MoxTestBase):
self
.
assertRaises
(
EndTest
,
fs
.
run
)
class
ClientOptionsTest
(
mox
.
MoxTestBase
):
def
setUp
(
self
):
mox
.
MoxTestBase
.
setUp
(
self
)
self
.
mox
.
StubOutWithMock
(
utils
,
'
read_config_defaults
'
)
utils
.
read_config_defaults
(
mox
.
IgnoreArg
(),
mox
.
IsA
(
str
))
self
.
mox
.
StubOutWithMock
(
utils
,
'
check_version
'
)
self
.
mox
.
StubOutWithMock
(
daemonize
,
'
daemonize
'
)
class
ClientRunner
(
object
):
def
_Run
(
self
,
args
,
expect_success
=
True
):
try
:
...
...
@@ -86,6 +82,55 @@ class ClientOptionsTest(mox.MoxTestBase):
'
execution with args:
"
%s
"
failed (status %s, expected %s)
'
%
(
'
'
.
join
(
args
),
success
,
expect_success
))
class
ClientWithConfigFileTest
(
ClientRunner
,
mox
.
MoxTestBase
):
def
setUp
(
self
):
mox
.
MoxTestBase
.
setUp
(
self
)
self
.
tmpdir
=
tempfile
.
mkdtemp
()
self
.
old_expanduser
=
os
.
path
.
expanduser
def
_expanduser
(
p
):
if
p
.
startswith
(
'
~/
'
):
return
os
.
path
.
join
(
self
.
tmpdir
,
p
[
2
:])
else
:
return
p
os
.
path
.
expanduser
=
_expanduser
def
tearDown
(
self
):
mox
.
MoxTestBase
.
tearDown
(
self
)
shutil
.
rmtree
(
self
.
tmpdir
)
os
.
path
.
expanduser
=
self
.
old_expanduser
def
test_run_options_from_config
(
self
):
config_file
=
os
.
path
.
join
(
self
.
tmpdir
,
'
.djrandom.conf
'
)
with
open
(
config_file
,
'
w
'
)
as
fd
:
fd
.
write
(
'
api_key = KEY
\n
bwlimit = 10
\n
'
)
self
.
mox
.
StubOutWithMock
(
utils
,
'
check_version
'
)
utils
.
check_version
()
self
.
mox
.
StubOutWithMock
(
daemonize
,
'
daemonize
'
)
daemonize
.
daemonize
(
mox
.
IgnoreArg
(),
client
.
run_client
,
CompareTuple
(
mox
.
IsA
(
str
),
mox
.
IsA
(
str
),
'
KEY
'
,
None
,
10
,
True
))
self
.
mox
.
ReplayAll
()
self
.
_Run
([])
class
ClientOptionsTest
(
ClientRunner
,
mox
.
MoxTestBase
):
def
setUp
(
self
):
mox
.
MoxTestBase
.
setUp
(
self
)
self
.
mox
.
StubOutWithMock
(
utils
,
'
read_config_defaults
'
)
utils
.
read_config_defaults
(
mox
.
IgnoreArg
(),
mox
.
IsA
(
str
))
self
.
mox
.
StubOutWithMock
(
utils
,
'
check_version
'
)
self
.
mox
.
StubOutWithMock
(
daemonize
,
'
daemonize
'
)
def
test_client_needs_api_key
(
self
):
self
.
mox
.
ReplayAll
()
self
.
_Run
([],
False
)
...
...
@@ -101,7 +146,7 @@ class ClientOptionsTest(mox.MoxTestBase):
CompareTuple
(
mox
.
IsA
(
str
),
mox
.
IsA
(
str
),
'
KEY
'
,
None
,
None
,
True
))
None
,
0
,
True
))
self
.
mox
.
ReplayAll
()
self
.
_Run
([
'
--api_key=KEY
'
])
...
...
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