Skip to content

Commit

Permalink
Merge pull request #9 from danielrichman/master
Browse files Browse the repository at this point in the history
Move spacenearus filter to habitat-transition
  • Loading branch information
adamgreig committed Sep 9, 2012
2 parents 05496a8 + 6e7b1e3 commit d7c0e75
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
3 changes: 3 additions & 0 deletions designdocs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
spacenearus:
filters:
spacenear: habitat_transition.spacenearus.spacenear_filter
15 changes: 15 additions & 0 deletions habitat_transition/spacenearus.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,27 @@
import json
import time
import statsd
from couch_named_python import version
from habitat.utils import rfc3339, immortal_changes

__all__ = ["SpaceNearUs"]
logger = logging.getLogger("habitat_transition.spacenearus")
statsd.init_statsd({'STATSD_BUCKET_PREFIX': 'habitat.spacenearus'})


@version(1)
def spacenear_filter(doc, req):
"""Select parsed payload_telemetry and all listener_telemetry documents."""
if 'type' not in doc:
return False
if doc['type'] == "listener_telemetry":
return True
if doc['type'] == "payload_telemetry":
if 'data' in doc and '_parsed' in doc['data']:
return True
return False


class SpaceNearUs:
"""
The SpaceNearUs daemon forwards on parsed telemetry to the spacenear.us
Expand Down
57 changes: 57 additions & 0 deletions habitat_transition/test_spacenear_filter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Copyright 2012 (C) Adam Greig
#
# This file is part of habitat.
#
# habitat is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# habitat is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with habitat. If not, see <http://www.gnu.org/licenses/>.

"""
Tests SpaceNear document functions
"""

from . import spacenearus

from copy import deepcopy

doc = {
"type": "payload_telemetry",
"data": {
"_parsed": "test test"
}
}

def test_spacenear_filter():
fil = spacenearus.spacenear_filter

wrongtype = deepcopy(doc)
wrongtype["type"] = "flight"
assert not fil(wrongtype, {})

listener = deepcopy(doc)
listener["type"] = "listener_telemetry"
assert fil(listener, {})

parsed = deepcopy(doc)
assert fil(parsed, {})

nodata = deepcopy(doc)
del nodata['data']
assert not fil(nodata, {})

notparsed = deepcopy(doc)
del notparsed['data']['_parsed']
assert not fil(notparsed, {})

def test_issue_241():
# this should not produce an exception
spacenearus.spacenear_filter({"_deleted": True}, {})

0 comments on commit d7c0e75

Please sign in to comment.