コード例 #1
0
def test_password_common():
    """ Common passwords aren't allowed. """
    with pytest.raises(ValueError):
        logins.Logins(password='******')

    inst = logins.Logins()
    with pytest.raises(ValueError):
        inst.password = '******'
コード例 #2
0
def test_password_blank():
    """ Blank passwords aren't allowed. """
    with pytest.raises(ValueError):
        logins.Logins(password='')

    inst = logins.Logins()
    with pytest.raises(ValueError):
        inst.password = ''
コード例 #3
0
def test_password_short():
    """ Short passwords aren't allowed. """
    with pytest.raises(ValueError):
        logins.Logins(password='******')

    inst = logins.Logins()
    with pytest.raises(ValueError):
        inst.password = '******'

    inst.password = '******'
コード例 #4
0
def test_password_email():
    """ Passwords aren't allowed to match email. """
    with pytest.raises(ValueError):
        logins.Logins(password='******', email='[email protected]')

    inst1 = logins.Logins(email='[email protected]')
    with pytest.raises(ValueError):
        inst1.password = '******'

    inst2 = logins.Logins(password='******')
    with pytest.raises(ValueError):
        inst2.email = '[email protected]'
コード例 #5
0
def test_password_setter():
    """ Getting and setting password. """
    inst1 = logins.Logins()

    passwd1 = '9738a470-6693-4968-81b2-2778a494a030'
    assert inst1._password is None  # pylint: disable=protected-access
    inst1.password = passwd1
    assert inst1._password is not None  # pylint: disable=protected-access
    assert inst1.password != passwd1

    passwd2 = 'bd2b45ec-1a4a-41c3-8d2a-6bdf456b4175'
    inst2 = logins.Logins(password=passwd2)
    assert inst2._password is not None  # pylint: disable=protected-access
    assert inst2.password != passwd2
コード例 #6
0
def testdata(createdb):
    """
    Create the necessary test data for this module.
    :param models.db createdb: pytest fixture for database module
    :return list(str): List of tokens for AuthenticationTokens created.
    """
    createdb.connect()
    tokens = []
    data = ({
        'full_name': '24c6e6a4 960f1df1d6ac',
        'email': '[email protected]',
        'password': '******'
    }, {
        'full_name': '8ad0c442 92728ef096a4',
        'email': '[email protected]',
        'password': '******'
    }, {
        'full_name': '5a61452b 2830a9f8c820',
        'email': '[email protected]',
        'password': '******'
    })
    for record in data:
        profile = profiles.Profiles(full_name=record['full_name'],
                                    email=record['email'])
        login = logins.Logins(password=record['password'], profile=profile)
        token = autht.AuthenticationTokens(login=login)
        createdb.add(token)
        tokens.append(token.token)

    createdb.commit()
    createdb.close()
    return tokens
コード例 #7
0
def testdata(createdb):
    """
    Create the necessary test data for this module.
    :param models.db createdb: pytest fixture for database module
    :return list(str): List of tokens for ForgotPasswordTokens created.
    """
    createdb.connect()
    tokens = []
    data = ({
        'full_name': 'df8df1a4 11162dcd40bb',
        'email': '[email protected]',
        'password': '******'
    }, {
        'full_name': '61c12783 784c62ee9e56',
        'email': '[email protected]',
        'password': '******'
    }, {
        'full_name': '8e75abf5 4ab60edd1e23',
        'email': '[email protected]',
        'password': '******'
    })
    for record in data:
        profile = profiles.Profiles(full_name=record['full_name'],
                                    email=record['email'])
        login = logins.Logins(password=record['password'], profile=profile)
        token = fpt.ForgotPasswordTokens(login=login)
        createdb.add(token)
        tokens.append(token.token)

    createdb.commit()
    createdb.close()
    return tokens
コード例 #8
0
def test_password_validation():
    """ Getting and setting password. """
    passwd = '99e7988b-578c-4edb-8a28-4831cd47617a'
    inst = logins.Logins(password=passwd)

    assert inst.is_valid_password('') is False
    assert inst.is_valid_password(passwd[:10]) is False
    assert inst.is_valid_password(passwd) is True
コード例 #9
0
def test_login_relation(dbsession):  # pylint: disable=unused-argument
    """ Profiles can have a Logins relation. """
    profile = profiles.Profiles(full_name='4176898b 61d515c6e423',
                                email='[email protected]')
    login = logins.Logins(password='******')

    assert profile.login is None
    profile.login = login
    assert profile.login == login
コード例 #10
0
def test_required_fields(dbsession):
    """
    Logins must have a password and an email address.
    :param sqlalchemy.orm.session.Session dbsession: pytest fixture for database session
    """
    login = logins.Logins(password='******', email='[email protected]')
    login.save()

    # Profile associated with email is missing.
    with pytest.raises(IntegrityError):
        dbsession.commit()
コード例 #11
0
def test_required_email(dbsession):
    """
    Logins must have a password and an email address.
    :param sqlalchemy.orm.session.Session dbsession: pytest fixture for database session
    """
    login = logins.Logins(password='******')
    login.save()

    # email is blank
    with pytest.raises(IntegrityError):
        dbsession.commit()
コード例 #12
0
def test_person_relation(dbsession):  # pylint: disable=unused-argument
    """
    Profiles can have a Logins relation.
    :param sqlalchemy.orm.session.Session dbsession: pytest fixture for database session
    """
    profile = profiles.Profiles(full_name='a142cb03 6b369b6bfd1e', email='[email protected]')
    login = logins.Logins(password='******')

    assert login.profile is None
    login.profile = profile
    assert login.profile == profile
コード例 #13
0
def test_required_password(dbsession):
    """
    Logins must have a password and an email address.
    :param sqlalchemy.orm.session.Session dbsession: pytest fixture for database session
    """
    login = logins.Logins(email='[email protected]')
    login.save()

    # password is blank
    with pytest.raises(IntegrityError):
        dbsession.commit()
コード例 #14
0
def test_required_fields_blank(dbsession):
    """
    Logins must have a password and an email address.
    :param sqlalchemy.orm.session.Session dbsession: pytest fixture for database session
    """
    login = logins.Logins()
    login.save()

    # password and email are blank
    with pytest.raises(IntegrityError):
        dbsession.commit()
コード例 #15
0
def test_required_profile_missing(dbsession):
    """
    Login profile not existing is an error.
    :param sqlalchemy.orm.session.Session dbsession: pytest fixture for database session
    """
    login = logins.Logins(password='******', email='[email protected]')
    profile = profiles.Profiles(full_name='5f904cb5 3dad7d54b87b', email='[email protected]')
    login.save()  # Profile isn't saved because we didn't use the relationship attribute.
    assert login.email == profile.email

    with pytest.raises(IntegrityError):
        dbsession.commit()
コード例 #16
0
def test_required_profile(dbsession):
    """
    Logins profile must exist.
    :param sqlalchemy.orm.session.Session dbsession: pytest fixture for database session
    """
    login = logins.Logins(password='******')
    profile = profiles.Profiles(full_name='9ca81d5c 42badee25c18', email='[email protected]')
    login.profile = profile
    login.save()
    assert login.email is None

    dbsession.commit()
    assert login.email == profile.email
コード例 #17
0
def test_required_login(dbsession):
    """
    Tokens must have a login relation (which must have a profile relation).
    :param sqlalchemy.orm.session.Session dbsession: pytest fixture for database session
    """
    profile = profiles.Profiles(full_name='f4e074b5 15503d6feef0',
                                email='[email protected]')
    login = logins.Logins(password='******',
                          profile=profile)
    token = fpt.ForgotPasswordTokens(login=login)
    token.save()
    assert token.login_id is None

    dbsession.commit()
    assert token.login == login
コード例 #18
0
def test_required_login(dbsession):
    """
    Tokens must have a login relation (which must have a profile relation).
    :param sqlalchemy.orm.session.Session dbsession: pytest fixture for database session
    """
    profile = profiles.Profiles(full_name='3ea4a6ec 7bb15fa70936',
                                email='[email protected]')
    login = logins.Logins(password='******',
                          profile=profile)
    token = autht.AuthenticationTokens(login=login)
    token.save()
    assert token.login_id is None

    dbsession.commit()
    assert token.login == login
コード例 #19
0
def test_get_by_email(dbsession):  # pylint: disable=unused-argument
    """
    Create Logins, and then fetch them by email address.
    :param sqlalchemy.orm.session.Session dbsession: pytest fixture for database session
    """
    login = logins.Logins(password='******')
    login.profile = profiles.Profiles(full_name='fb000987 2e2cb7f95b6a', email='[email protected]')

    # Unsaved logins shouldn't be found
    assert logins.Logins.get_by_email('[email protected]') is None

    login.save()

    # Now it can be found.
    assert logins.Logins.get_by_email('[email protected]') is login
コード例 #20
0
def test_get_by_token(dbsession):  # pylint: disable=unused-argument
    """
    Create AuthenticationTokens.
    :param sqlalchemy.orm.session.Session dbsession: pytest fixture for database session
    """
    profile = profiles.Profiles(full_name='8afcc6f0 34086c4efc7c',
                                email='[email protected]')
    login = logins.Logins(password='******',
                          profile=profile)
    token = autht.AuthenticationTokens(login=login)

    # Unsaved tokens shouldn't be found
    assert autht.AuthenticationTokens.get_by_token(token.token) is None

    token.save()

    # Now it can be found.
    assert autht.AuthenticationTokens.get_by_token(token.token) is token
コード例 #21
0
def test_get_by_token(dbsession):  # pylint: disable=unused-argument
    """
    Create ForgotPasswordTokens.
    :param sqlalchemy.orm.session.Session dbsession: pytest fixture for database session
    """
    profile = profiles.Profiles(full_name='7aad753a bf457864c212',
                                email='[email protected]')
    login = logins.Logins(password='******',
                          profile=profile)
    token = fpt.ForgotPasswordTokens(login=login)

    # Unsaved tokens shouldn't be found
    assert fpt.ForgotPasswordTokens.get_by_token(token.token) is None

    token.save()

    # Now it can be found.
    assert fpt.ForgotPasswordTokens.get_by_token(token.token) is token
コード例 #22
0
def testdata(createdb):
    """
    Create the necessary test data for this module.
    :param models.db createdb: pytest fixture for database module
    :return list(str): List of emails for Logins created.
    """
    createdb.connect()
    emails = []
    data = ({'full_name': 'f4d94fd2 c10282e403d0', 'email': '[email protected]',
             'password': '******'},
            {'full_name': 'e3391b5 586ecf591968', 'email': '[email protected]',
             'password': '******'})
    for record in data:
        profile = profiles.Profiles(full_name=record['full_name'], email=record['email'])
        login = logins.Logins(password=record['password'], profile=profile)
        createdb.add(login)
        emails.append(profile.email)

    createdb.commit()
    createdb.close()
    return emails