~iahmad/messaging-app/autopilot_test_helpers

« back to all changes in this revision

Viewing changes to tests/autopilot/messaging_app/helpers.py

  • Committer: CI bot
  • Author(s): Chris Gagnon
  • Date: 2014-06-09 17:41:59 UTC
  • mfrom: (108.2.1 messaging-app)
  • Revision ID: ps-jenkins@lists.canonical.com-20140609174159-t13hw9vvsrr43b7y
move receive sms out of page proxy into helper 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
 
2
# Copyright 2014 Canonical
 
3
#
 
4
# This file is part of messaging-app.
 
5
#
 
6
# messaging-app is free software: you can redistribute it and/or modify it
 
7
# under the terms of the GNU General Public License version 3, as published
 
8
# by the Free Software Foundation.
 
9
 
 
10
import dbus
 
11
import os
 
12
import shutil
 
13
import tempfile
 
14
 
 
15
 
 
16
def receive_sms(sender, text):
 
17
    """Receive an SMS based on sender number and text
 
18
 
 
19
    :parameter sender: phone number the message is from
 
20
    :parameter text: text you want to send in the message
 
21
    """
 
22
 
 
23
    # prepare and send a Qt GUI script to phonesim, over its private D-BUS
 
24
    # set up by ofono-phonesim-autostart
 
25
    script_dir = tempfile.mkdtemp(prefix="phonesim_script")
 
26
    os.chmod(script_dir, 0o755)
 
27
    with open(os.path.join(script_dir, "sms.js"), "w") as f:
 
28
        f.write("""tabSMS.gbMessage1.leMessageSender.text = "%s";
 
29
tabSMS.gbMessage1.leSMSClass.text = "1";
 
30
tabSMS.gbMessage1.teSMSText.setPlainText("%s");
 
31
tabSMS.gbMessage1.pbSendSMSMessage.click();
 
32
""" % (sender, text))
 
33
 
 
34
    with open("/run/lock/ofono-phonesim-dbus.address") as f:
 
35
        phonesim_bus = f.read().strip()
 
36
    bus = dbus.bus.BusConnection(phonesim_bus)
 
37
    script_proxy = bus.get_object("org.ofono.phonesim", "/")
 
38
    script_proxy.SetPath(script_dir)
 
39
    script_proxy.Run("sms.js")
 
40
    shutil.rmtree(script_dir)