Beispiel #1
0
class TestStream():

	TEST_USERNAME = '******'
	TEST_PASSWORD = '******'

	def setup(self):
		def callback(x):
			pass

		self.stream = Stream(consumer=callback, username=self.TEST_USERNAME, password=self.TEST_PASSWORD)

	@raises(Exception)
	@with_setup(None, None)
	def test_invalid_consumer(self):
		callback = set()

		Stream(consumer=callback, username=self.TEST_USERNAME, password=self.TEST_PASSWORD)

	@with_setup(None, None)
	def test_consumer_function(self):
		def callback(x):
			pass

		stream = Stream(consumer=callback, username=self.TEST_USERNAME, password=self.TEST_PASSWORD)
		
		assert stream

	@with_setup(None, None)
	def test_consumer_class(self):
		class ConsumerTest():
			def __call__(self, *args, **kwargs):
				pass

		consumer = ConsumerTest()

		stream = Stream(consumer=consumer, username=self.TEST_USERNAME, password=self.TEST_PASSWORD)

		assert stream

	def test_reset(self):
		self.stream.reset()

		eq_([], self.stream.keywords)
		eq_([], self.stream.locations)
		eq_([], self.stream.usernames)

	def test_filter_keywords_list(self):
		words = ['a', 'list', 'of', 'keywords']

		self.stream.filter_keywords(words)

		eq_(words, self.stream.keywords)

	def test_filter_keywords_string(self):
		self.stream.filter_keywords('a keyword')

		eq_(['a keyword'], self.stream.keywords)

	def test_append_keywords(self):
		words = ['a', 'list', 'of', 'keywords']

		self.stream.filter_keywords(words[:2])

		eq_(['a', 'list'], self.stream.keywords)

		self.stream.filter_keywords(words[2:4])

		eq_(words, self.stream.keywords)

	def test_filter_locations(self):
		locations = [(1, 2, 3, 4)]

		self.stream.filter_locations(locations)

		eq_(locations, self.stream.locations)

	@raises(Exception)
	def test_filter_invalid_locations(self):
		self.stream.filter_locations([1, 2, 3, 4])
Beispiel #2
0
	def setup(self):
		def callback(x):
			pass

		self.stream = Stream(consumer=callback, username=self.TEST_USERNAME, password=self.TEST_PASSWORD)
Beispiel #3
0
from turbine.stream import Stream
from turbine.consumers import JSONConsumer
import pprint

USERNAME = ''
PASSWORD = ''

class Consumer(JSONConsumer):
	def on_status(self, status):
		pprint.pprint(status)

consumer = Consumer()

stream = Stream(USERNAME, PASSWORD, consumer)

stream.filter_keywords(['python'])
stream.filter_locations([(140.999283, -37.505032, 159.278717, -28.157021)])

stream.filter()