summaryrefslogtreecommitdiff
path: root/tests/twisted/avahi/file-transfer/receive-file-cancelled-immediately.py
blob: 91597f8a69544ae916978ad2c59ac50ff7342de7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import socket

from saluttest import exec_test
from file_transfer_helper import ReceiveFileTest

import constants as cs

class ReceiveFileCancelledImmediatelyTest(ReceiveFileTest):
    def accept_file(self):
        # sender cancels FT immediately so stop to listen to the HTTP socket
        # before we accept the transfer.
        self.httpd.server_close()

        ReceiveFileTest.accept_file(self)

    def receive_file(self):
        # Connect to Salut's socket
        s = socket.socket(self._get_socket_address_family(), socket.SOCK_STREAM)
        s.connect(self.address)

        # Salut can't connect to download the file
        e = self.q.expect('dbus-signal', signal='FileTransferStateChanged')
        state, reason = e.args
        assert state == cs.FT_STATE_CANCELLED
        assert reason == cs.FT_STATE_CHANGE_REASON_REMOTE_STOPPED

if __name__ == '__main__':
    test = ReceiveFileCancelledImmediatelyTest()
    exec_test(test.test)