Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
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
Ejemplo n.º 3
0
    def activate_via_key(self, fixture):
        system_account = fixture.new_system_account(email='*****@*****.**',
                                                    activated=False)
        activation_request = VerifyEmailRequest(
            email=system_account.email,
            subject_config='accounts.activation_subject',
            email_config='accounts.activation_email')
        Session.add(activation_request)
        deferred_activation = ActivateAccount(
            system_account=system_account, requirements=[activation_request])
        Session.add(deferred_activation)
        account_management_interface = fixture.account_management_interface

        # Case where there is an email mismatch
        account_management_interface.email = '*****@*****.**'
        account_management_interface.secret = activation_request.as_secret_key(
        )
        with expected(InvalidEmailException, test=lambda e: vassert(e.commit)):
            account_management_interface.verify_email()
        vassert(not system_account.registration_activated)

        # Case where there is a key mismatch
        account_management_interface.email = system_account.email
        account_management_interface.secret = 'a key that is invalid'
        with expected(KeyException):
            account_management_interface.verify_email()
        vassert(not system_account.registration_activated)

        # Case where it works
        vassert(not system_account.registration_activated)
        vassert(not system_account.account_enabled)
        vassert(not system_account.registration_date)
        account_management_interface.email = system_account.email
        account_management_interface.secret = activation_request.as_secret_key(
        )
        account_management_interface.verify_email()
        vassert(system_account.registration_activated)
        vassert(system_account.account_enabled)
        assert_recent(system_account.registration_date)
        vassert(
            Session.query(VerifyEmailRequest).filter_by(
                id=activation_request.id).count() == 0)
Ejemplo n.º 4
0
def test_last_commit_time(git_fixture):
    fixture = git_fixture
    git = Git(fixture.git_directory.name)
    git.commit('testing', allow_empty=True)

    assert_recent(git.last_commit_time)
Ejemplo n.º 5
0
    def last_commit_time(self, fixture):
        bzr = Bzr(fixture.bzr_directory.name)
        bzr.commit('testing', unchanged=True)

        assert_recent( bzr.last_commit_time )