<commit_before><commit_msg>add test-receive-file-decline.py<commit_after>from servicetest import EventPattern
from twisted.words.xish import xpath

from file_transfer_helper import ReceiveFileTest, FT_STATE_CANCELLED, \
    FT_STATE_CHANGE_REASON_LOCAL_STOPPED, exec_file_transfer_test

class ReceiveFileDeclineTest(ReceiveFileTest):
    def accept_file(self):
        # decline FT
        self.channel.Close()

        state_event, iq_event = self.q.expect_many(
            EventPattern('dbus-signal', signal='FileTransferStateChanged'),
            EventPattern('stream-iq', iq_type='error'))

        error_node = xpath.queryForNodes('/iq/error', iq_event.stanza)[0]
        assert error_node['code'] == '403'

        state, reason = state_event.args
        assert state == FT_STATE_CANCELLED
        assert reason == FT_STATE_CHANGE_REASON_LOCAL_STOPPED
        self.q.expect('dbus-signal', signal='Closed')

        # stop test
        return True

if __name__ == '__main__':
    exec_file_transfer_test(ReceiveFileDeclineTest)
{'fraction_non_alphanumeric': 0.09468599033816426, 'fraction_numerical': 0.003864734299516908, 'mean_word_length': 3.774193548387097, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4820576', 'n_tokens_mistral': 330, 'n_tokens_neox': 318, 'n_words': 55}