From 3c58ea2e1522b7f290e972a13d709a9cd1ae82aa Mon Sep 17 00:00:00 2001 From: kovacsbalu Date: Tue, 13 Jan 2015 13:57:13 +0000 Subject: [PATCH 1/3] tests for Device --- tests/test_devices.py | 63 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 55 insertions(+), 8 deletions(-) diff --git a/tests/test_devices.py b/tests/test_devices.py index 336db99..04db7ca 100644 --- a/tests/test_devices.py +++ b/tests/test_devices.py @@ -1,19 +1,66 @@ from __future__ import print_function import os +import mock +import pytest +import time -import pushbullet +from pushbullet import device -API_KEY = os.environ["PUSHBULLET_API_KEY"] class TestDevices(object): - @classmethod def setup_class(cls): - cls.pb = pushbullet.PushBullet(API_KEY) + cls.device_iden = "test_iden" + device_info = {"active": True, "iden": cls.device_iden, "created": time.time(), "modified": time.time(), + "type": "stream", "kind": "stream", "nickname": "test dev", "manufacturer": "test c", "model": "test m", "pushable": True} + cls.account = mock.Mock(return_value=True) + cls.device = device.Device(cls.account, device_info) def test_encoding_support(self): - for device in self.pb.devices: - # We're not actually intersted in the output, just that it doesn't - # cause any errors. - print(device) + # We're not actually intersted in the output, just that it doesn't + # cause any errors. + print(self.device) + + def test_push_note(self): + title = "test title" + body = "test body" + self.device.push_note(title, body) + pushed_data = {"type": "note", "title": title, "body": body, "device_iden": self.device_iden} + self.account._push.assert_called_with(pushed_data) + + def test_push_address(self): + name = "test name" + address = "test address" + self.device.push_address(name, address) + pushed_data = {"type": "address", "name": name, "address": address, "device_iden": self.device_iden} + self.account._push.assert_called_with(pushed_data) + + def test_push_list(self): + title = "test title" + items = ["test item 1", "test item 2"] + self.device.push_list(title, items) + pushed_data = {"type": "list", "title": title, "items": items, "device_iden": self.device_iden} + self.account._push.assert_called_with(pushed_data) + + def test_push_link(self): + title = "test title" + url = "http://test.url" + body = "test body" + self.device.push_link(title, url, body) + pushed_data = {"type": "link", "title": title, "url": url, "body": body, "device_iden": self.device_iden} + self.account._push.assert_called_with(pushed_data) + + def test_push_file(self): + file_name = "test_file.name" + file_url = "http://file.url" + file_type = "test/type" + body = "test body" + self.device.push_file(file_name, file_url, file_type, body) + self.account.push_file.assert_called_with(file_name, file_url, file_type, body, device=self.device) + + def test_account_push(self): + data = {"title": "test title"} + self.device._push(data) + pushed_data = {"title": "test title", "device_iden": self.device_iden} + self.account._push.assert_called_with(pushed_data) From 3fac367f73a30c79d8fced0a6174ba1cf9161cde Mon Sep 17 00:00:00 2001 From: kovacsbalu Date: Wed, 14 Jan 2015 08:36:14 +0000 Subject: [PATCH 2/3] channels test added channels test minor modification in device tests --- tests/test_channels.py | 61 ++++++++++++++++++++++++++++++++++++------ tests/test_devices.py | 4 +-- 2 files changed, 54 insertions(+), 11 deletions(-) diff --git a/tests/test_channels.py b/tests/test_channels.py index 7e8ee13..96006e7 100644 --- a/tests/test_channels.py +++ b/tests/test_channels.py @@ -1,19 +1,64 @@ from __future__ import print_function -import os +import mock +import time -import pushbullet +from pushbullet import channel -API_KEY = os.environ["PUSHBULLET_API_KEY"] class TestChannels(object): @classmethod def setup_class(cls): - cls.pb = pushbullet.PushBullet(API_KEY) + cls.channel_tag = "test_tag" + channel_info = {'iden': "test_iden", 'name': 'test channel', 'created': time.time(), 'modified': time.time(), 'tag': cls.channel_tag, 'active': True} + cls.account = mock.Mock(return_value=True) + cls.channel = channel.Channel(cls.account, channel_info) def test_encoding_support(self): - for channel in self.pb.channels: - # We're not actually intersted in the output, just that it doesn't - # cause any errors. - print(channel) + # We're not actually intersted in the output, just that it doesn't + # cause any errors. + print(self.channel) + + def test_push_note(self): + title = "test title" + body = "test body" + self.channel.push_note(title, body) + pushed_data = {"type": "note", "title": title, "body": body, "channel_tag": self.channel_tag} + self.account._push.assert_called_with(pushed_data) + + def test_push_address(self): + name = "test name" + address = "test address" + self.channel.push_address(name, address) + pushed_data = {"type": "address", "name": name, "address": address, "channel_tag": self.channel_tag} + self.account._push.assert_called_with(pushed_data) + + def test_push_list(self): + title = "test title" + items = ["test item 1", "test item 2"] + self.channel.push_list(title, items) + pushed_data = {"type": "list", "title": title, "items": items, "channel_tag": self.channel_tag} + self.account._push.assert_called_with(pushed_data) + + def test_push_link(self): + title = "test title" + url = "http://test.url" + body = "test body" + self.channel.push_link(title, url, body) + pushed_data = {"type": "link", "title": title, "url": url, "body": body, "channel_tag": self.channel_tag} + self.account._push.assert_called_with(pushed_data) + + def test_push_file(self): + file_name = "test_file.name" + file_url = "http://file.url" + file_type = "test/type" + body = "test body" + self.channel.push_file(file_name, file_url, file_type, body) + self.account.push_file.assert_called_with(file_name, file_url, file_type, body, channel=self.channel) + + def test_push(self): + data = {"title": "test title"} + self.channel._push(data) + pushed_data = {"title": "test title", "channel_tag": self.channel_tag} + self.account._push.assert_called_with(pushed_data) diff --git a/tests/test_devices.py b/tests/test_devices.py index 04db7ca..eb32771 100644 --- a/tests/test_devices.py +++ b/tests/test_devices.py @@ -1,8 +1,6 @@ from __future__ import print_function -import os import mock -import pytest import time from pushbullet import device @@ -59,7 +57,7 @@ def test_push_file(self): self.device.push_file(file_name, file_url, file_type, body) self.account.push_file.assert_called_with(file_name, file_url, file_type, body, device=self.device) - def test_account_push(self): + def test_push(self): data = {"title": "test title"} self.device._push(data) pushed_data = {"title": "test title", "device_iden": self.device_iden} From fb0d65cebd8ba9417b567f3a02c727dd384cb121 Mon Sep 17 00:00:00 2001 From: kovacsbalu Date: Thu, 15 Jan 2015 09:15:44 +0000 Subject: [PATCH 3/3] added __repr__ test --- tests/test_channels.py | 5 +++++ tests/test_devices.py | 3 +++ 2 files changed, 8 insertions(+) diff --git a/tests/test_channels.py b/tests/test_channels.py index 96006e7..b5ac0c3 100644 --- a/tests/test_channels.py +++ b/tests/test_channels.py @@ -20,6 +20,9 @@ def test_encoding_support(self): # cause any errors. print(self.channel) + def test_repr(self): + assert repr(self.channel) == "Channel(name: 'test channel' tag: '%s')" % self.channel_tag + def test_push_note(self): title = "test title" body = "test body" @@ -62,3 +65,5 @@ def test_push(self): self.channel._push(data) pushed_data = {"title": "test title", "channel_tag": self.channel_tag} self.account._push.assert_called_with(pushed_data) + + diff --git a/tests/test_devices.py b/tests/test_devices.py index eb32771..993825b 100644 --- a/tests/test_devices.py +++ b/tests/test_devices.py @@ -20,6 +20,9 @@ def test_encoding_support(self): # cause any errors. print(self.device) + def test_repr(self): + assert repr(self.device) == "Device('test dev')" + def test_push_note(self): title = "test title" body = "test body"