def test_get_user(name, password, email, default_domain):
    with UnitOfWork(session=get_session().session) as do:
        new_user = do.new_user(name, password, email, default_domain)

    with UnitOfWork(session=get_session().session) as do:
        found_user = do.get_user(new_user.id)
    assert found_user.id == new_user.id
def test_get_user_ids_returns_all_user_ids_in_a_domain_namespace():
    emails = ['*****@*****.**', '*****@*****.**']
    for email in emails:
        with UnitOfWork(session=get_session().session) as do:
            _ = do.new_user("Name", VALID_PASSWORDS[0], email)
    with UnitOfWork(session=get_session().session) as do:
        users = do.get_user_ids()
    assert len(users) == len(emails)
def test_add_domain_to_user(domain):
    with UnitOfWork(session=get_session().session) as do:
        new_user = do.new_user("Name", VALID_PASSWORDS[0], "*****@*****.**")

    with UnitOfWork(session=get_session().session) as do:
        modified_user = do.add_domain_to_user(new_user.id, domain)

    assert domain in modified_user.domains
def test_discard_user(name, password, email):
    with UnitOfWork(session=get_session().session) as do:
        new_user = do.new_user(name, password, email)

    user_id = new_user.id

    with UnitOfWork(session=get_session().session) as do:
        do.discard_user(new_user.id)

    with UnitOfWork(session=get_session().session) as do:
        users = do.get_user_ids('public.example.com')
    assert user_id not in users
def test_change_password(initial_password, changed_password):
    with UnitOfWork(session=get_session().session) as do:
        new_user = do.new_user("Name", initial_password, "*****@*****.**")

    initial_version = new_user.version

    with UnitOfWork(session=get_session().session) as do:
        do.change_password(new_user.id, changed_password)

    with UnitOfWork(session=get_session().session) as do:
        modified_user = do.get_user(new_user.id)

    assert modified_user.version > initial_version
def test_new_user(name, password, email, default_domain):
    with UnitOfWork(session=get_session().session) as do:
        new_user = do.new_user(name, password, email, default_domain)
    assert new_user.name == name
    assert new_user.email == email
    assert new_user.password == SANITIZED_PASSWORD
    assert new_user.default_domain == default_domain
    assert default_domain in new_user.domains
def test_modify_user(initial_name, changed_name, password, initial_email,
                     changed_email, initial_default_domain,
                     changed_default_domain):
    with UnitOfWork(session=get_session().session) as do:
        new_user = do.new_user(initial_name, password, initial_email,
                               initial_default_domain)

    with UnitOfWork(session=get_session().session) as do:
        do.modify_user(new_user.id, 'name', changed_name)

    with UnitOfWork(session=get_session().session) as do:
        do.modify_user(new_user.id, 'email', changed_email)

    with UnitOfWork(session=get_session().session) as do:
        do.modify_user(new_user.id, 'default_domain', changed_default_domain)

    with UnitOfWork(session=get_session().session) as do:
        modified_user = do.get_user(new_user.id)

    assert modified_user.name == changed_name
    assert modified_user.email == changed_email
    assert modified_user.default_domain == changed_default_domain
Beispiel #8
0
    def __init__(self, **kwargs):
        session = get_session().session
        entity_active_record_strategy = SQLAlchemyActiveRecordStrategy(
            active_record_class=IntegerSequencedItemRecord, session=session)
        snapshot_active_record_strategy = SQLAlchemyActiveRecordStrategy(
            active_record_class=SnapshotRecord, session=session)
        super(UnitOfWork, self).__init__(
            entity_active_record_strategy=entity_active_record_strategy,
            snapshot_active_record_strategy=snapshot_active_record_strategy,
            **kwargs)

        self.snapshot_strategy = EventSourcedSnapshotStrategy(
            event_store=self.snapshot_event_store)

        self.users = EventSourcedRepository(
            event_store=self.entity_event_store,
            mutator=User._mutate,
            snapshot_strategy=self.snapshot_strategy)

        self.snapshotting_policy = KanbanSnapshottingPolicy(
            repository=self.users)
def test_get_non_existent_user_raises_entity_not_found_error(user_id):
    with raises(EntityNotFoundError):
        with UnitOfWork(session=get_session().session) as do:
            do.get_user(user_id)