def test_find_or_new(self): user1 = users.find_or_new(self.test_user_id) new_user_id = str(ObjectId()) user2 = users.find_or_new(new_user_id) user3 = users.find(new_user_id) self.assertIsNotNone(user1) self.assertIsNotNone(user2) self.assertIsNone(user3) self.assertEqual(user1.name, self.test_user_name) self.assertEqual(user2.name, '(new unnamed)')
def _find_or_create_user(self, user_id, username): user = users.find_or_new(user_id) user.name = username users.save(user) return user