def chk_ipaddress(ipaddress): """ Check if IP address exists in our database """ DEV_ADD_IP = False # uncomment this to import from a fake different IP / used for dev # DEV_ADD_IP = '127.0.0.2' if DEV_ADD_IP: previous_ip = ipaddress ipaddress = DEV_ADD_IP try: switch = Switch.objects.get(ipaddress=ipaddress) except Switch.DoesNotExist: switch = Switch(name=ipaddress, ipaddress=ipaddress) switch.save() if not switch.id: print "Error when adding new Switch!" raise SystemExit if DEV_ADD_IP: ipaddress = previous_ip data = {'ipaddress': ipaddress, 'switch': switch} return data
def setUp(self): """Create model object""" self.user = User.objects.get(pk=1) # Switch model self.switch = Switch(name='localhost', ipaddress='127.0.0.1') self.switch.save() self.assertTrue(self.switch.__unicode__()) self.hangupcause = HangupCause(code=700, enumeration='UNALLOCATED_NUMBER') self.hangupcause.save() self.assertTrue(self.hangupcause.__unicode__())
def testSwitch(self): obj = Switch(name='localhost', ipaddress='127.0.0.1') obj.save() self.assertEquals('localhost', obj.name) self.assertNotEquals(obj.id, None) obj.delete()