1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2
# Copyright 2014 Canonical
4
# This program is free software: you can redistribute it and/or modify it
5
# under the terms of the GNU General Public License version 3, as published
6
# by the Free Software Foundation.
8
"""push-notifications autopilot tests."""
13
from push_notifications import config
14
from autopilot.testcase import AutopilotTestCase
15
from autopilot.matchers import Eventually
16
from autopilot.platform import model
17
from testtools.matchers import Equals
20
class PushNotificationMessage:
22
Class to hold all the details required for a
23
push notification message
30
class PushNotificationTestBase(AutopilotTestCase):
32
Base class for push notification test cases
35
PUSH_CLIENT_CONFIG_FILE = '~/.config/ubuntu-push-client/config.json'
36
DEFAULT_DISPLAY_MESSAGE = 'There\'s an updated system image.'
37
PUSH_MIME_TYPE = 'application/json'
38
SECTION_DEFAULT = 'default'
39
KEY_ENVIRONMENT = 'environment'
40
KEY_SERVER_DEVICE_URL = 'push_server_device_url'
41
KEY_SERVER_LISTENER_URL = 'push_server_listener_url'
45
Start the client running with the correct server config
47
# Read the config data
48
self.read_config_file()
49
# Read the server device address
50
server_device_address = self.get_push_server_device_address()
51
# write server device address to the client config
52
self.write_push_client_server_address(server_device_address)
53
# restart the push client
54
self.restart_push_client()
55
# validate that the initialisation push message is displayed
56
self.validate_push_message(self.DEFAULT_DISPLAY_MESSAGE)
58
super(PushNotificationTestBase, self).setUp()
61
def read_config_file(self):
63
Read data from config file
65
config_file = config.get_config_file()
66
self.config = configparser.ConfigParser()
67
self.config.read(config_file)
68
# read the name of the environment to use (local/remote)
69
self.environment = self.config.get(self.SECTION_DEFAULT, self.KEY_ENVIRONMENT)
71
def get_push_server_device_address(self):
73
Return the server device address from config file
75
return self.config.get(self.environment, self.KEY_SERVER_DEVICE_URL)
77
def get_push_server_listener_address(self):
79
Return the server device address from config file
81
return self.config(self.environment, self.KEY_SERVER_LISTENER_URL)
83
def restart_push_client(self):
85
Restart the push client
88
def write_push_client_server_address(self, server_address):
90
Write the server details to the push client config
93
def send_push_notification(self, server_address, json_data):
95
Send the specified push message to the server
96
using an HTTP POST command
99
def format_json_data(self, push_message):
101
Return the json formatted encoding of push_message including:
102
channel, data, expire_after
105
def validate_push_message(self, display_message, timeout=10):
107
Validate that a notification message is displayed on screen