Changeset View
Changeset View
Standalone View
Standalone View
swh/scheduler/tests/test_model.py
Show First 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | assert TestModel.insert_columns_and_metavars() == ( | ||||
("id", "test1", "updated"), | ("id", "test1", "updated"), | ||||
("%(id)s", "%(test1)s", "now()"), | ("%(id)s", "%(test1)s", "now()"), | ||||
) | ) | ||||
def test_insert_columns_primary_key(): | def test_insert_columns_primary_key(): | ||||
@attr.s | @attr.s | ||||
class TestModel(model.BaseSchedulerModel): | class TestModel(model.BaseSchedulerModel): | ||||
id = attr.ib(type=str, metadata={"primary_key": True}) | id = attr.ib(type=str, metadata={"auto_primary_key": True}) | ||||
test1 = attr.ib(type=str) | test1 = attr.ib(type=str) | ||||
assert TestModel.insert_columns_and_metavars() == (("test1",), ("%(test1)s",)) | assert TestModel.insert_columns_and_metavars() == (("test1",), ("%(test1)s",)) | ||||
def test_insert_primary_key(): | |||||
@attr.s | |||||
class TestModel(model.BaseSchedulerModel): | |||||
id = attr.ib(type=str, metadata={"auto_primary_key": True}) | |||||
test1 = attr.ib(type=str) | |||||
assert TestModel.primary_key_columns() == ("id",) | |||||
@attr.s | |||||
class TestModel2(model.BaseSchedulerModel): | |||||
col1 = attr.ib(type=str, metadata={"primary_key": True}) | |||||
col2 = attr.ib(type=str, metadata={"primary_key": True}) | |||||
test1 = attr.ib(type=str) | |||||
assert TestModel2.primary_key_columns() == ("col1", "col2") |