Skip to content
This repository has been archived by the owner on Jul 7, 2022. It is now read-only.

Tests #28

Merged
merged 3 commits into from
Jan 30, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 58 additions & 8 deletions tests/test_channels.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,69 @@
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_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"
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)


66 changes: 57 additions & 9 deletions tests/test_devices.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,67 @@
from __future__ import print_function

import os
import mock
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_repr(self):
assert repr(self.device) == "Device('test dev')"

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_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)