コード例 #1
0
def test_verify_email_change(party_account_fixture):
    fixture = party_account_fixture

    system_account = fixture.system_account
    new_email = '*****@*****.**'
    change_email_action = ChangeAccountEmail(system_account, new_email)
    Session.add(change_email_action)
    request = change_email_action.verify_email_request
    account_management_interface = fixture.account_management_interface

    # Case where there is a password mismatch
    account_management_interface.email = new_email
    account_management_interface.password = '******'
    account_management_interface.secret = request.as_secret_key()
    with expected(InvalidPasswordException, test=assert_is_set_to_commit):
        account_management_interface.verify_email()
    assert system_account.email != new_email

    # Case where there is a key mismatch
    account_management_interface.email = new_email
    account_management_interface.password = system_account.password
    account_management_interface.secret = 'invalid key'
    with expected(KeyException):
        account_management_interface.verify_email()
    assert system_account.email != new_email

    # Case where it works
    assert system_account.email != new_email
    account_management_interface.email = new_email
    account_management_interface.password = system_account.password
    account_management_interface.secret = request.as_secret_key()
    account_management_interface.verify_email()
    assert Session.query(VerifyEmailRequest).filter_by(
        id=request.id).count() == 0
    assert system_account.email == new_email
コード例 #2
0
ファイル: test_party.py プロジェクト: diopib/reahl
    def create_account(self, fixture):
        login_email = '*****@*****.**'
        mailer_stub = fixture.mailer
        #        EmailAndPasswordSystemAccount.mailer = mailer_stub
        account_management_interface = fixture.account_management_interface
        account_management_interface.email = login_email

        # Case where the email does not exist as system_account, but as pending new email
        mailer_stub.reset()
        other_system_account = fixture.system_account
        new_email = '*****@*****.**'
        Session.add(ChangeAccountEmail(other_system_account, new_email))

        with expected(NotUniqueException):
            account_management_interface.email = new_email
            account_management_interface.register()

        vassert(not mailer_stub.mail_sent)
        fixture.system_control.rollback()

        # Case where it all works
        vassert(Session.query(ActivateAccount).count() == 0)
        account_management_interface.email = login_email
        system_account = account_management_interface.register()
        [activation_action] = Session.query(ActivateAccount).filter_by(
            system_account=system_account).all()
        activation_request = activation_action.requirements[0]

        vassert(mailer_stub.mail_sent)
        vassert(system_account.email == account_management_interface.email)
        # FIXME: These are those dubious tests where the assert just repeats the implementation verbatim
        vassert(system_account.password_md5 == hashlib.md5(
            account_management_interface.password.encode('utf-8')).hexdigest())
        vassert( system_account.apache_digest == hashlib.md5(('%s:%s:%s' %\
                                              (account_management_interface.email,'',account_management_interface.password)).encode('utf-8')).hexdigest() )
        assert_recent(activation_action.deadline - timedelta(days=10))
        vassert(not system_account.registration_activated)
        vassert(not system_account.account_enabled)
        vassert(not system_account.registration_date)

        vassert(isinstance(system_account, EmailAndPasswordSystemAccount))
        vassert(system_account.owner is None)
        vassert(system_account.id)

        # Case where the email name exists
        mailer_stub.reset()
        with expected(NotUniqueException):
            account_management_interface.register()
        vassert(not mailer_stub.mail_sent)
コード例 #3
0
def test_create_account(reahl_system_fixture, party_account_fixture):
    fixture = party_account_fixture

    login_email = '*****@*****.**'
    mailer_stub = fixture.mailer
    # EmailAndPasswordSystemAccount.mailer = mailer_stub
    account_management_interface = fixture.account_management_interface
    account_management_interface.email = login_email

    # Case where the email does not exist as system_account, but as pending new email
    mailer_stub.reset()
    other_system_account = fixture.system_account
    new_email = '*****@*****.**'
    Session.add(ChangeAccountEmail(other_system_account, new_email))

    with expected(NotUniqueException):
        account_management_interface.email = new_email
        account_management_interface.register()

    assert not mailer_stub.mail_sent
    reahl_system_fixture.system_control.rollback()

    # Case where it all works
    assert Session.query(ActivateAccount).count() == 0
    account_management_interface.email = login_email
    system_account = account_management_interface.register()
    [activation_action] = Session.query(ActivateAccount).filter_by(
        system_account=system_account).all()
    activation_request = activation_action.requirements[0]

    assert mailer_stub.mail_sent
    assert system_account.email == account_management_interface.email
    assert_recent(activation_action.deadline - timedelta(days=10))
    assert not system_account.registration_activated
    assert not system_account.account_enabled
    assert not system_account.registration_date

    assert isinstance(system_account, EmailAndPasswordSystemAccount)
    assert system_account.owner is None
    assert system_account.id

    # Case where the email name exists
    mailer_stub.reset()
    with expected(NotUniqueException):
        account_management_interface.register()
    assert not mailer_stub.mail_sent