Ejemplo n.º 1
0
    def test_generate_session_key_creates_user(self, db_mock):
        """generate_session_key creates a new user if not found"""
        repo = Repository()
        db_instance = db_mock.return_value

        db_instance.get_user_info_by_google_id.return_value = None
        db_instance.new_session.return_value = "1234"

        self.assertEquals(repo.generate_session_key({"id": 123}), "1234")

        db_instance.new_session.assert_called_once()
        db_instance.create_user.assert_called_once()
Ejemplo n.º 2
0
    def test_generate_session_key(self, db_mock):
        """generate_session_key returns a session key if user was found"""
        repo = Repository()

        db_instance = db_mock.return_value

        db_instance.get_user_info_by_google_id.return_value = (1, {"id": 12345})
        db_instance.new_session.return_value = "1234abcd"
        
        self.assertEquals(repo.generate_session_key({"id": 12345}), "1234abcd")

        db_instance.new_session.assert_called_once()
        db_instance.create_user.assert_not_called()