Exemplo n.º 1
0
def test_authenticate_raises_wrong_password():
    "User.authenticate raises User.WrongPassword when password is wrong"

    User.create(name=u'Auth User',
                username=u'john.doe',
                email=u'*****@*****.**',
                password=u'my-password')

    assert_raises(User.WrongPassword,
                  User.authenticate, '*****@*****.**', 'wrong-password')
Exemplo n.º 2
0
def test_can_authenticate_user():
    "User.authenticate(email, passwd) should fetch a valid user"

    User.create(name=u'Foo Bar',
                username=u'john.doe',
                email=u'*****@*****.**',
                password=u'my-password')


    user = User.authenticate('*****@*****.**', 'my-password')
    assert_equals(user.name, 'Foo Bar')
    assert_equals(user.email, '*****@*****.**')
Exemplo n.º 3
0
def test_can_create_user():
    "User.create() creates and persists a new user"
    User.create(name=u'John Doe',
                username=u'john.doe',
                email=u'*****@*****.**',
                password=u'some-password')

    session = meta.get_session()
    users = session.query(User).all()
    assert_equals(len(users), 1)
    user = users[0]
    assert_equals(user.name, u'John Doe')
    assert_equals(user.email, u'*****@*****.**')
Exemplo n.º 4
0
def test_new_user_has_hashed_password():
    "User.create() creates a user with hashed password"
    User.create(name=u'John Doe',
                username=u'john.doe',
                email=u'*****@*****.**',
                password=u'some-password')

    session = meta.get_session()
    user = session.query(User).first()

    concatenated = '[email protected]+some-password'
    expected_password = "******" % sha.new(concatenated).hexdigest()

    assert_equals(user.password, expected_password)
Exemplo n.º 5
0
def test_user_can_get_gravatar_url():
    "User().get_gravatar() should fetch user's gravatar"

    user = User.create(name=u'John Doe',
                       username=u'john.doe',
                       email=u'*****@*****.**',
                       password=u'some-password')

    email_md5 = md5.new('*****@*****.**').hexdigest()
    expected_url = u'http://www.gravatar.com/avatar/%s.jpg' % email_md5
    assert_equals(user.get_gravatar(), expected_url)
Exemplo n.º 6
0
def test_can_add_keys_to_user():
    "User().add_public_key(description, content) adds a ssh pub key to user"

    user = User.create(name=u'SSH User',
                       username=u'john.doe',
                       email=u'*****@*****.**',
                       password=u'my-password')

    user.add_public_key("laptop key", "ssh-rsa aAbBcCdD1e2f3g4h5I== [email protected]")
    assert_equals(user.keys[0].description, "laptop key")
    assert_equals(user.keys[0].data, "ssh-rsa aAbBcCdD1e2f3g4h5I== [email protected]")
Exemplo n.º 7
0
def test_user_get_repository_dir():
    "User().get_repository_dir() give full path to user's root dir"

    user = User.create(name=u'Auth User',
                       username=u'john.doe',
                       email=u'*****@*****.**',
                       password=u'my-password')

    expected = abspath(join(repository_base, "john.doe"))
    got = user.get_repository_dir()
    assert_equals(got, expected)
Exemplo n.º 8
0
def test_user_can_be_deleted():
    "User().delete() should delete a user"
    session = get_session()

    assert session.query(User).count() is 0
    user = User.create(name=u'some-name',
                       username=u'some-username',
                       email=u'*****@*****.**',
                       password=u'some-password')
    assert session.query(User).count() is 1
    user.delete()
    assert session.query(User).count() is 0
Exemplo n.º 9
0
def test_create_will_make_a_repository_dir_for_user():
    "User.create() makes a repository base dir for user"

    user = User.create(name=u'Auth User',
                       username=u'john.doe',
                       email=u'*****@*****.**',
                       password=u'my-password')

    expected = join(repository_base, "john.doe")
    msg = "After creating a user of uuid %s, the path %s " \
          "should exist in filesystem" % (user.uuid, expected)
    assert exists(expected), msg
Exemplo n.º 10
0
def test_can_create_a_repository_to_user():
    "User().create_repository(name, description) adds a new git repository to user's account"

    user = User.create(name=u'Hacker #1',
                       username=u'hacker.no1',
                       email=u'*****@*****.**',
                       password=u'my-password')

    repo = user.create_repository("repo-one", "repo one")

    assert_equals(repo.name, "repo-one")
    assert_equals(repo.description, "repo one")

    assert_equals(user.repositories[0].name, "repo-one")
    assert_equals(user.repositories[0].description, "repo one")
Exemplo n.º 11
0
def test_can_create_repository():
    "GitRepository.create() creates and persists a new repository"

    first = User.create(name=u'First Repo',
                          username=u'first.repo',
                          email=u'*****@*****.**',
                          password=u'some-passwd')

    GitRepository.create(name=u'Hacklab Contributions',
                         description=u'Some description...',
                         owner=first,
                         slug=u"hacklab-contrib")

    session = meta.get_session()
    repositories = session.query(GitRepository).all()
    assert_equals(len(repositories), 1)
    repository = repositories[0]
    assert_equals(repository.name, u'Hacklab Contributions')
    assert_equals(repository.description, u'Some description...')
    assert_equals(repository.slug, u'hacklab-contrib')
    assert_equals(repository.owner.username, 'first.repo')