def run_moving2onepercent_to_onepercent_test():

  transitionlist = []


  # Change the vessel_dict and reset all the mock functions in order to have the appropriate info
  vessels_dict[mockutil.extra_vessel_name]["userkeys"] = [node_transition_lib.movingtoonepercentmanyeventspublickey]  

  mockutil.mock_nodemanager_get_node_info(mockutil.nodeid_key, "10.0test", vessels_dict)
  mockutil.mock_backend_set_vessel_owner_key()
  mockutil.mock_backend_split_vessel()
  mockutil.mock_backend_set_vessel_user_keylist([mockutil._mock_pubkey_to_string(
                                                node_transition_lib.onepercentmanyeventspublickey)])

  onepercentmanyevents_resource_fd = file(transition_canonical_to_onepercentmanyevents.RESOURCES_TEMPLATE_FILE_PATH)
  onepercentmanyevents_resourcetemplate = onepercentmanyevents_resource_fd.read()
  onepercentmanyevents_resource_fd.close()

  


  transitionlist.append((("movingto_onepercent_state", node_transition_lib.movingtoonepercentmanyeventspublickey),
                        ("onepercentmanyevents_state", node_transition_lib.onepercentmanyeventspublickey),
                         transition_canonical_to_onepercentmanyevents.onepercentmanyevents_divide,
                         node_transition_lib.noop,
                         onepercentmanyevents_resourcetemplate))

  print "Starting canonical to movingtoonepercentmanyevents test....."

  (success_count, failure_count) = node_transition_lib.do_one_processnode_run(transitionlist, "startstatename", 1)[0]

  assert(success_count == 1)
  assert(failure_count == 0)

  assert_database_info_after_completed()

  assert(mockutil.set_vessel_owner_key_call_count == 0)
  
  # Note that the call to set_vessel_user_keylist should be 10.
  # 9 time for splitting the vessels and setting keylist to []
  # and one time for setting the actual state of the node.
  assert(mockutil.set_vessel_user_keylist_call_count == 10)

  testuser = maindb.get_user(mockutil.testusername)

  all_donations = maindb.get_donations_by_user(testuser, include_inactive_and_broken=True)
  node = all_donations[0].node

  vessel_list_per_node = maindb.get_vessels_on_node(node)

  #testing to see if the vessels exist after splitting
  assert(mockutil.split_vessel_call_count == 9)
  assert(len(vessel_list_per_node) == 9)

  for i in range(len(vessel_list_per_node)):
    # Note that the vessel names go from 1-9 rather then 0-8
    assert(vessel_list_per_node[i].node == node)
    assert(vessel_list_per_node[i].name == "new_vessel"+str(1+i))

  assert(node.extra_vessel_name == "extra_vessel_split9")
Esempio n. 2
0
def run_success_test():
  """
  <Purpose>
    Run the test and make sure that the database was modified
    properly, the right keys were set, and generally all information
    is what was expected.

  <Arguments>
    None

  <Exceptions>
    None

  <Side Effects>
    None

  <Return>
    None
  """

  transitionlist = []

  transitionlist.append(("acceptdonation", "canonical", 
                         node_transition_lib.noop,
                         node_transition_lib.noop, False))

  (success_count, failure_count) = node_transition_lib.do_one_processnode_run(transitionlist, "startstatename", 1)[0]

  assert(success_count == 1)
  assert(failure_count == 0)

  assert_database_info()

  assert(mockutil.set_vessel_owner_key_call_count == 1)
  assert(mockutil.set_vessel_user_keylist_call_count == 1)  
def run_movingto_twopercent_to_canonical_test():

  transitionlist = []


  # Change the vessel_dict and reset all the mock functions in order to have the appropriate info
  testuser = maindb.get_user(mockutil.testusername)

  all_donations = maindb.get_donations_by_user(testuser, include_inactive_and_broken=True)
  node = all_donations[0].node

  # Create 9 vessels for this node
  for i in range(9):
    vessels_dict["vessel"+str(i)]={}
    vessels_dict["vessel"+str(i)]["userkeys"] = []
    vessels_dict["vessel"+str(i)]["ownerkey"] = rsa.rsa_string_to_publickey(node.owner_pubkey)
    vessels_dict["vessel"+str(i)]["ownerinfo"] = ""
    vessels_dict["vessel"+str(i)]["status"] = ""
    vessels_dict["vessel"+str(i)]["advertise"] = True

    maindb.create_vessel(node, "vessel"+str(i))



  vessels_dict[mockutil.extra_vessel_name]["userkeys"] = [node_transition_lib.transition_state_keys['movingto_twopercent']]
  vessels_dict[mockutil.extra_vessel_name]["ownerkey"] = rsa.rsa_string_to_publickey(node.owner_pubkey)

  mockutil.mock_nodemanager_get_node_info(mockutil.nodeid_key, "10.0test", vessels_dict)
  mockutil.mock_backend_set_vessel_owner_key()
  mockutil.mock_backend_join_vessels()
  mockutil.mock_backend_set_vessel_user_keylist([mockutil._mock_pubkey_to_string(
                                                node_transition_lib.transition_state_keys['canonical'])])


  transitionlist.append(("movingto_twopercent", "canonical",
                         node_transition_lib.combine_vessels,
                         node_transition_lib.noop, False))

  print "Starting movingto_twopercent to canonical test....."

  (success_count, failure_count) = node_transition_lib.do_one_processnode_run(transitionlist, "startstatename", 1)[0]

  assert(success_count == 1)
  assert(failure_count == 0)

  assert_database_info_before_completed()

  assert(mockutil.set_vessel_owner_key_call_count == 0)

  assert(mockutil.set_vessel_user_keylist_call_count == 1)

  all_donations = maindb.get_donations_by_user(testuser, include_inactive_and_broken=True)
  node = all_donations[0].node
  
  vessel_list_per_node = maindb.get_vessels_on_node(node)

  #testing to see if the vessels were deleted after join_vessels was called
  assert(mockutil.join_vessels_call_count == 9)
  assert(len(vessel_list_per_node) == 0)
  assert(node.extra_vessel_name == "extra_vessel_join9")
Esempio n. 4
0
def run_movingto_canonical_to_canonical():
    """
  <Purpose>
    Test the process of transitioning a node from the
    movingto_canonical state to the canonical
    state.

  <Arguments>
    None

  <Side Effects>
    None

  <Exceptions>
    AssertionError raised if test fails.

  <Return>
    None
  """

    print "Starting movingto_canonical to canonical test....."
    transitionlist = []

    transitionlist.append(
        ("movingto_canonical", "canonical",
         node_transition_lib.combine_vessels, node_transition_lib.noop, False))

    (success_count,
     failure_count) = node_transition_lib.do_one_processnode_run(
         transitionlist, "startstatename", 1)[0]

    assert (success_count == 1)
    assert (failure_count == 0)

    assert_database_info_non_active()

    assert (mockutil.set_vessel_owner_key_call_count == 0)
    assert (mockutil.set_vessel_user_keylist_call_count == 1)

    # Retrieve the donated node and check its status with the database.
    testuser = maindb.get_user(mockutil.testusername)
    all_donations = maindb.get_donations_by_user(
        testuser, include_inactive_and_broken=True)
    node = all_donations[0].node

    vessel_list_per_node = maindb.get_vessels_on_node(node)

    #testing to see if the vessels were deleted after join_vessels was called
    assert (mockutil.join_vessels_call_count == 9)
    assert (len(vessel_list_per_node) == 0)
    assert (node.extra_vessel_name == "extra_vessel_join9")
def run_movingto_canonical_to_canonical():
  """
  <Purpose>
    Test the process of transitioning a node from the
    movingto_canonical state to the canonical
    state.

  <Arguments>
    None

  <Side Effects>
    None

  <Exceptions>
    AssertionError raised if test fails.

  <Return>
    None
  """

  print "Starting movingto_canonical to canonical test....."
  transitionlist = []

  transitionlist.append(("movingto_canonical", "canonical",
                         node_transition_lib.combine_vessels,
                         node_transition_lib.noop, False))



  (success_count, failure_count) = node_transition_lib.do_one_processnode_run(transitionlist, "startstatename", 1)[0]

  assert(success_count == 1)
  assert(failure_count == 0)

  assert_database_info_non_active()

  assert(mockutil.set_vessel_owner_key_call_count == 0)
  assert(mockutil.set_vessel_user_keylist_call_count == 1)

  # Retrieve the donated node and check its status with the database.
  testuser = maindb.get_user(mockutil.testusername)
  all_donations = maindb.get_donations_by_user(testuser, include_inactive_and_broken=True)
  node = all_donations[0].node

  vessel_list_per_node = maindb.get_vessels_on_node(node)

  #testing to see if the vessels were deleted after join_vessels was called
  assert(mockutil.join_vessels_call_count == 9)
  assert(len(vessel_list_per_node) == 0)
  assert(node.extra_vessel_name == "extra_vessel_join9")
def run_database_stituation_three_test():
  """
  <Purpose>
    The purpose of this test is to test the case where a record
    for the node has been registered in the database and a 
    record for the donation has been registered, but the
    owner key on the node has not been changed.

  <Arguments>
    None

  <Exceptions>
    None

  <Side Effects>
    None

  <Return>
    None
  """

  # Create a database entry for the node
  node_object = maindb.create_node(mockutil.nodeid_key_str, mockutil.node_ip, mockutil.node_port, "10.0test",
                                  False, mockutil.per_node_key_str, mockutil.extra_vessel_name)

  user_object = maindb.get_user(mockutil.testusername)

  # Create a donation for user
  maindb.create_donation(node_object, user_object, "Making a donation")

  transitionlist = []

  transitionlist.append((("donation_state", node_transition_lib.acceptdonationpublickey),
                        ("canonical_state", node_transition_lib.canonicalpublickey),
                         node_transition_lib.noop,
                         node_transition_lib.noop))

  print "Running test where database has record of node, has record of donation and node has donor key"

  (success_count, failure_count) = node_transition_lib.do_one_processnode_run(transitionlist, "startstatename", 1)[0]

  assert(success_count == 1)
  assert(failure_count == 0)

  assert_database_info()

  assert(mockutil.set_vessel_owner_key_call_count == 1)
  assert(mockutil.set_vessel_user_keylist_call_count == 1)
Esempio n. 7
0
def run_database_update_test():
    """
  <Purpose>
    Run the test and make sure that the database was modified
    properly, the right keys were set, and generally all information
    is what was expected.

  <Arguments>
    None

  <Exceptions>
    None

  <Side Effects>
    None

  <Return>
    None
  """

    transitionlist = []

    active_nodes_list = maindb.get_active_nodes()
    active_nodes_list[0].is_active = False
    active_nodes_list[0].save()

    transitionlist.append(
        (("startstatename", node_transition_lib.onepercentmanyeventspublickey),
         ("endstatename", node_transition_lib.onepercentmanyeventspublickey),
         transition_onepercentmanyevents_to_onepercentmanyevents.
         update_database, node_transition_lib.noop,
         transition_onepercentmanyevents_to_onepercentmanyevents.
         update_database_node))

    (success_count,
     failure_count) = node_transition_lib.do_one_processnode_run(
         transitionlist, "startstatename", 1)[0]

    assert (success_count == 1)
    assert (failure_count == 0)

    assert_database_info()

    assert (mockutil.set_vessel_owner_key_call_count == 0)
    # set_vessel_user_keylist_call_count won't be called because the
    # node_transition_lib will see that it's a state change to the same state.
    assert (mockutil.set_vessel_user_keylist_call_count == 0)
def run_database_update_test():
  """
  <Purpose>
    Run the test and make sure that the database was modified
    properly, the right keys were set, and generally all information
    is what was expected.

  <Arguments>
    None

  <Exceptions>
    None

  <Side Effects>
    None

  <Return>
    None
  """

  transitionlist = []

  active_nodes_list = maindb.get_active_nodes()
  active_nodes_list[0].is_active = False
  active_nodes_list[0].save()

  transitionlist.append(("twopercent", "twopercent", 
                         node_transition_lib.update_database,
                         node_transition_lib.noop, True,
                         node_transition_lib.update_database_node))

  (success_count, failure_count) = node_transition_lib.do_one_processnode_run(transitionlist, "startstatename", 1)[0]

  assert(success_count == 1)
  assert(failure_count == 0)

  assert_database_info()

  assert(mockutil.set_vessel_owner_key_call_count == 0)
  # set_vessel_user_keylist_call_count won't be called because the
  # node_transition_lib will see that it's a state change to the same state.
  assert(mockutil.set_vessel_user_keylist_call_count == 0)  
Esempio n. 9
0
def run_can_to_moving1percent_test():
    """
  <Purpose>
    Run the test and make sure that the database was modified
    properly, the right keys were set, and generally all information
    is what was expected.

  <Arguments>
    None

  <Exceptions>
    None

  <Side Effects>
    None

  <Return>
    None
  """

    print "Starting canonical to movingtoonepercentmanyevents test....."
    transitionlist = []

    transitionlist.append(
        (("canonical_state", node_transition_lib.canonicalpublickey),
         ("movingto_onepercent_state",
          node_transition_lib.movingtoonepercentmanyeventspublickey),
         node_transition_lib.noop, node_transition_lib.noop))

    (success_count,
     failure_count) = node_transition_lib.do_one_processnode_run(
         transitionlist, "startstatename", 1)[0]

    assert (success_count == 1)
    assert (failure_count == 0)

    assert_database_info_before_completed()

    assert (mockutil.set_vessel_owner_key_call_count == 0)
    assert (mockutil.set_vessel_user_keylist_call_count == 1)
def run_can_to_moving1percent_test():
  """
  <Purpose>
    Run the test and make sure that the database was modified
    properly, the right keys were set, and generally all information
    is what was expected.

  <Arguments>
    None

  <Exceptions>
    None

  <Side Effects>
    None

  <Return>
    None
  """

  print "Starting canonical to movingtoonepercentmanyevents test....."
  transitionlist = []

  transitionlist.append((("canonical_state", node_transition_lib.canonicalpublickey),
                        ("movingto_onepercent_state", node_transition_lib.movingtoonepercentmanyeventspublickey),
                         node_transition_lib.noop,
                         node_transition_lib.noop))
  


  (success_count, failure_count) = node_transition_lib.do_one_processnode_run(transitionlist, "startstatename", 1)[0]

  assert(success_count == 1)
  assert(failure_count == 0)

  assert_database_info_before_completed()

  assert(mockutil.set_vessel_owner_key_call_count == 0)
  assert(mockutil.set_vessel_user_keylist_call_count == 1)  
def run_onepercentmanyevents_to_movingto_canonical():
  """
  <Purpose>
    Test the process of transitioning a node from the 
    onepercentmanyevents state to the movingto_canonical
    state.

  <Arguments>
    None

  <Side Effects>
    None

  <Exceptions>
    AssertionError raised if test fails.

  <Return>
    None
  """

  print "Starting onepercentmanyevents to movingto_canonical test....."
  transitionlist = []

  transitionlist.append(("onepercentmanyevents", "movingto_canonical",
                         node_transition_lib.noop,
                         node_transition_lib.noop, False))



  (success_count, failure_count) = node_transition_lib.do_one_processnode_run(transitionlist, "startstatename", 1)[0]

  assert(success_count == 1)
  assert(failure_count == 0)

  assert_database_info_non_active()

  assert(mockutil.set_vessel_owner_key_call_count == 0)
  assert(mockutil.set_vessel_user_keylist_call_count == 1)
Esempio n. 12
0
def run_onepercentmanyevents_to_movingto_canonical():
    """
  <Purpose>
    Test the process of transitioning a node from the 
    onepercentmanyevents state to the movingto_canonical
    state.

  <Arguments>
    None

  <Side Effects>
    None

  <Exceptions>
    AssertionError raised if test fails.

  <Return>
    None
  """

    print "Starting onepercentmanyevents to movingto_canonical test....."
    transitionlist = []

    transitionlist.append(
        ("onepercentmanyevents", "movingto_canonical",
         node_transition_lib.noop, node_transition_lib.noop, False))

    (success_count,
     failure_count) = node_transition_lib.do_one_processnode_run(
         transitionlist, "startstatename", 1)[0]

    assert (success_count == 1)
    assert (failure_count == 0)

    assert_database_info_non_active()

    assert (mockutil.set_vessel_owner_key_call_count == 0)
    assert (mockutil.set_vessel_user_keylist_call_count == 1)
def run_movingto_canonical_to_onepercentmanyevents():
  """
  <Purpose>
    Test the process of transitioning a node from the
    movingto_canonical state to the onepercentmanyevents
    state.

  <Arguments>
    None

  <Side Effects>
    None

  <Exceptions>
    AssertionError raised if test fails.

  <Return>
    None
  """

  print "Starting movingto_canonical to onepercentmanyevents test....."
  transitionlist = []

  onepercentmanyevents_resource_fd = file(transition_onepercentmanyevents_to_canonical.RESOURCES_TEMPLATE_FILE_PATH)
  onepercentmanyevents_resourcetemplate = onepercentmanyevents_resource_fd.read()
  onepercentmanyevents_resource_fd.close()

  transitionlist.append(("movingto_canonical", "onepercentmanyevents",
                         node_transition_lib.split_vessels,
                         node_transition_lib.noop, True, 
                         onepercentmanyevents_resourcetemplate))



  (success_count, failure_count) = node_transition_lib.do_one_processnode_run(transitionlist, "startstatename", 1)[0]

  assert(success_count == 1)
  assert(failure_count == 0)

  assert_database_info_active()

  assert(mockutil.set_vessel_owner_key_call_count == 0)

  # The count for setting user key list is 10, once for the extra vessel
  # and 9 times for splitting the vessel.
  assert(mockutil.set_vessel_user_keylist_call_count == 10)

  # Retrieve the donated node and check its status with the database.
  testuser = maindb.get_user(mockutil.testusername)
  all_donations = maindb.get_donations_by_user(testuser, include_inactive_and_broken=True)
  node = all_donations[0].node

  vessel_list_per_node = maindb.get_vessels_on_node(node)

  # Testing to see if the vessels were created after split_vessels was called
  assert(mockutil.split_vessel_call_count == 9)
  assert(len(vessel_list_per_node) == 9)

  for i in range(len(vessel_list_per_node)):
    # Note that the vessel names go from 1-9 rather then 0-8
    assert(vessel_list_per_node[i].node == node)
    assert(vessel_list_per_node[i].name == "new_vessel"+str(1+i))

  assert(node.extra_vessel_name == "extra_vessel_split9")
Esempio n. 14
0
def run_movingto_canonical_to_onepercentmanyevents():
    """
  <Purpose>
    Test the process of transitioning a node from the
    movingto_canonical state to the onepercentmanyevents
    state.

  <Arguments>
    None

  <Side Effects>
    None

  <Exceptions>
    AssertionError raised if test fails.

  <Return>
    None
  """

    print "Starting movingto_canonical to onepercentmanyevents test....."
    transitionlist = []

    onepercentmanyevents_resource_fd = file(
        transition_onepercentmanyevents_to_canonical.
        RESOURCES_TEMPLATE_FILE_PATH)
    onepercentmanyevents_resourcetemplate = onepercentmanyevents_resource_fd.read(
    )
    onepercentmanyevents_resource_fd.close()

    transitionlist.append(
        ("movingto_canonical", "onepercentmanyevents",
         node_transition_lib.split_vessels, node_transition_lib.noop, True,
         onepercentmanyevents_resourcetemplate))

    (success_count,
     failure_count) = node_transition_lib.do_one_processnode_run(
         transitionlist, "startstatename", 1)[0]

    assert (success_count == 1)
    assert (failure_count == 0)

    assert_database_info_active()

    assert (mockutil.set_vessel_owner_key_call_count == 0)

    # The count for setting user key list is 10, once for the extra vessel
    # and 9 times for splitting the vessel.
    assert (mockutil.set_vessel_user_keylist_call_count == 10)

    # Retrieve the donated node and check its status with the database.
    testuser = maindb.get_user(mockutil.testusername)
    all_donations = maindb.get_donations_by_user(
        testuser, include_inactive_and_broken=True)
    node = all_donations[0].node

    vessel_list_per_node = maindb.get_vessels_on_node(node)

    # Testing to see if the vessels were created after split_vessels was called
    assert (mockutil.split_vessel_call_count == 9)
    assert (len(vessel_list_per_node) == 9)

    for i in range(len(vessel_list_per_node)):
        # Note that the vessel names go from 1-9 rather then 0-8
        assert (vessel_list_per_node[i].node == node)
        assert (vessel_list_per_node[i].name == "new_vessel" + str(1 + i))

    assert (node.extra_vessel_name == "extra_vessel_split9")
Esempio n. 15
0
def run_moving2onepercent_to_onepercent_test():

    transitionlist = []

    # Change the vessel_dict and reset all the mock functions in order to have the appropriate info
    vessels_dict[mockutil.extra_vessel_name]["userkeys"] = [
        node_transition_lib.
        transition_state_keys['movingto_onepercentmanyevents']
    ]

    mockutil.mock_nodemanager_get_node_info(mockutil.nodeid_key, "10.0test",
                                            vessels_dict)
    mockutil.mock_backend_set_vessel_owner_key()
    mockutil.mock_backend_split_vessel()
    mockutil.mock_backend_set_vessel_user_keylist([
        mockutil._mock_pubkey_to_string(
            node_transition_lib.transition_state_keys['onepercentmanyevents'])
    ])

    onepercentmanyevents_resource_fd = file(
        transition_canonical_to_onepercentmanyevents.
        RESOURCES_TEMPLATE_FILE_PATH)
    onepercentmanyevents_resourcetemplate = onepercentmanyevents_resource_fd.read(
    )
    onepercentmanyevents_resource_fd.close()

    transitionlist.append(
        ("movingto_onepercentmanyevents", "onepercentmanyevents",
         node_transition_lib.split_vessels, node_transition_lib.noop, True,
         onepercentmanyevents_resourcetemplate))

    print "Starting canonical to movingtoonepercentmanyevents test....."

    (success_count,
     failure_count) = node_transition_lib.do_one_processnode_run(
         transitionlist, "startstatename", 1)[0]

    assert (success_count == 1)
    assert (failure_count == 0)

    assert_database_info_after_completed()

    assert (mockutil.set_vessel_owner_key_call_count == 0)

    # Note that the call to set_vessel_user_keylist should be 10.
    # 9 time for splitting the vessels and setting keylist to []
    # and one time for setting the actual state of the node.
    assert (mockutil.set_vessel_user_keylist_call_count == 10)

    testuser = maindb.get_user(mockutil.testusername)

    all_donations = maindb.get_donations_by_user(
        testuser, include_inactive_and_broken=True)
    node = all_donations[0].node

    vessel_list_per_node = maindb.get_vessels_on_node(node)

    #testing to see if the vessels exist after splitting
    assert (mockutil.split_vessel_call_count == 9)
    assert (len(vessel_list_per_node) == 9)

    for i in range(len(vessel_list_per_node)):
        # Note that the vessel names go from 1-9 rather then 0-8
        assert (vessel_list_per_node[i].node == node)
        assert (vessel_list_per_node[i].name == "new_vessel" + str(1 + i))

    assert (node.extra_vessel_name == "extra_vessel_split9")
Esempio n. 16
0
def run_moving2onepercent_to_canonical_test():

    transitionlist = []

    # Change the vessel_dict and reset all the mock functions in order to have the appropriate info
    testuser = maindb.get_user(mockutil.testusername)

    all_donations = maindb.get_donations_by_user(
        testuser, include_inactive_and_broken=True)
    node = all_donations[0].node

    # Create 9 vessels for this node
    for i in range(9):
        vessels_dict["vessel" + str(i)] = {}
        vessels_dict["vessel" + str(i)]["userkeys"] = []
        vessels_dict["vessel" +
                     str(i)]["ownerkey"] = rsa.rsa_string_to_publickey(
                         node.owner_pubkey)
        vessels_dict["vessel" + str(i)]["ownerinfo"] = ""
        vessels_dict["vessel" + str(i)]["status"] = ""
        vessels_dict["vessel" + str(i)]["advertise"] = True

        maindb.create_vessel(node, "vessel" + str(i))

    vessels_dict[mockutil.extra_vessel_name]["userkeys"] = [
        node_transition_lib.
        transition_state_keys['movingto_onepercentmanyevents']
    ]
    vessels_dict[
        mockutil.extra_vessel_name]["ownerkey"] = rsa.rsa_string_to_publickey(
            node.owner_pubkey)

    mockutil.mock_nodemanager_get_node_info(mockutil.nodeid_key, "10.0test",
                                            vessels_dict)
    mockutil.mock_backend_set_vessel_owner_key()
    mockutil.mock_backend_join_vessels()
    mockutil.mock_backend_set_vessel_user_keylist([
        mockutil._mock_pubkey_to_string(
            node_transition_lib.transition_state_keys['canonical'])
    ])

    transitionlist.append(
        ("movingto_onepercentmanyevents", "canonical",
         node_transition_lib.combine_vessels, node_transition_lib.noop, False))

    print "Starting canonical to movingtoonepercentmanyevents test....."

    (success_count,
     failure_count) = node_transition_lib.do_one_processnode_run(
         transitionlist, "startstatename", 1)[0]

    assert (success_count == 1)
    assert (failure_count == 0)

    assert_database_info_before_completed()

    assert (mockutil.set_vessel_owner_key_call_count == 0)

    assert (mockutil.set_vessel_user_keylist_call_count == 1)

    all_donations = maindb.get_donations_by_user(
        testuser, include_inactive_and_broken=True)
    node = all_donations[0].node

    vessel_list_per_node = maindb.get_vessels_on_node(node)

    #testing to see if the vessels were deleted after join_vessels was called
    assert (mockutil.join_vessels_call_count == 9)
    assert (len(vessel_list_per_node) == 0)
    assert (node.extra_vessel_name == "extra_vessel_join9")
def run_multiple_donation_test():
  """
  <Purpose>
    The purpose of this test is to see how the transtion script would
    react if we provide a dictionary where a vessel is in the acceptdonation
    state but the node has already in the canonical state. This is possible
    if the node had two vessel in the acceptdonation state to start with.
    This is essentially if the node has two donations. Currently we don't handle
    multiple donations from the second node, so when we run the test, the success
    count should be 0 and the failure count should be 1. Also the name of the extra
    vessel should not change.

  <Arguments>
    None

  <Exceptions>
    None

  <Side Effects>
    None

  <Return>
    None
  """
 
  # Have the extra vessel in canonical form
  vessels_dict[mockutil.extra_vessel_name]["userkeys"] = [node_transition_lib.canonicalpublickey]

  # Have a second vessel in acceptdonation state. Essentially a second donation.
  vessels_dict["second_donation"] = {"userkeys" : [node_transition_lib.acceptdonationpublickey],
                                   "ownerkey" : mockutil.donor_key,
                                   "ownerinfo" : "",
                                   "status" : "",
                                   "advertise" : True}

  # Create a database entry for the node
  node_object = maindb.create_node(mockutil.nodeid_key_str, mockutil.node_ip, mockutil.node_port, "10.0test",
                                  False, mockutil.per_node_key_str, mockutil.extra_vessel_name)
  user_object = maindb.get_user(mockutil.testusername)
  # Create a donation for user
  maindb.create_donation(node_object, user_object, "Making a donation")
  
  # Register the new vesseldict so get_info returns this new modified vesseldict
  mockutil.mock_nodemanager_get_node_info(mockutil.nodeid_key, "10.0test", vessels_dict)




  transitionlist = []

  transitionlist.append((("donation_state", node_transition_lib.acceptdonationpublickey),
                        ("canonical_state", node_transition_lib.canonicalpublickey),
                         node_transition_lib.noop,
                         node_transition_lib.noop))

  print "Running test where database has record of node, no record of donation and node has donor key"

  (success_count, failure_count) = node_transition_lib.do_one_processnode_run(transitionlist, "startstatename", 1)[0]

  assert(success_count == 0)
  assert(failure_count == 1)

  assert_database_info()

  assert(mockutil.set_vessel_owner_key_call_count == 0)
  assert(mockutil.set_vessel_user_keylist_call_count == 0)