"""
<Program Name>
  z_test_connection_connect.repy

<Started>
  February 9, 2009

<Author>
  Richard Jordan

<Purpose>
  To test that Connection.connect() function works.

  Passes quietly
"""
include connection.repy
include dummies.repy

if callfunc == "initialize":
  IP = getmyip()
  PORT = 12345

def test_connect():
  conn = Connection()
  conn.localip = IP
  conn.localport = PORT
  conn.connect(IP, PORT)
  assert conn.conn
  stopcomm(conn.conn)
  assert conn.remoteip
  assert conn.remoteport
  assert conn.remoteip == IP
  assert conn.remoteport == PORT
  
def test_connect_not_bound():
  conn = Connection()
  try:
    conn.connect(IP, PORT)
  except NotBoundError:
    pass
  else:
    raise Exception("should raise not bound error")

def test_connect_already_connected():
  conn = Connection()
  conn.localip = IP
  conn.localport = PORT
  conn.conn = True
  try:
    conn.connect(IP, PORT)
  except AlreadyConnectedError:
    pass
  else:
    raise Exception("should raise already connected")

####################
# Test Helper Functions
####################

def main():
  # setup
  
  # Run tests
  test_connect()
  test_connect_not_bound()
  test_connect_already_connected()

  # teardown
  exitall()

if callfunc == 'initialize':
  main()
