# !!! This is far from finished !!!

"""Test 1 'The solo test' - Can I hear myself talking?

001 A - Open the service, and a channel
        instantiate an Atalk service
        ats = atalk.get_service(service_type, service_medium, relevant_credentials)
        Access a channel on a service, e.g. channel 6
        atc = ats.get_channel("6")
        set my default sender identity
        atc.my_name_is("My_name")
        And have the Janitor clean all obsolete messages
        atc.clean()

002 A - Create a new talk
        Ask the Janitor for a vacant talk-ID
        akt_id = atc.janitor("find_vacant_talkid", "pattern")
        Create an a-talk object, and 
        atk = atc.make_talk(atk_id)

003 A - Post a test-message
        atk.post('PT1M', 'test body...'), where 'PT1M' means one minute

004 A - Read the test-message
        Try to read the message back in
        list_of_messages = atk.look(me, '', '')
        to get all messages from 'me', no tags nor max-age indicated
        Check that the message is as expected

005 A - Clean up ...
        Have Janitor remove the talk, from the channel
        atc.remove_talk(tid)
"""

import atalk

print "\n# 001"
ats = atalk.get_service("file_disk", "/var/atalk")
print "Service:", ats.is_open(), ats

atc = ats.get_channel(ats.test_channel())
print "Channel:", atc.is_open(), atc
print "My name:", atc.my_name_is("cIhmst")
print "Clean  :", atc.clean()

print "\n# 002"
atk_id = atc.get_vacant_talkid("pattern")
print "Talk id:", atk_id
atk = atc.get_talk(atk_id)
print "Atalk  :", atk

print "\n# 003"
atm = atk.post('', '1 m', 'test body with (":-=*)...\nAnd another line.\ntalk_id = '+atk_id, ['test']) # Add the atk_id to the body to make message unique...
print "Message:", atm
print "selftst:", atm._selftest()
print "Message:\n", atm.as_textblock()

print "\n# 004"
#XXX change this to actually search all messages by 'me'
str_atm_id = atm.get_uid()
print "Msg id :", str_atm_id
atm_retur = atk.get_message_by_id(str_atm_id)
print "selftst:", atm_retur._selftest()
atm.show_diff(atm_retur)
atm.show()
atm_retur.show()
 
print "\n# 005"
atc.erase_talk(atk_id)
# its not custom to actively close a channel behind you, 
# even if it becomes empty, closing it may be a larger operation. 
# Leave to the implementation to maintain the most cost-efficient housekeeping.
del atm_retur, atm, str_atm_id, atk, atk_id, atc, ats
