from nose.tools import assert_true, assert_false, assert_equal, \
                        assert_list_equal, raises
import datajoint as dj
from . import CONN_INFO
from pymysql.err import OperationalError


class TestTLS:

    @staticmethod
    def test_secure_connection():
        result = dj.conn(reset=True, **CONN_INFO).query(
                "SHOW STATUS LIKE 'Ssl_cipher';").fetchone()[1]
        assert_true(len(result) == 0)

    @staticmethod
    def test_insecure_connection():
        result = dj.conn(use_tls=False, reset=True, **CONN_INFO).query(
                "SHOW STATUS LIKE 'Ssl_cipher';").fetchone()[1]
        assert_equal(result, '')

    @staticmethod
    @raises(OperationalError)
    def test_reject_insecure():
        result = dj.conn(
                CONN_INFO['host'], user='djssl', password='djssl',
                use_tls=False, reset=True
                ).query("SHOW STATUS LIKE 'Ssl_cipher';").fetchone()[1]

@@ -424,10 +424,9 @@
 lt) 
-==
+%3E
  0)%0A
@@ -733,33 +733,24 @@
 e():%0A       
- result =
  dj.conn(%0A  
@@ -747,20 +747,16 @@
 j.conn(%0A
-    
         
@@ -822,20 +822,16 @@
         
-    
 use_tls=
@@ -848,24 +848,16 @@
 et=True%0A
-        
         

fix TLS test