Example #1
0
 def setUp(self):
     super(TestRegistrationHandler, self).setUp()
     set_up_db()
     app = Application([('/', RegistrationHandler)],
                       cookie_secret=settings.COOKIE_SECRET)
     req = Mock()
     req.cookies = {}
     self.registration_handler = RegistrationHandler(app, req)
Example #2
0
class TestRegistrationHandler(unittest.TestCase):

    def setUp(self):
        app = Application([('/', RegistrationHandler)])
        req = Mock()
        self.auth_handler = RegistrationHandler(app, req)

        # Mock out the User and Session object
        self.MockUser = Mock()
        self.MockCommit = Mock()
        self.MockRollback = Mock()

        self.patches = []
        self.patches.append(patch.object(authserver, 'User', self.MockUser))
        self.patches.append(patch('elixir_models.db.commit', self.MockCommit))
        self.patches.append(patch('elixir_models.db.rollback', self.MockRollback))

        for p in self.patches:
            p.start()

    def tearDown(self):
        for p in self.patches:
            p.stop()

    def test_register_user(self):
        self.MockUser.select().where().exists = Mock(return_value=False)

        # Test
        result = self.auth_handler.register_user("username", "password", "email")

        self.assertEqual(result, self.MockUser())

    def test_register_user_already_existing(self):
        from sqlalchemy.exc import IntegrityError
        self.MockCommit.side_effect = IntegrityError(None, None, None, None)

        # Test
        result = self.auth_handler.register_user("username", "password", "email")

        self.assertFalse(result)
Example #3
0
class TestRegistrationHandler(unittest.TestCase):

    def setUp(self):
        app = Application([('/', RegistrationHandler)])
        req = Mock()
        self.auth_handler = RegistrationHandler(app, req)

        # Mock out the User and Session object
        self.MockSession = Mock()
        self.MockUser = Mock()

        self.patches = []
        self.patches.append(patch.object(authserver, 'User', self.MockUser))
        self.patches.append(patch('authserver.session', self.MockSession))

        for p in self.patches:
            p.start()

    def tearDown(self):
        for p in self.patches:
            p.stop()

    def test_register_user(self):
        # Test
        result = self.auth_handler.register_user("username", "password", "email")

        self.assertEqual(result, self.MockUser())
        self.assertEqual(self.MockSession.commit.call_count, 1)
        self.assertEqual(self.MockSession.rollback.call_count, 0)

    def test_register_user_already_existing(self):
        from sqlalchemy.exc import IntegrityError
        self.MockSession.commit.side_effect = IntegrityError(None, None, None, None)

        # Test
        result = self.auth_handler.register_user("username", "password", "email")

        self.assertFalse(result)
        self.assertEqual(self.MockSession.commit.call_count, 1)
        self.assertEqual(self.MockSession.rollback.call_count, 1)
Example #4
0
    def setUp(self):
        app = Application([('/', RegistrationHandler)])
        req = Mock()
        self.auth_handler = RegistrationHandler(app, req)

        # Mock out the User and Session object
        self.MockSession = Mock()
        self.MockUser = Mock()

        self.patches = []
        self.patches.append(patch.object(authserver, 'User', self.MockUser))
        self.patches.append(patch('authserver.session', self.MockSession))

        for p in self.patches:
            p.start()
Example #5
0
    def setUp(self):
        app = Application([('/', RegistrationHandler)])
        req = Mock()
        self.auth_handler = RegistrationHandler(app, req)

        # Mock out the User and Session object
        self.MockUser = Mock()
        self.MockCommit = Mock()
        self.MockRollback = Mock()

        self.patches = []
        self.patches.append(patch.object(authserver, 'User', self.MockUser))
        self.patches.append(patch('elixir_models.db.commit', self.MockCommit))
        self.patches.append(patch('elixir_models.db.rollback', self.MockRollback))

        for p in self.patches:
            p.start()