def test_duplicate_group(db): """Ensure groups with duplicate paths can't be created.""" original = Group("twins") db.add(original) duplicate = Group("twins") db.add(duplicate) with raises(IntegrityError): db.commit()
def test_is_subgroup_multilevel(): """Ensure is_subgroup_of() works with "deeper" subgroups.""" path = "test.one.two.three" group = Group(path) path_parts = path.split(".") # tests each of the "higher" groups (test, test.one, test.one.two) for level in range(1, len(path_parts)): assert group.is_subgroup_of(Group(".".join(path_parts[:level])))
def session_group(sdb): """Create a group named 'sessiongroup' in the db for test session.""" group = Group("sessiongroup") sdb.add(group) sdb.commit() yield group
def insert_dev_data(config_path: str) -> None: """Load the app config and insert some "starter" data for a dev version.""" session = get_session_from_config(config_path) user = User("TestUser", "password") group = Group("testing", "An automatically created group to use for testing") subscription = GroupSubscription(user, group) motte_group = Group( "themotte", "Themotte group, automatically created for the dev environment") motte_subscription = GroupSubscription(user, motte_group) session.add_all( [user, group, subscription, motte_group, motte_subscription]) session.commit()
def test_creation_validates_schema(mocker): """Ensure that group creation goes through expected validation.""" mocker.spy(GroupSchema, "load") mocker.spy(Ltree, "_validate") mocker.spy(SimpleString, "_validate") Group("testing", "with a short description") assert GroupSchema.load.called assert Ltree._validate.call_args[0][1] == "testing" assert SimpleString._validate.call_args[0][1] == "with a short description"
def test_creation_validates_schema(mocker): """Ensure that group creation goes through expected validation.""" mocker.spy(GroupSchema, 'load') mocker.spy(Ltree, '_validate') mocker.spy(SimpleString, '_validate') Group('testing', 'with a short description') assert GroupSchema.load.called assert Ltree._validate.call_args[0][1] == 'testing' assert SimpleString._validate.call_args[0][1] == 'with a short description'
def insert_dev_data(config_path: str) -> None: """Load the app config and insert some "starter" data for a dev version.""" session = get_session_from_config(config_path) session.add_all([ User('TestUser', 'password'), Group( 'testing', 'An automatically created group to use for testing purposes', ), ]) session.commit()
def test_is_subgroup_backwards(): """Ensure is_subgroup_of() returns False if called "backwards".""" assert not Group("test").is_subgroup_of(Group("test.subgroup"))
def test_is_subgroup_equal(): """Ensure is_subgroup_of() returns False with the same groups.""" group = Group("testing") assert not group.is_subgroup_of(group)
def test_is_subgroup(): """Ensure is_subgroup_of() works with an obvious subgroup.""" assert Group("test.subgroup").is_subgroup_of(Group("test"))
def test_uppercase_letters_fixed(): """Ensure a group path gets uppercase letters converted to lowercase.""" assert Group("Comp.Lang.C").path == "comp.lang.c"