def test_21_add_update_delete_clientapp(self): ClientApplication(ip="1.2.3.4", hostname="host1", clienttype="PAM", node="localnode").save() c = ClientApplication.query.filter( ClientApplication.ip == "1.2.3.4").first() self.assertEqual(c.hostname, "host1") self.assertEqual(c.ip, "1.2.3.4") self.assertEqual(c.clienttype, "PAM") t1 = c.lastseen self.assertIn("localnode", repr(c)) ClientApplication(ip="1.2.3.4", hostname="host1", clienttype="PAM", node="localnode").save() c = ClientApplication.query.filter( ClientApplication.ip == "1.2.3.4").first() self.assertTrue(c.lastseen > t1) ClientApplication.query.filter(ClientApplication.id == c.id).delete() c = ClientApplication.query.filter( ClientApplication.ip == "1.2.3.4").first() self.assertEqual(c, None)
def test_21_add_update_delete_clientapp(self): # MySQLs DATETIME type supports only seconds so we have to mock now() current_time = datetime(2018, 3, 4, 5, 6, 8) with mock.patch('privacyidea.models.datetime') as mock_dt: mock_dt.now.return_value = current_time ClientApplication(ip="1.2.3.4", hostname="host1", clienttype="PAM", node="localnode").save() c = ClientApplication.query.filter( ClientApplication.ip == "1.2.3.4").first() self.assertEqual(c.hostname, "host1") self.assertEqual(c.ip, "1.2.3.4") self.assertEqual(c.clienttype, "PAM") t1 = c.lastseen self.assertIn("localnode", repr(c)) ClientApplication(ip="1.2.3.4", hostname="host1", clienttype="PAM", node="localnode").save() c = ClientApplication.query.filter( ClientApplication.ip == "1.2.3.4").first() self.assertGreater(c.lastseen, t1, c) ClientApplication.query.filter(ClientApplication.id == c.id).delete() c = ClientApplication.query.filter( ClientApplication.ip == "1.2.3.4").first() self.assertEqual(c, None)