MCPcopy
hub / github.com/piccolo-orm/piccolo / test_update

Method test_update

tests/table/test_update.py:618–655  ·  view source on GitHub ↗

Make sure the update method uses ``auto_update`` columns correctly.

(self)

Source from the content-addressed store, hash-verified

616 self.assertGreater(row.modified_on, existing_modified_on)
617
618 def test_update(self):
619 """
620 Make sure the update method uses ``auto_update`` columns correctly.
621 """
622 # Insert a row for us to update
623 AutoUpdateTable.insert(AutoUpdateTable(name="test")).run_sync()
624
625 data = (
626 AutoUpdateTable.select(
627 AutoUpdateTable.name, AutoUpdateTable.modified_on
628 )
629 .first()
630 .run_sync()
631 )
632
633 assert data is not None
634
635 self.assertDictEqual(
636 data,
637 {"name": "test", "modified_on": None},
638 )
639
640 # Update the row
641 AutoUpdateTable.update(
642 {AutoUpdateTable.name: "test 2"}, force=True
643 ).run_sync()
644
645 # Retrieve the row
646 updated_row = (
647 AutoUpdateTable.select(
648 AutoUpdateTable.name, AutoUpdateTable.modified_on
649 )
650 .first()
651 .run_sync()
652 )
653 assert updated_row is not None
654 self.assertIsInstance(updated_row["modified_on"], datetime.datetime)
655 self.assertEqual(updated_row["name"], "test 2")
656
657
658###############################################################################

Callers

nothing calls this directly

Calls 7

AutoUpdateTableClass · 0.85
insertMethod · 0.80
selectMethod · 0.80
updateMethod · 0.80
assertEqualMethod · 0.80
run_syncMethod · 0.45
firstMethod · 0.45

Tested by

no test coverage detected