def __preRegister(self, userEmail): from dao.user import User from main import userclient if User.isRegistered(userEmail): User.fromEmail(userEmail).setStudy(self.clientName) else: pendingDoc = { 'user_email': userEmail, 'study': self.clientName, 'last_update': datetime.now() } # Should I do insert or upsert here? If a user has pre-registered for one # study and then pre-registers for another study before registering, do we # want to throw an error or just update silently? # Update silently for now writeResult = get_pending_signup_db().update( {'user_email': userEmail}, pendingDoc, upsert=True) print 'in __preRegister, writeResult = %s' % writeResult if 'err' in writeResult and writeResult['err'] is not None: e = Exception() e.code = writeResult['err'][0]["code"] e.msg = writeResult['err'][0]["errmsg"] raise e return (get_pending_signup_db().find({ 'study': self.clientName }).count(), userclient.countForStudy(self.clientName))
def testChangeUpdateTs(self): from datetime import datetime, timedelta user = User.register('*****@*****.**') self.assertTrue(User.isRegistered('*****@*****.**')) user.changeUpdateTs(timedelta(days = -20)) self.assertEqual((datetime.now() - user.getUpdateTS()).days, 20)
def testChangeUpdateTs(self): from datetime import datetime, timedelta user = User.register('*****@*****.**') self.assertTrue(User.isRegistered('*****@*****.**')) user.changeUpdateTs(timedelta(days=-20)) self.assertEqual((datetime.now() - user.getUpdateTS()).days, 20)
def testSetClientSpecificFields(self): user = User.register('*****@*****.**') self.assertTrue(User.isRegistered('*****@*****.**')) # Check that the field doesn't exist initially self.assertTrue(user.getProfile().get('test_field', 'blank'), 'blank') # Check that a simple value update works user.setClientSpecificProfileFields({'test_field': 'something beautiful'}) self.assertTrue(user.getProfile().get('test_field', 'blank'), 'something beautiful') # Check that a data structure update works user.setClientSpecificProfileFields({'test_field': {'something': 'beautiful'}}) self.assertTrue(user.getProfile().get('test_field', 'blank'), {'something': 'beautiful'})
def testGetFirstStudy(self): user = User.register('*****@*****.**') self.assertTrue(User.isRegistered('*****@*****.**')) client = Client("testclient") client.update(createKey = False) common.makeValid(client) (resultPre, resultReg) = client.preRegister("this_is_the_super_secret_id", "*****@*****.**") self.assertEqual(resultPre, 0) self.assertEqual(resultReg, 1) user = User.fromEmail('*****@*****.**') self.assertEqual(user.getFirstStudy(), 'testclient')
def testGetFirstStudy(self): user = User.register('*****@*****.**') self.assertTrue(User.isRegistered('*****@*****.**')) client = Client("testclient") client.update(createKey=False) common.makeValid(client) (resultPre, resultReg) = client.preRegister("this_is_the_super_secret_id", "*****@*****.**") self.assertEqual(resultPre, 0) self.assertEqual(resultReg, 1) user = User.fromEmail('*****@*****.**') self.assertEqual(user.getFirstStudy(), 'testclient')
def testSetClientSpecificFields(self): user = User.register('*****@*****.**') self.assertTrue(User.isRegistered('*****@*****.**')) # Check that the field doesn't exist initially self.assertTrue(user.getProfile().get('test_field', 'blank'), 'blank') # Check that a simple value update works user.setClientSpecificProfileFields( {'test_field': 'something beautiful'}) self.assertTrue(user.getProfile().get('test_field', 'blank'), 'something beautiful') # Check that a data structure update works user.setClientSpecificProfileFields( {'test_field': { 'something': 'beautiful' }}) self.assertTrue(user.getProfile().get('test_field', 'blank'), {'something': 'beautiful'})
def __preRegister(self, userEmail): from dao.user import User from main import userclient if User.isRegistered(userEmail): User.fromEmail(userEmail).setStudy(self.clientName) else: pendingDoc = { 'user_email': userEmail, 'study': self.clientName, 'last_update': datetime.now()} # Should I do insert or upsert here? If a user has pre-registered for one # study and then pre-registers for another study before registering, do we # want to throw an error or just update silently? # Update silently for now writeResult = get_pending_signup_db().update({'user_email': userEmail}, pendingDoc, upsert=True) print 'in __preRegister, writeResult = %s' % writeResult if 'err' in writeResult and writeResult['err'] is not None: e = Exception() e.code = writeResult['err'][0]["code"] e.msg = writeResult['err'][0]["errmsg"] raise e return (get_pending_signup_db().find({'study': self.clientName}).count(), userclient.countForStudy(self.clientName))
def testIsRegistered(self): user = User.register('*****@*****.**') self.assertTrue(User.isRegistered('*****@*****.**'))
def testIsNotRegistered(self): self.assertFalse(User.isRegistered('*****@*****.**'))
def testUnregister(self): user = User.register('*****@*****.**') self.assertTrue(User.isRegistered('*****@*****.**')) User.unregister('*****@*****.**') self.assertFalse(User.isRegistered('*****@*****.**'))
def testIsRegistered(self): user = User.register('*****@*****.**') self.assertTrue(User.isRegistered('*****@*****.**'))
def testIsNotRegistered(self): self.assertFalse(User.isRegistered('*****@*****.**'))
def testUnregister(self): user = User.register('*****@*****.**') self.assertTrue(User.isRegistered('*****@*****.**')) User.unregister('*****@*****.**') self.assertFalse(User.isRegistered('*****@*****.**'))