autowisp.tests.test_bui_models module

Class Inheritance Diagram

Inheritance diagram of BuiModelBase, BuiModelTestCase, Path, Project, TestMigrationCarriesExistingRows, TestModelBase, TestModifiedIsMaintained

Tests for the browser-interface model base and its timestamp triggers.

Importing this module configures Django against the throwaway user data directory that autowisp.tests installs, so the developer’s real bui_db.sqlite3 – which holds their project list – is never touched. That redirect happens when the parent package is imported, which is before this module runs, so nothing here needs to arrange it.

class autowisp.tests.test_bui_models.BuiModelTestCase(methodName='runTest')[source]

Bases: TestCase

Inheritance diagram of autowisp.tests.test_bui_models.BuiModelTestCase

Base migrating the throwaway browser-interface database.

make_project(name)[source]

Create and return a project row to experiment on.

classmethod setUpClass()[source]

Hook method for setting up class fixture before running tests in the class.

stamp(project)[source]

Re-read project’s modified from the database.

class autowisp.tests.test_bui_models.TestMigrationCarriesExistingRows(methodName='runTest')[source]

Bases: BuiModelTestCase

Inheritance diagram of autowisp.tests.test_bui_models.TestMigrationCarriesExistingRows

Upgrading an existing database keeps its data and stamps it.

test_existing_row_keeps_created_and_gains_modified()[source]

The column is added to a populated table without loss.

Also exercises migrating backwards across the change, which is what first revealed that SQLite refuses to alter a column while a trigger names it – hence dropping them in pre_migrate.

class autowisp.tests.test_bui_models.TestModelBase(methodName='runTest')[source]

Bases: BuiModelTestCase

Inheritance diagram of autowisp.tests.test_bui_models.TestModelBase

Every browser-interface model carries the timestamp columns.

test_contrib_models_are_left_alone()[source]

Django’s own tables get no trigger; they have no such column.

test_project_has_both_columns()[source]

Project inherits created and modified.

test_selection_matches_the_base_class()[source]

Exactly the models deriving from the base are selected.

Comparing the two sets, rather than checking one known model, is what makes this hold for models added later: the triggers are installed on the strength of a modified field being present, and this asserts that predicate agrees with deriving from core.models.BuiModelBase. A model that gained the column some other way, or one that derived from the base but shadowed the field, would show up here.

class autowisp.tests.test_bui_models.TestModifiedIsMaintained(methodName='runTest')[source]

Bases: BuiModelTestCase

Inheritance diagram of autowisp.tests.test_bui_models.TestModifiedIsMaintained

modified advances however the row is written.

_assert_advances(project, write)[source]

Assert write moves modified forward.

test_bulk_update()[source]

bulk_update would otherwise write back a stale value.

Django reads the in-memory attribute rather than calling pre_save, so without the trigger this does not merely skip the stamp – it restores the timestamp the object was loaded with.

test_every_covered_model_has_its_trigger()[source]

migrate leaves a trigger on each selected model’s table.

test_queryset_update()[source]

QuerySet.update bypasses auto_now entirely.

test_raw_sql()[source]

Statements issued outside the ORM are covered too.

test_save()[source]

The ordinary path, covered by auto_now alone.

autowisp.tests.test_bui_models._tick = 0.05

Enough for the millisecond-resolution timestamps the trigger writes to differ between two updates.