Repository: terminusdb/terminusdb-client-python
Issue: client.set_db should also check for connection

client.set_db should also check for connection before accessing self._account

Changed files:
terminusdb_client/tests/integration_tests/test_client.py, terminusdb_client/tests/test_woqlClient.py, terminusdb_client/woqlclient/woqlClient.py

diff --git a/terminusdb_client/tests/integration_tests/test_client.py b/terminusdb_client/tests/integration_tests/test_client.py
index 28cb2d3..5076c5d 100644
--- a/terminusdb_client/tests/integration_tests/test_client.py
+++ b/terminusdb_client/tests/integration_tests/test_client.py
@@ -23,7 +23,9 @@ def test_happy_path(docker_url):
     # test adding doctype
     WOQLQuery().doctype("Station").execute(client)
     first_commit = client._get_current_commit()
+    target_commit = client._get_target_commit(1)
     assert first_commit != init_commit
+    assert target_commit == init_commit.split("_")[-1]
     commit_history = client.get_commit_history()
     assert len(commit_history) == 2
     assert len(client.get_commit_history(2)) == 2
@@ -36,15 +38,24 @@ def test_happy_path(docker_url):
     assert "test_happy_path" not in client.list_databases()
 
 
-def _generate_csv():
-    file_path = "employee_file.csv"
-    with open(file_path, mode="w") as employee_file:
-        employee_writer = csv.writer(
-            employee_file, delimiter=",", quotechar='"', quoting=csv.QUOTE_MINIMAL
-        )
-        employee_writer.writerow(["John Smith", "Accounting", "November"])
-        employee_writer.writerow(["Erica Meyers", "IT", "March"])
-    return file_path
+def _generate_csv(option):
+    if option == 1:
+        file_path = "employee_file.csv"
+        with open(file_path, mode="w") as employee_file:
+            employee_writer = csv.writer(
+                employee_file, delimiter=",", quotechar='"', quoting=csv.QUOTE_MINIMAL
+            )
+            employee_writer.writerow(["John Smith", "Accounting", "November"])
+            employee_writer.writerow(["Erica Meyers", "IT", "March"])
+        return file_path
+    else:
+        file_path = "employee_file.csv"
+        with open(file_path, mode="w") as employee_file:
+            employee_writer = csv.writer(
+                employee_file, delimiter=",", quotechar='"', quoting=csv.QUOTE_MINIMAL
+            )
+            employee_writer.writerow(["Cow Duck", "Marketing", "April"])
+        return file_path
 
 
 def _file_clean_up(filename):
@@ -63,14 +74,19 @@ def test_csv_handeling(docker_url):
     client._get_current_commit()
     assert client._db == "test_csv"
     assert "test_csv" in client.list_databases()
-    csv_file_path = _generate_csv()  # create testing csv
+    csv_file_path = _generate_csv(1)  # create testing csv
     try:
         client.insert_csv(csv_file_path)
         client.get_csv(csv_file_path, csv_output_name="new_" + csv_file_path)
         assert filecmp.cmp(csv_file_path, "new_" + csv_file_path)
+        csv_file_path = _generate_csv(2)
+        client.update_csv(csv_file_path)
+        client.get_csv(csv_file_path, csv_output_name="update_" + csv_file_path)
+        assert not filecmp.cmp("new_" + csv_file_path, "update_" + csv_file_path)
     finally:
         _file_clean_up(csv_file_path)
         _file_clean_up("new_" + csv_file_path)
+        _file_clean_up("update_" + csv_file_path)
 
 
 def test_create_graph(docker_url):
diff --git a/terminusdb_client/tests/test_woqlClient.py b/terminusdb_client/tests/test_woqlClient.py
index 6c7202b..edebb4c 100644
--- a/terminusdb_client/tests/test_woqlClient.py
+++ b/terminusdb_client/tests/test_woqlClient.py
@@ -264,3 +264,47 @@ def test_rollback(mocked_requests):
     woql_client.connect(user="admin", account="admin", key="root")
     with pytest.raises(NotImplementedError):
         woql_client.rollback()
+
+
+def test_copy_client():
+    woql_client = WOQLClient("http://localhost:6363")
+    copy_client = woql_client.copy()
+    assert id(woql_client) != copy_client
+
+
+@mock.patch("requests.get", side_effect=mocked_requests_get)
+def test_basic_auth(mocked_requests):
+    woql_client = WOQLClient("http://localhost:6363")
+    result = woql_client.basic_auth()
+    assert result is None
+    woql_client.connect(user="admin", account="admin", key="root")
+    result = woql_client.basic_auth()
+    assert result == "admin:root"
+    assert woql_client.account() == "admin"
+    assert woql_client.user() == "admin"
+
+
+@mock.patch("requests.get", side_effect=mocked_requests_get)
+def test_remote_auth(mocked_requests):
+    woql_client = WOQLClient("http://localhost:6363")
+    result = woql_client.remote_auth()
+    assert result is None
+    woql_client.connect(user="admin", account="admin", key="root")
+    result = woql_client.remote_auth()
+    assert result is None
+    auth_setting = {"type": "jwt", "user": "admin", "key": "<token>"}
+    woql_client.remote_auth(auth_setting)
+    result = woql_client.remote_auth()
+    assert result == auth_setting
+
+
+@mock.patch("requests.get", side_effect=mocked_requests_get)
+def test_set_db(mocked_requests):
+    woql_client = WOQLClient("http://localhost:6363")
+    with pytest.raises(InterfaceError):
+        woql_client.set_db("my_db")
+    woql_client.connect()
+    woql_client.set_db("my_db")
+    assert woql_client._db == "my_db"
+    assert woql_client.db() == "my_db"
+    assert woql_client.repo() == "local"
diff --git a/terminusdb_client/woqlclient/woqlClient.py b/terminusdb_client/woqlclient/woqlClient.py
index 121d482..f9cceb5 100644
--- a/terminusdb_client/woqlclient/woqlClient.py
+++ b/terminusdb_client/woqlclient/woqlClient.py
@@ -353,6 +353,8 @@ class WOQLClient:
         >>> client.remote_auth({"type": "jwt", "user": "admin", "key": "<token>"})
         {'type': 'jwt', 'user': 'admin', 'key': '<token>'}
         """
+        if not self._connected:
+            return None
         if auth_info is not None:
             self._remote_auth = auth_info
         return self._remote_auth
@@ -378,6 +380,7 @@ class WOQLClient:
         >>> client.set_db("database1")
         'database1'
         """
+        self._check_connection(check_db=False)
 
         if account is None:
             account = self._account
@@ -981,7 +984,7 @@ class WOQLClient:
         graph_type: Optional[str] = "instance",
         graph_id: Optional[str] = "main",
     ) -> None:
-        """Updates the contents of the specified graph with the triples encoded in turtle format Replaces the entire graph contents
+        """Updates the contents of the specified graph with the csv. Replaces the entire file contents
 
         Parameters
         ----------
@@ -1022,7 +1025,7 @@ class WOQLClient:
         graph_type: Optional[str] = "instance",
         graph_id: Optional[str] = "main",
     ) -> None:
-        """Inserts into the specified graph with the triples encoded in turtle format.
+        """Inserts into the specified graph with the csv.
 
         Parameters
         ----------