import os
from unittest import TestCase
from tiingo.wsclient import TiingoWebsocketClient
from tiingo.exceptions import MissingRequiredArgumentError

class TestRestClientWithSession(TestCase):
    def setUp(self):

        def msg_cb(msg):
            print(msg)

        self.cb=msg_cb

        self.config =  {
            'eventName':'subscribe',
            'authorization':os.getenv("TIINGO_API_KEY"),
            #see https://api.tiingo.com/documentation/websockets/iex > Request for more info
            'eventData': { 
                'thresholdLevel':5
            }
        }

    # test for missing or incorrectly supplied endpoints
    def test_missing_or_wrong_endpoint(self):
        with self.assertRaises(AttributeError) as ex:
            TiingoWebsocketClient(config=self.config,on_msg_cb=self.cb)
        self.assertTrue(type(ex.exception)==AttributeError)

        with self.assertRaises(AttributeError) as ex:
             TiingoWebsocketClient(config=self.config,endpoint='wq',on_msg_cb=self.cb)
        self.assertTrue(type(ex.exception)==AttributeError)

    # test for missing callback argument    
    def test_missing_msg_cb(self):
        with self.assertRaises(MissingRequiredArgumentError) as ex:
            TiingoWebsocketClient(config=self.config,endpoint='iex')
        self.assertTrue(type(ex.exception)==MissingRequiredArgumentError)

    # test for missing API keys in config dict and in os env
    def test_missing_api_key(self):
        del os.environ['TIINGO_API_KEY']
        with self.assertRaises(RuntimeError) as ex:
            TiingoWebsocketClient(config={},endpoint='iex',on_msg_cb=self.cb)
        self.assertTrue(type(ex.exception)==RuntimeError)

@@ -32,16 +32,21 @@
 TestCase
+,mock
 %0Afrom ti
@@ -1479,24 +1479,88 @@
     
-del os.environ%5B'
+with mock.patch.dict(os.environ, %7B%7D, clear=True): #clear env vars including the 
 TIIN
@@ -1573,19 +1573,18 @@
 _KEY
-'%5D
 %0A
+ 
         
 with
@@ -1571,32 +1571,35 @@
 PI_KEY%0A         
+   
 with self.assert
@@ -1618,32 +1618,36 @@
 meError) as ex:%0A
+    
             Tiin
@@ -1700,32 +1700,36 @@
 msg_cb=self.cb)%0A
+    
         self.ass

use unittest.mock to remove TIINGO_API_KEY