def test_rollback_removed_mapped_system(self): baseline = SystemBaseline(account=account1, display_name="baseline1", baseline_facts=baseline_facts) db.session.add(baseline) test_system_ids = [] for i in range(4): test_system_id = str(uuid.uuid4()) test_system_ids.append(test_system_id) baseline.add_mapped_system(test_system_id) db.session.commit() query = SystemBaseline.query.filter(SystemBaseline.account == account1) self.assertEqual(query.count(), 1) result = query.one() self.assertEqual(len(result.mapped_system_ids()), 4) removed_system_id = test_system_ids.pop(2) result.remove_mapped_system(removed_system_id) self.assertNotIn(removed_system_id, result.mapped_system_ids()) db.session.rollback() self.assertIn(removed_system_id, result.mapped_system_ids()) query = SystemBaseline.query.filter(SystemBaseline.account == account1) self.assertEqual(query.count(), 1) result = query.one() self.assertEqual(len(result.mapped_system_ids()), 4) for test_system_id in test_system_ids: self.assertIn(test_system_id, result.mapped_system_ids()) self.assertIn(removed_system_id, result.mapped_system_ids())
def test_add_mapped_system(self): baseline = SystemBaseline(account=account1, display_name="baseline1", baseline_facts=baseline_facts) new_uuid = str(uuid.uuid4()) baseline.add_mapped_system(new_uuid) db.session.add(baseline) db.session.commit() query = SystemBaseline.query.filter(SystemBaseline.account == account1) self.assertEqual(query.count(), 1) result = query.one() self.assertEqual(len(result.mapped_system_ids()), 1) self.assertEqual(result.mapped_system_ids()[0], new_uuid)
def test_remove_mapped_system_not_in_list(self): baseline = SystemBaseline(account=account1, display_name="baseline1", baseline_facts=baseline_facts) db.session.add(baseline) test_system_ids = [] for i in range(4): test_system_id = str(uuid.uuid4()) test_system_ids.append(test_system_id) baseline.add_mapped_system(test_system_id) db.session.commit() query = SystemBaseline.query.filter(SystemBaseline.account == account1) self.assertEqual(query.count(), 1) result = query.one() self.assertEqual(len(result.mapped_system_ids()), 4) with self.assertRaises(ValueError) as context: result.remove_mapped_system(str(uuid.uuid4())) self.assertTrue( "Failed to remove system id" in str(context.exception))