示例#1
0
    def testInviteCreatesUser(self):
        """We should get a new user when inviting something"""
        me = User()
        me.username = u'me'
        me.email = u'me.com'
        me.invite_ct = 2
        you = me.invite(u'you.com')

        self.assertEqual(
            'you.com',
            you.username,
            'The email should be the username')
        self.assertEqual(
            'you.com',
            you.email,
            'The email should be the email')
        self.assertTrue(
            len(you.api_key),
            'The api key should be generated for the user')
        self.assertFalse(
            you.activated,
            'The new user should not be activated')
        self.assertEqual(
            1,
            me.invite_ct,
            'My invite count should be deprecated')
示例#2
0
 def testHasNoInvites(self):
     """Verify that if the user has no invites, they can't invite"""
     u = User()
     u.invite_ct = 0
     self.assertFalse(u.has_invites(), 'User should have no invites')
     self.assertFalse(u.invite('*****@*****.**'),
                      'Should not be able to invite a user')
示例#3
0
 def testHasNoInvites(self):
     """Verify that if the user has no invites, they can't invite"""
     u = User()
     u.invite_ct = 0
     self.assertFalse(u.has_invites(), 'User should have no invites')
     self.assertFalse(
         u.invite('*****@*****.**'), 'Should not be able to invite a user')
示例#4
0
    def test_unique_ct(self):
        """Verify that our unique count method is working"""
        ct = 5
        common = 'testing.com'
        users = []
        for i in range(ct):
            user = User()
            user.username = gen_random_word(10)
            DBSession.add(user)
            users.append(user)

        for i in range(ct - 2):
            b = Bmark(url=gen_random_word(12), username=users[i].username)
            DBSession.add(b)

        # Add in our dupes
        c = Bmark(url=common, username=users[3].username)
        DBSession.add(c)
        DBSession.flush()

        d = Bmark(url=common, username=users[4].username)
        DBSession.add(d)
        DBSession.flush()

        ct = BmarkMgr.count(distinct=True)
        eq_(4, ct, 'We should have a total of 4: ' + str(ct))
示例#5
0
    def test_unique_ct(self):
        """Verify that our unique count method is working"""
        ct = 5
        common = 'testing.com'
        users = []
        for i in range(ct):
            user = User()
            user.username = gen_random_word(10)
            DBSession.add(user)
            users.append(user)

        for i in range(ct - 2):
            b = Bmark(
                url=gen_random_word(12),
                username=users[i].username
            )
            DBSession.add(b)

        # Add in our dupes
        c = Bmark(
            url=common,
            username=users[3].username
        )
        DBSession.add(c)
        DBSession.flush()

        d = Bmark(
            url=common,
            username=users[4].username
        )
        DBSession.add(d)
        DBSession.flush()

        ct = BmarkMgr.count(distinct=True)
        eq_(4, ct, 'We should have a total of 4: ' + str(ct))
示例#6
0
    def test_password_set(self):
        """Make sure we get the proper hashed password"""
        tst = User()
        tst.password = self.test_password

        eq_(len(tst.password), 60,
            "Hashed should be 60 char long: " + tst.password)
        eq_('$2a$', tst.password[:4],
            "Hash should start with the right complexity: " + tst.password[:4])
示例#7
0
    def test_password_set(self):
        """Make sure we get the proper hashed password"""
        tst = User()
        tst.password = self.test_password

        eq_(len(tst.password), 60,
            "Hashed should be 60 char long: " + tst.password)
        eq_('$2a$', tst.password[:4],
            "Hash should start with the right complexity: " + tst.password[:4])
示例#8
0
    def test_password_match(self):
        """Try to match a given hash"""

        tst = User()
        tst._password = self.test_hash

        ok_(tst._password == self.test_hash, "Setting should have hash")
        ok_(tst.password == self.test_hash, "Getting should have hash")
        ok_(tst.validate_password(self.test_password),
            "The password should pass against the given hash: " + tst.password)
示例#9
0
    def test_password_match(self):
        """Try to match a given hash"""

        tst = User()
        tst._password = self.test_hash

        ok_(tst._password == self.test_hash, "Setting should have hash")
        ok_(tst.password == self.test_hash, "Getting should have hash")
        ok_(tst.validate_password(self.test_password),
            "The password should pass against the given hash: " + tst.password)
示例#10
0
文件: api.py 项目: xuanhan863/Bookie
def new_user(request):
    """Add a new user to the system manually."""
    rdict = request.params

    u = User()

    u.username = unicode(rdict.get('username'))
    u.email = unicode(rdict.get('email'))
    passwd = get_random_word(8)
    u.password = passwd
    u.activated = True
    u.is_admin = False
    u.api_key = User.gen_api_key()

    try:
        DBSession.add(u)
        DBSession.flush()
        # We need to return the password since the admin added the user
        # manually.  This is only time we should have/give the original
        # password.
        ret = dict(u)
        ret['random_pass'] = passwd
        return ret

    except IntegrityError, exc:
        # We might try to add a user that already exists.
        LOG.error(exc)
        request.response.status_int = 400
        return {
            'error': 'Bad Request: User exists.',
        }
示例#11
0
def _new_user(args):
    """Handle adding a new user to the system.

    If you don't include the required info, it will prompt you for it

    """
    if not args.username:
        args.username = raw_input('username? ')

    if not args.email:
        args.email = raw_input('email address? ')

    if not args.username or not args.email:
        raise Exception('Must supply a username and email address')

    import transaction
    _init_sql(args)
    from bookie.models import DBSession
    sess = DBSession()

    u = User()
    u.username = unicode(args.username)
    passwd = get_random_word(8)
    u.password = passwd
    u.email = unicode(args.email)
    u.activated = True
    u.is_admin = False
    u.api_key = User.gen_api_key()

    print dict(u)
    print passwd

    sess.add(u)
    sess.flush()
    transaction.commit()
示例#12
0
def make_user(username=None):
    """Generate a fake user to test against."""
    user = User()

    if not username:
        username = random_string(10)

    user.username = username

    DBSession.add(user)
    DBSession.flush()
    return user
示例#13
0
文件: factory.py 项目: vackup/Bookie
def make_user(username=None):
    """Generate a fake user to test against."""
    user = User()

    if not username:
        username = random_string(10)

    user.username = username

    DBSession.add(user)
    DBSession.flush()
    return user
示例#14
0
    def testInitialUserInactivated(self):
        """A new user signup should be a deactivated user"""
        u = User()
        u.email = gen_random_word(10)
        DBSession.add(u)

        eq_(False, u.activated,
            'A new signup should start out deactivated by default')
        ok_(u.activation.code is not None,
            'A new signup should start out as deactivated')
        eq_('signup', u.activation.created_by,
            'This is a new signup, so mark is as thus')
示例#15
0
    def test_total_ct(self):
        """Verify that our total count method is working"""
        ct = 5
        user = User()
        user.username = gen_random_word(10)
        DBSession.add(user)
        for i in range(ct):
            b = Bmark(url=gen_random_word(12), username=user.username)
            b.hash_id = gen_random_word(3)
            DBSession.add(b)

        ct = BmarkMgr.count()
        eq_(5, ct, 'We should have a total of 5: ' + str(ct))
示例#16
0
def new_user(request):
    """Add a new user to the system manually."""
    rdict = request.params

    u = User()

    u.username = unicode(rdict.get('username'))
    u.email = unicode(rdict.get('email'))
    passwd = get_random_word(8)
    u.password = passwd
    u.activated = True
    u.is_admin = False
    u.api_key = User.gen_api_key()

    try:
        DBSession.add(u)
        DBSession.flush()
        # We need to return the password since the admin added the user
        # manually.  This is only time we should have/give the original
        # password.
        ret = dict(u)
        ret['random_pass'] = passwd
        return _api_response(request, ret)

    except IntegrityError, exc:
        # We might try to add a user that already exists.
        LOG.error(exc)
        request.response.status_int = 400
        return _api_response(request, {
            'error': 'Bad Request: User exists.',
        })
示例#17
0
文件: admin.py 项目: aldeka/Bookie
def new_user(username, email):
    """Add new user function, pass username, email

    :param username: string of new user
    :param email: string of new email

    """
    require('hosts', provided_by=[sample])
    require('ini', provided_by=[sample])

    parse_ini(env["ini_file"])

    import transaction
    from bookie.models import initialize_sql
    initialize_sql(dict(env.ini.items('app:main')))

    from bookie.models import DBSession
    from bookie.models.auth import get_random_word, User
    sess = DBSession()

    u = User()
    u.username = unicode(username)
    passwd = get_random_word(8)
    u.password = passwd
    u.email = unicode(email)
    u.activated = True
    u.is_admin = False
    u.api_key = User.gen_api_key()

    print dict(u)
    print passwd

    sess.add(u)
    sess.flush()
    transaction.commit()
示例#18
0
    def test_activation_delete(self):
        """Make sure removing an activation does not remove a user."""
        tst = User()
        tst.username = gen_random_word(10)
        tst.activation = Activation('signup')
        DBSession.add(tst)
        DBSession.flush()

        DBSession.delete(tst.activation)

        users = UserMgr.get_list()

        # We still have the admin user as well so the count is two.
        eq_(2, len(users),
            'We should have a total of 2 users still: ' + str(len(users)))
示例#19
0
    def test_total_ct(self):
        """Verify that our total count method is working"""
        ct = 5
        user = User()
        user.username = gen_random_word(10)
        DBSession.add(user)
        for i in range(ct):
            b = Bmark(
                url=gen_random_word(12),
                username=user.username
            )
            b.hash_id = gen_random_word(3)
            DBSession.add(b)

        ct = BmarkMgr.count()
        eq_(5, ct, 'We should have a total of 5: ' + str(ct))
示例#20
0
    def setUp(self):
        """Populate the DB with a couple of testing records"""
        trans = transaction.begin()
        user = User()
        user.username = gen_random_word(10)
        DBSession.add(user)

        for i in range(3):
            url = gen_random_word(12)
            b = self.__create_bookmark(url, user.username)
            DBSession.add(b)

        # add bookmark with duplicate url
        b = self.__create_bookmark(url, gen_random_word(10))
        DBSession.add(b)

        trans.commit()
示例#21
0
    def setUp(self):
        """Populate the DB with a couple of testing records"""
        trans = transaction.begin()
        user = User()
        user.username = gen_random_word(10)
        DBSession.add(user)

        for i in range(3):
            url = gen_random_word(12)
            b = self.__create_bookmark(url, user.username)
            DBSession.add(b)

        # add bookmark with duplicate url
        b = self.__create_bookmark(url, gen_random_word(10))
        DBSession.add(b)

        trans.commit()
示例#22
0
    def test_activation_delete(self):
        """Make sure removing an activation does not remove a user."""
        tst = User()
        tst.username = gen_random_word(10)
        tst.activation = Activation(u'signup')
        DBSession.add(tst)
        DBSession.flush()

        DBSession.delete(tst.activation)

        users = UserMgr.get_list()

        # We still have the admin user as well so the count is two.
        self.assertEqual(
            2,
            len(users),
            'We should have a total of 2 users still: ' + str(len(users)))
示例#23
0
    def test_activation_cascade(self):
        """Removing a user cascades the activations as well."""
        tst = User()
        tst.username = gen_random_word(10)
        tst.activation = Activation('signup')
        DBSession.add(tst)
        DBSession.flush()

        DBSession.delete(tst)

        users = UserMgr.get_list()

        # We still have the admin user as well so the count is one.
        eq_(1, len(users),
            'We should have a total of 1 user still: ' + str(len(users)))

        activations = DBSession.query(Activation).all()
        eq_(0, len(activations), 'There should be no activations left')
示例#24
0
    def test_activation_cascade(self):
        """Removing a user cascades the activations as well."""
        tst = User()
        tst.username = gen_random_word(10)
        tst.activation = Activation('signup')
        DBSession.add(tst)
        DBSession.flush()

        DBSession.delete(tst)

        users = UserMgr.get_list()

        # We still have the admin user as well so the count is one.
        eq_(
            1,
            len(users),
            'We should have a total of 1 user still: ' + str(len(users)))

        activations = DBSession.query(Activation).all()
        eq_(0, len(activations), 'There should be no activations left')
def upgrade(migrate_engine):
    """Need to add a col to the users for their api key"""
    meta = MetaData(migrate_engine)

    users = Table('users', meta, autoload=True)
    api_key = Column('api_key', Unicode(12))
    create_column(api_key, users)

    # now add an api key for our admin user
    migrate_engine.execute(users.update().\
                           where(users.c.username==u'admin').\
                           values(api_key=User.gen_api_key()))
示例#26
0
    def test_per_user(self):
        """We should only get a pair of results for this single user"""
        ct = 5
        common = 'testing.com'
        user = User()
        user.username = gen_random_word(10)
        DBSession.add(user)

        usercommon = User()
        usercommon.username = common
        DBSession.add(usercommon)

        for i in range(ct - 2):
            b = Bmark(url=gen_random_word(12), username=user.username)
            DBSession.add(b)

        # add in our dupes
        c = Bmark(
            url=gen_random_word(10),
            username=usercommon.username,
        )
        DBSession.add(c)
        DBSession.flush()

        d = Bmark(
            url=gen_random_word(10),
            username=usercommon.username,
        )
        DBSession.add(d)
        DBSession.flush()

        ct = BmarkMgr.count(username=usercommon.username)
        eq_(2, ct, 'We should have a total of 2: ' + str(ct))
示例#27
0
    def test_per_user(self):
        """We should only get a pair of results for this single user"""
        ct = 5
        common = 'testing.com'
        user = User()
        user.username = gen_random_word(10)
        DBSession.add(user)

        usercommon = User()
        usercommon.username = common
        DBSession.add(usercommon)

        for i in range(ct - 2):
            b = Bmark(
                url=gen_random_word(12),
                username=user.username
            )
            DBSession.add(b)

        # add in our dupes
        c = Bmark(
            url=gen_random_word(10),
            username=usercommon.username,
        )
        DBSession.add(c)
        DBSession.flush()

        d = Bmark(
            url=gen_random_word(10),
            username=usercommon.username,
        )
        DBSession.add(d)
        DBSession.flush()

        ct = BmarkMgr.count(username=usercommon.username)
        eq_(2, ct, 'We should have a total of 2: ' + str(ct))
示例#28
0
    def testInviteCreatesUser(self):
        """We should get a new user when inviting something"""
        me = User()
        me.username = '******'
        me.email = 'me.com'
        me.invite_ct = 2
        you = me.invite('you.com')

        eq_('you.com', you.username, 'The email should be the username')
        eq_('you.com', you.email, 'The email should be the email')
        ok_(len(you.api_key), 'The api key should be generated for the user')
        ok_(not you.activated, 'The new user should not be activated')
        eq_(1, me.invite_ct, 'My invite count should be deprecated')