def test_with_invalid_type_ip(self): with self.assertRaises(Exception): ordinateur = models.Ordinateur(123456) with self.assertRaises(Exception): ordinateur = models.Ordinateur([]) with self.assertRaises(Exception): ordinateur = models.Ordinateur(10.20)
def test_optional_params_are_set(self): params = { "ip" : "1.2.3.4", "user" : "abc", "name" : "xyz" } ordinateur = models.Ordinateur(params["ip"], params["user"], params["name"]) self.assertEqual(ordinateur.ip, params["ip"]) self.assertEqual(ordinateur.user, params["user"]) self.assertEqual(ordinateur.name, params["name"])
def load_from_mocks(self): return [ # VM Linuxlocal models.Ordinateur("192.168.1.156", "linuxlocal"), # VM Linuxlocal models.Ordinateur("192.168.1.157", "linuxlocal"), # IP valide, non joignable (Timeout) models.Ordinateur("1.2.3.4"), # IP invalide models.Ordinateur("192.168.1.300", name="Test"), # IP invalide models.Ordinateur("192.168.1.400"), # IP invalide models.Ordinateur("192.168.1.500"), ]
def to_ordinateur(self): ordinateur = models.Ordinateur(self.edit_ip.text(), self.edit_user.text(), self.edit_name.text()) return ordinateur
def test_empty_params_replaced_by_defaults(self): ordinateur = models.Ordinateur("1.2.3.4", "", "") self.assertEqual(ordinateur.user, models.Ordinateur.DEFAULT_USER) self.assertEqual(ordinateur.name, models.Ordinateur.DEFAULT_NAME)
def test_ip_is_stripped(self): expected_ip = "1.2.3.4" self.assertEqual(models.Ordinateur("1.2.3.4").ip, expected_ip) self.assertEqual(models.Ordinateur(" 1.2.3.4").ip, expected_ip) self.assertEqual(models.Ordinateur("1.2.3.4 ").ip, expected_ip)
def test_with_only_ip(self): ordinateur = models.Ordinateur("1.2.3.4") self.assertEqual(ordinateur.ip, "1.2.3.4")
def test_with_empty_ip(self): with self.assertRaises(Exception): ordinateur = models.Ordinateur("") with self.assertRaises(Exception): ordinateur = models.Ordinateur(" ")
def test_without_params(self): with self.assertRaises(Exception): ordinateur = models.Ordinateur()