theAbdoSabbagh / UnlimitedGPT

An unofficial Python wrapper for OpenAI's ChatGPT API
https://pypi.org/project/UnlimitedGPT/
GNU General Public License v3.0
346 stars 43 forks source link

Unit Tests #9

Closed Uranium2 closed 1 year ago

Uranium2 commented 1 year ago

Would be great for you to make unittests for your module. Develop new features without breaking old ones, or ones you forgot you developed.

import unittest
from dotenv import load_dotenv
from unlimitedgpt import ChatGPT

class UnlimitedGPTRegressionTest(unittest.TestCase):
    def setUp(self):
        self.session_token_1 = os.getenv("SESSION_TOKEN_1")
        self.session_token_2 = os.getenv("SESSION_TOKEN_2")
        self.api = ChatGPT(self.session_token_1 )

    def test_send_message(self):
        message = self.api.send_message("Hello World")
        # Add assertions to check the response

    def test_get_session_data(self):
        session_data = self.api.get_session_data()
        # Add assertions to check the session data

    def test_toggle_chat_history(self):
        self.api.toggle_chat_history(False)
        # Add assertions to check if chat history is toggled off

        self.api.toggle_chat_history(True)
        # Add assertions to check if chat history is toggled on again

    def test_switch_theme(self):
        self.api.switch_theme("DARK")
        # Add assertions to check if theme is switched to DARK

    def test_clear_conversations(self):
        self.api.clear_conversations()
        # Add assertions to check if conversations are cleared

    def test_reset_conversation(self):
        self.api.reset_conversation()
        # Add assertions to check if conversation is reset

    def test_switch_conversation(self):
        self.api.switch_conversation("conversation-id")
        # Add assertions to check if conversation is switched to "conversation-id"

    def test_switch_account(self):
        self.api.switch_account(self.session_token_2 )
        # Add assertions to check if account is switched to "new-session-token"

    def test_logout(self):
        self.api.logout()
        # Add assertions to check if logout is successful

if __name__ == "__main__":
    unittest.main()

You can make a template env file to store your tokens template.env

 SESSION_TOKEN_1=your_first_session_token_here
SESSION_TOKEN_2=your_second_session_token_here

You can push template.env to the repo. People could rename it to .env (also need to add .env to .gitignore) and put their tokens for testing

theAbdoSabbagh commented 1 year ago

Brilliant idea, very useful one too, thank you! Could you make a PR for this? I can't code for now as I'm going to be busy with some IRL stuff.