| 1 |
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- |
| 2 |
# |
| 3 |
# Push Notifications Autopilot Test Suite |
| 4 |
# Copyright (C) 2014 Canonical |
| 5 |
# |
| 6 |
# This program is free software: you can redistribute it and/or modify |
| 7 |
# it under the terms of the GNU General Public License as published by |
| 8 |
# the Free Software Foundation, either version 3 of the License, or |
| 9 |
# (at your option) any later version. |
| 10 |
# |
| 11 |
# This program is distributed in the hope that it will be useful, |
| 12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
# GNU General Public License for more details. |
| 15 |
# |
| 16 |
# You should have received a copy of the GNU General Public License |
| 17 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
# |
| 19 |
|
| 20 |
|
| 21 |
"""Push-Notifications autopilot data structure classes""" |
| 22 |
|
| 23 |
|
| 24 |
class PushNotificationMessage: |
| 25 |
""" |
| 26 |
Class to hold all the details required for a |
| 27 |
push notification message |
| 28 |
""" |
| 29 |
|
| 30 |
def __init__(self, channel='system', data=None, expire_after=None): |
| 31 |
""" |
| 32 |
Constructor |
| 33 |
:param channel: Name of channel |
| 34 |
:param data: Data value |
| 35 |
:param expire_after: expiration time |
| 36 |
""" |
| 37 |
self.channel = channel |
| 38 |
self.data = data |
| 39 |
self.expire_after = expire_after |
| 40 |
|
| 41 |
def to_json(self): |
| 42 |
""" |
| 43 |
Return JSON representation of message |
| 44 |
:return: JSON representation of message |
| 45 |
""" |
| 46 |
json_str = '{{"channel":"{0}", "data":{{{1}}}, "expire_on":"{2}"}}' |
| 47 |
return json_str.format(self.channel, self.data, self.expire_after) |
| 48 |
|
| 49 |
|
| 50 |
class DeviceNotificationData: |
| 51 |
""" |
| 52 |
Class to represent device's data used for sending notification, including: |
| 53 |
- Device software channel |
| 54 |
- Device build number |
| 55 |
- Device model |
| 56 |
- Device last update |
| 57 |
- Data for the notification |
| 58 |
""" |
| 59 |
|
| 60 |
def __init__(self, channel=None, device=None, build_number=None, |
| 61 |
last_update=None, version=None, data=None): |
| 62 |
""" |
| 63 |
Constructor |
| 64 |
:param channel: Name of channel |
| 65 |
:param device: Name of device |
| 66 |
:param build_number: Build number |
| 67 |
:param last_update: Last update time |
| 68 |
:param version: Build version |
| 69 |
:param data: Device specific data |
| 70 |
""" |
| 71 |
self.channel = channel |
| 72 |
self.build_number = build_number |
| 73 |
self.device = device |
| 74 |
self.last_update = last_update |
| 75 |
self.version = version |
| 76 |
self.data = data |
| 77 |
|
| 78 |
def inc_build_number(self): |
| 79 |
""" |
| 80 |
Increment build number |
| 81 |
""" |
| 82 |
self.build_number = str(int(self.build_number) + 1) |
| 83 |
|
| 84 |
def dec_build_number(self): |
| 85 |
""" |
| 86 |
Decrement build number |
| 87 |
""" |
| 88 |
self.build_number = str(int(self.build_number) - 1) |
| 89 |
|
| 90 |
def to_json(self): |
| 91 |
""" |
| 92 |
Return json representation of info based: |
| 93 |
"IMAGE-CHANNEL/DEVICE-MODEL": [BUILD-NUMBER, CHANNEL-ALIAS]" |
| 94 |
:return: JSON representation of device data |
| 95 |
""" |
| 96 |
json_str = '"{0}/{1}": [{2}, "{3}"]' |
| 97 |
return json_str.format(self.channel, self.device, self.build_number, |
| 98 |
self.data) |