Page MenuHomeSoftware Heritage

test_model.py
No OneTemporary

test_model.py

# Copyright (C) 2020 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
import datetime
import attr
from swh.scheduler import model
def test_select_columns():
@attr.s
class TestModel(model.BaseSchedulerModel):
id = attr.ib(type=str)
test1 = attr.ib(type=str)
a_first_attr = attr.ib(type=str)
@property
def test2(self):
"""This property should not show up in the extracted columns"""
return self.test1
assert TestModel.select_columns() == ("a_first_attr", "id", "test1")
def test_insert_columns():
@attr.s
class TestModel(model.BaseSchedulerModel):
id = attr.ib(type=str)
test1 = attr.ib(type=str)
@property
def test2(self):
"""This property should not show up in the extracted columns"""
return self.test1
assert TestModel.insert_columns_and_metavars() == (
("id", "test1"),
("%(id)s", "%(test1)s"),
)
def test_insert_columns_auto_now_add():
@attr.s
class TestModel(model.BaseSchedulerModel):
id = attr.ib(type=str)
test1 = attr.ib(type=str)
added = attr.ib(type=datetime.datetime, metadata={"auto_now_add": True})
assert TestModel.insert_columns_and_metavars() == (
("id", "test1"),
("%(id)s", "%(test1)s"),
)
def test_insert_columns_auto_now():
@attr.s
class TestModel(model.BaseSchedulerModel):
id = attr.ib(type=str)
test1 = attr.ib(type=str)
updated = attr.ib(type=datetime.datetime, metadata={"auto_now": True})
assert TestModel.insert_columns_and_metavars() == (
("id", "test1", "updated"),
("%(id)s", "%(test1)s", "now()"),
)
def test_insert_columns_primary_key():
@attr.s
class TestModel(model.BaseSchedulerModel):
id = attr.ib(type=str, metadata={"primary_key": True})
test1 = attr.ib(type=str)
assert TestModel.insert_columns_and_metavars() == (("test1",), ("%(test1)s",))

File Metadata

Mime Type
text/x-python
Expires
Tue, Apr 15, 2:21 AM (8 h, 2 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3286500

Event Timeline