def setUp(self): self.moonlock = { "Name": "Moonlock", "Sign": "MOON", "Address": "1.1.1.1", "Port": "8000" } self.muskrat = { "Name": "Muskrat", "Sign": "MUSK", "Address": "2.2.2.2", "Port": "8001" } self.group = { "Name": "Group", "Sign": "GROUP", "Members": str(common.toMorse(self.moonlock["Sign"])) + " " + str(common.toMorse(self.muskrat["Sign"])) } self.destinationConfig = DestinationConfig(TEST_CONTACTS_FILE, TEST_GROUPS_FILE)
def testAddContact(self): self.destinationConfig.addContact(self.moonlock) retrievedContact = self.destinationConfig.createDestination( common.toMorse(self.moonlock["Sign"])) expectedEndpoints = [(self.moonlock["Address"], self.moonlock["Port"])] self.assertEqual(self.moonlock["Name"], retrievedContact.getName()) self.assertEqual(self.moonlock["Sign"], retrievedContact.getSign()) self.assertEqual(expectedEndpoints, retrievedContact.getEndpoints())
def testToMorse(self): callsign = "MOON" expectedMorse = [s.DAH, s.DAH, s.CHAR_SPACE, s.DAH, s.DAH, s.DAH, s.CHAR_SPACE, s.DAH, s.DAH, s.DAH, s.CHAR_SPACE, s.DAH, s.DIT] morseString = commonFunctions.toMorse(callsign) calculatedMorse = [s(int(val)) for val in morseString] self.assertEqual(expectedMorse, calculatedMorse)
def testAddGroup(self): self.destinationConfig.addContact(self.moonlock) self.destinationConfig.addContact(self.muskrat) self.destinationConfig.addGroup(self.group) retrievedGroup = self.destinationConfig.createDestination( common.toMorse(self.group["Sign"])) expectedEndpoints = [(self.moonlock["Address"], self.moonlock["Port"]), (self.muskrat["Address"], self.muskrat["Port"])] self.assertEqual(self.group["Name"], retrievedGroup.getName()) self.assertEqual(self.group["Sign"], retrievedGroup.getSign()) self.assertEqual([self.moonlock["Sign"], self.muskrat["Sign"]], retrievedGroup.getMemberCallsigns()) self.assertEqual(expectedEndpoints, retrievedGroup.getEndpoints())
def getMembers(oldList=None): contacts = destConfig.getAllContacts() print() for contact in contacts: print(" " + contact.getSign() + ": " + contact.getName()) print() print("Enter call signs of members, separated by spaces:") if oldList: print(" [" + " ".join(oldList) + "]") members = input(" > ") memberList = [] for member in [m.upper() for m in members.split()]: if not member in [contact.getSign() for contact in contacts]: print("Error: " + member + " is not in contacts list; not adding to group.") else: code = str(toMorse(member)) memberList.append(code) return " ".join(memberList)
def testCallsignDoesNotExist(self): destinationConfig = DestinationConfig(TEST_CONTACTS_FILE, TEST_GROUPS_FILE) self.assertIsNone( destinationConfig.createDestination(common.toMorse("TEST")))
def updateGroup(self, oldCallsign, newConfig): self.groupsConfig.remove_section(oldCallsign) if newConfig is not None: self.groupsConfig[toMorse(newConfig["Sign"])] = newConfig writeConfig(self.groupsFile, self.groupsConfig)
def addGroup(self, newGroup): #TODO: Ask to overwrite if duplicate self.groupsConfig[toMorse(newGroup["Sign"])] = newGroup writeConfig(self.groupsFile, self.groupsConfig)
def addContact(self, newContact): #TODO: Ask to overwrite if duplicate self.contactsConfig[toMorse(newContact["Sign"])] = newContact writeConfig(self.contactsFile, self.contactsConfig)