示例#1
0
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()
示例#2
0
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])))
示例#3
0
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
示例#4
0
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()
示例#5
0
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"
示例#6
0
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'
示例#7
0
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()
示例#8
0
def test_is_subgroup_backwards():
    """Ensure is_subgroup_of() returns False if called "backwards"."""
    assert not Group("test").is_subgroup_of(Group("test.subgroup"))
示例#9
0
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)
示例#10
0
def test_is_subgroup():
    """Ensure is_subgroup_of() works with an obvious subgroup."""
    assert Group("test.subgroup").is_subgroup_of(Group("test"))
示例#11
0
def test_uppercase_letters_fixed():
    """Ensure a group path gets uppercase letters converted to lowercase."""
    assert Group("Comp.Lang.C").path == "comp.lang.c"