Skip to content

Commit

Permalink
Add 'screenboard revoke' command to dogshell
Browse files Browse the repository at this point in the history
- Add tests for 'screenboard revoke' command
- Also add tests for 'screenboard share' command
  • Loading branch information
Matthieu Allegre committed Jun 5, 2015
1 parent 8080fbc commit 77b3556
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
16 changes: 16 additions & 0 deletions datadog/dogshell/screenboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ def setup_parser(cls, subparsers):
share_parser.add_argument('screenboard_id', help="screenboard to share")
share_parser.set_defaults(func=cls._share)

revoke_parser = verb_parsers.add_parser('revoke', help="Revoke an existing screenboard's"
" with a public URL.")
revoke_parser.add_argument('screenboard_id', help="screenboard to revoke")
revoke_parser.set_defaults(func=cls._revoke)

pull_parser = verb_parsers.add_parser('pull', help="Pull a screenboard on the server"
" into a local file")
pull_parser.add_argument('screenboard_id', help="ID of screenboard to pull")
Expand Down Expand Up @@ -240,6 +245,17 @@ def _share(cls, args):
else:
print(json.dumps(res))

@classmethod
def _revoke(cls, args):
api._timeout = args.timeout
format = args.format
res = api.Screenboard.revoke(args.screenboard_id)

if format == 'pretty':
print(cls._pretty_json(res))
else:
print(json.dumps(res))

@classmethod
def _new_file(cls, args):
api._timeout = args.timeout
Expand Down
17 changes: 17 additions & 0 deletions tests/integration/dogshell/test_dogshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import time
import tempfile
import unittest
import urllib2

# 3rd
from nose.plugins.attrib import attr
Expand Down Expand Up @@ -267,6 +268,7 @@ def test_timeboards(self):
check_return_code=False)
self.assertNotEquals(return_code, 0)

@attr('screenboard')
def test_screenboards(self):
# Create a screenboard and write it to a file
name, temp0 = get_temp_file()
Expand Down Expand Up @@ -338,6 +340,21 @@ def test_screenboards(self):
finally:
os.unlink(updated_file)

# Share the screenboard
out, _, _ = self.dogshell(["screenboard", "share", str(screenboard["id"])])
out = json.loads(out)
assert out['board_id'] == screenboard['id']
# Verify it's actually shared
public_url = out['public_url'].replace('8080', '5000')
response = urllib2.urlopen(public_url)
assert response.code == 200

# Revoke the screenboard and verify it's actually revoked
self.dogshell(["screenboard", "revoke", str(screenboard["id"])])
with self.assertRaises(urllib2.HTTPError) as cm:
urllib2.urlopen(public_url)
assert cm.exception.code == 404

# Delete the screenboard
self.dogshell(["screenboard", "delete", str(screenboard["id"])])

Expand Down

0 comments on commit 77b3556

Please sign in to comment.