def test_can_add_user_key(self): user = SaUserFactory.create() key = yield self.storage.add_user_key(user, 'ssh-rsa some-random-key heynemann@mypc') expect(key.id).to_be_greater_than(0) expect(key.user_id).to_equal(user.id) expect(key.public_key).to_equal('some-random-key')
def test_create_user_already_exists(self): user = SaUserFactory.create() response = self.fetch( '/user/new', method='POST', body='name=%s' % user.name ) expect(response.code).to_equal(409) expect(response.reason).to_be_like('User already exists')
def test_can_create_user(self): user = SaUserFactory.create() expect(user.id).to_be_greater_than(0) loaded = self.db.query(User).filter(User.name == user.name).one() expect(loaded).not_to_be_null() expect(loaded.id).to_equal(user.id) expect(loaded.name).to_equal(user.name) expect(loaded.slug).to_equal(user.slug)
def test_can_create_key(self): user = SaUserFactory.create() key = SaKeyFactory.create(user=user) loaded = self.db.query(Key).filter(Key.id == key.id).one() expect(loaded).not_to_be_null() expect(loaded.id).to_equal(key.id) expect(loaded.public_key).to_equal(key.public_key) self.db.refresh(user) expect(user.keys).to_length(1) expect(user.keys[0].id).to_equal(key.id)
def test_add_user_key(self): user = SaUserFactory.create() name = user.name key = """ssh-rsa DAAAB3NzaC1yc2EAAAADAQABAAABAQD5eYo2ZM8Inuf73WqA3C8HCPjb1DUWLs4z2x+eCY3VHc7oZZmVguB/kAGxUmIpxvMKtNeOicHIfUvJ6UIibl2vagFn0+t8KooUovbPugxFSEeuYPKcqhA5U3hlAGbYa2HS5Z+2pImLidQuCnv07vO7cQFshEndsX11ff4ZjrpvI+LoidzZkxeOwGkMTrkmMNrvT4u26OBQGPHJU0JVq3e4X1FjrdSQ2lJHZ5qxdyZn84pypyPctc2WaNeHKV0h4UeqRK7VLCjpkrNXpZlFj0JO3Yetac2bkl6qpR+FuUPUdxeTb2QmdHFi6MN1yfX+YBSTxMWniC/gQDRQ8PYYTAvV heynemann@someserver""" response = self.fetch( '/users/%s/add-key' % user.slug, method='POST', body='key=%s' % quote(key) ) expect(response.code).to_equal(200) expect(response.body).to_be_like('OK') user = yield self.storage.get_user_by_name(name) expect(user).not_to_be_null() expect(user.keys).to_length(1) expect(user.keys[0].public_key).to_equal(key.split(' ')[1])
def test_can_get_user_by_slug(self): user = SaUserFactory.create() loaded = yield self.storage.get_user_by_slug(user.slug) expect(loaded.id).to_equal(user.id)