tplinkrouterc6u 5.0.3__py3-none-any.whl → 5.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- test/{test_client.py → test_client_c6u.py} +2 -1
- test/test_client_ex.py +339 -0
- test/test_client_mr.py +365 -0
- test/test_client_xdr.py +536 -0
- tplinkrouterc6u/__init__.py +16 -12
- tplinkrouterc6u/client/__init__.py +1 -0
- tplinkrouterc6u/client/c1200.py +102 -0
- tplinkrouterc6u/client/c5400x.py +109 -0
- tplinkrouterc6u/client/c6u.py +436 -0
- tplinkrouterc6u/client/c6v4.py +38 -0
- tplinkrouterc6u/client/deco.py +177 -0
- tplinkrouterc6u/client/ex.py +295 -0
- tplinkrouterc6u/client/mr.py +712 -0
- tplinkrouterc6u/client/xdr.py +263 -0
- tplinkrouterc6u/client_abstract.py +48 -0
- tplinkrouterc6u/common/__init__.py +1 -0
- tplinkrouterc6u/{dataclass.py → common/dataclass.py} +40 -1
- tplinkrouterc6u/{package_enum.py → common/package_enum.py} +5 -0
- tplinkrouterc6u/provider.py +39 -0
- {tplinkrouterc6u-5.0.3.dist-info → tplinkrouterc6u-5.2.0.dist-info}/METADATA +52 -2
- tplinkrouterc6u-5.2.0.dist-info/RECORD +30 -0
- {tplinkrouterc6u-5.0.3.dist-info → tplinkrouterc6u-5.2.0.dist-info}/WHEEL +1 -1
- tplinkrouterc6u/client.py +0 -1451
- tplinkrouterc6u-5.0.3.dist-info/RECORD +0 -17
- /tplinkrouterc6u/{encryption.py → common/encryption.py} +0 -0
- /tplinkrouterc6u/{exception.py → common/exception.py} +0 -0
- /tplinkrouterc6u/{helper.py → common/helper.py} +0 -0
- {tplinkrouterc6u-5.0.3.dist-info → tplinkrouterc6u-5.2.0.dist-info}/LICENSE +0 -0
- {tplinkrouterc6u-5.0.3.dist-info → tplinkrouterc6u-5.2.0.dist-info}/top_level.txt +0 -0
test/test_client_mr.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
from unittest import main, TestCase
|
|
2
2
|
from macaddress import EUI48
|
|
3
3
|
from ipaddress import IPv4Address
|
|
4
|
+
from datetime import datetime
|
|
4
5
|
from tplinkrouterc6u import (
|
|
5
6
|
TPLinkMRClient,
|
|
6
7
|
Connection,
|
|
@@ -10,6 +11,11 @@ from tplinkrouterc6u import (
|
|
|
10
11
|
IPv4Reservation,
|
|
11
12
|
IPv4DHCPLease,
|
|
12
13
|
IPv4Status,
|
|
14
|
+
ClientError,
|
|
15
|
+
SMS,
|
|
16
|
+
LTEStatus,
|
|
17
|
+
VPNStatus,
|
|
18
|
+
VPN,
|
|
13
19
|
)
|
|
14
20
|
|
|
15
21
|
|
|
@@ -679,6 +685,365 @@ DNSServers=0.0.0.0,0.0.0.0
|
|
|
679
685
|
self.assertEqual(check_data, ('2\r\n[LTE_SMS_SENDNEWMSG#0,0,0,0,0,0#0,0,0,0,0,0]0,3\r\nindex=1\r\n'
|
|
680
686
|
'to=534324724234\r\ntextContent=test sms\r\n'))
|
|
681
687
|
|
|
688
|
+
def test_send_ussd(self) -> None:
|
|
689
|
+
responses = ['''[error]0
|
|
690
|
+
|
|
691
|
+
''', '''[0,0,0,0,0,0]0
|
|
692
|
+
sessionStatus=1
|
|
693
|
+
sendResult=1
|
|
694
|
+
response=
|
|
695
|
+
ussdStatus=0
|
|
696
|
+
[error]0
|
|
697
|
+
|
|
698
|
+
''', '''[0,0,0,0,0,0]0
|
|
699
|
+
sessionStatus=0
|
|
700
|
+
sendResult=1
|
|
701
|
+
response=some text
|
|
702
|
+
ussdStatus=1
|
|
703
|
+
[error]0
|
|
704
|
+
|
|
705
|
+
''']
|
|
706
|
+
|
|
707
|
+
check_url = []
|
|
708
|
+
check_data = []
|
|
709
|
+
|
|
710
|
+
class TPLinkMRClientTest(TPLinkMRClient):
|
|
711
|
+
def _request(self, url, method='POST', data_str=None, encrypt=False):
|
|
712
|
+
nonlocal check_url, check_data
|
|
713
|
+
check_url.append(url)
|
|
714
|
+
check_data.append(data_str)
|
|
715
|
+
return 200, responses.pop(0)
|
|
716
|
+
|
|
717
|
+
client = TPLinkMRClientTest('', '')
|
|
718
|
+
|
|
719
|
+
self.assertEqual('some text', client.send_ussd('534324724234'))
|
|
720
|
+
|
|
721
|
+
self.assertIn('http:///cgi_gdpr?_=', check_url.pop(0))
|
|
722
|
+
self.assertEqual(check_data.pop(0),
|
|
723
|
+
'2\r\n[LTE_USSD#0,0,0,0,0,0#0,0,0,0,0,0]0,2\r\naction=1\r\nreqContent=534324724234\r\n')
|
|
724
|
+
|
|
725
|
+
self.assertIn('http:///cgi_gdpr?_=', check_url.pop(0))
|
|
726
|
+
self.assertEqual(check_data.pop(0),
|
|
727
|
+
('1\r\n[LTE_USSD#0,0,0,0,0,0#0,0,0,0,0,0]0,4\r\nsessionStatus\r\n'
|
|
728
|
+
'sendResult\r\nresponse\r\nussdStatus\r\n'))
|
|
729
|
+
|
|
730
|
+
def test_send_ussd_error(self) -> None:
|
|
731
|
+
responses = ['''[error]0
|
|
732
|
+
|
|
733
|
+
''', '''[0,0,0,0,0,0]0
|
|
734
|
+
sessionStatus=1
|
|
735
|
+
sendResult=1
|
|
736
|
+
response=
|
|
737
|
+
ussdStatus=0
|
|
738
|
+
[error]0
|
|
739
|
+
|
|
740
|
+
''', '''[0,0,0,0,0,0]0
|
|
741
|
+
sessionStatus=0
|
|
742
|
+
sendResult=1
|
|
743
|
+
response=
|
|
744
|
+
ussdStatus=2
|
|
745
|
+
[error]0
|
|
746
|
+
|
|
747
|
+
''']
|
|
748
|
+
|
|
749
|
+
check_url = []
|
|
750
|
+
check_data = []
|
|
751
|
+
|
|
752
|
+
class TPLinkMRClientTest(TPLinkMRClient):
|
|
753
|
+
def _request(self, url, method='POST', data_str=None, encrypt=False):
|
|
754
|
+
nonlocal check_url, check_data
|
|
755
|
+
check_url.append(url)
|
|
756
|
+
check_data.append(data_str)
|
|
757
|
+
return 200, responses.pop(0)
|
|
758
|
+
|
|
759
|
+
client = TPLinkMRClientTest('', '')
|
|
760
|
+
|
|
761
|
+
with self.assertRaises(ClientError) as context:
|
|
762
|
+
client.send_ussd('534324724234')
|
|
763
|
+
|
|
764
|
+
self.assertTrue('Cannot send USSD!' in str(context.exception))
|
|
765
|
+
|
|
766
|
+
self.assertIn('http:///cgi_gdpr?_=', check_url.pop(0))
|
|
767
|
+
self.assertEqual(check_data.pop(0),
|
|
768
|
+
'2\r\n[LTE_USSD#0,0,0,0,0,0#0,0,0,0,0,0]0,2\r\naction=1\r\nreqContent=534324724234\r\n')
|
|
769
|
+
|
|
770
|
+
self.assertIn('http:///cgi_gdpr?_=', check_url.pop(0))
|
|
771
|
+
self.assertEqual(check_data.pop(0),
|
|
772
|
+
('1\r\n[LTE_USSD#0,0,0,0,0,0#0,0,0,0,0,0]0,4\r\nsessionStatus\r\nsendResult\r\n'
|
|
773
|
+
'response\r\nussdStatus\r\n'))
|
|
774
|
+
|
|
775
|
+
def test_get_sms(self) -> None:
|
|
776
|
+
response = '''[1,0,0,0,0,0]1
|
|
777
|
+
index=3
|
|
778
|
+
from=sender1
|
|
779
|
+
content=text second
|
|
780
|
+
receivedTime=2024-11-15 22:28:09
|
|
781
|
+
unread=1
|
|
782
|
+
[2,0,0,0,0,0]1
|
|
783
|
+
index=2
|
|
784
|
+
from=sender2
|
|
785
|
+
content=text first
|
|
786
|
+
receivedTime=2024-11-15 22:23:59
|
|
787
|
+
unread=0
|
|
788
|
+
[error]0
|
|
789
|
+
'''
|
|
790
|
+
|
|
791
|
+
class TPLinkMRClientTest(TPLinkMRClient):
|
|
792
|
+
def _request(self, url, method='POST', data_str=None, encrypt=False):
|
|
793
|
+
return 200, response
|
|
794
|
+
|
|
795
|
+
client = TPLinkMRClientTest('', '')
|
|
796
|
+
messages = client.get_sms()
|
|
797
|
+
|
|
798
|
+
self.assertEqual(len(messages), 2)
|
|
799
|
+
self.assertIsInstance(messages[0], SMS)
|
|
800
|
+
self.assertEqual(messages[0].id, 1)
|
|
801
|
+
self.assertEqual(messages[0].sender, 'sender1')
|
|
802
|
+
self.assertEqual(messages[0].content, 'text second')
|
|
803
|
+
self.assertEqual(messages[0].received_at, datetime.fromisoformat('2024-11-15 22:28:09'))
|
|
804
|
+
self.assertEqual(messages[0].unread, True)
|
|
805
|
+
self.assertIsInstance(messages[1], SMS)
|
|
806
|
+
self.assertEqual(messages[1].id, 2)
|
|
807
|
+
self.assertEqual(messages[1].sender, 'sender2')
|
|
808
|
+
self.assertEqual(messages[1].content, 'text first')
|
|
809
|
+
self.assertEqual(messages[1].received_at, datetime.fromisoformat('2024-11-15 22:23:59'))
|
|
810
|
+
self.assertEqual(messages[1].unread, False)
|
|
811
|
+
|
|
812
|
+
def test_get_sms_empty(self) -> None:
|
|
813
|
+
response = '''[error]0
|
|
814
|
+
|
|
815
|
+
'''
|
|
816
|
+
|
|
817
|
+
class TPLinkMRClientTest(TPLinkMRClient):
|
|
818
|
+
def _request(self, url, method='POST', data_str=None, encrypt=False):
|
|
819
|
+
return 200, response
|
|
820
|
+
|
|
821
|
+
client = TPLinkMRClientTest('', '')
|
|
822
|
+
messages = client.get_sms()
|
|
823
|
+
|
|
824
|
+
self.assertEqual([], messages)
|
|
825
|
+
|
|
826
|
+
def test_set_sms_read(self) -> None:
|
|
827
|
+
response = '''
|
|
828
|
+
[error]0
|
|
829
|
+
|
|
830
|
+
'''
|
|
831
|
+
|
|
832
|
+
check_url = ''
|
|
833
|
+
check_data = ''
|
|
834
|
+
|
|
835
|
+
class TPLinkMRClientTest(TPLinkMRClient):
|
|
836
|
+
def _request(self, url, method='POST', data_str=None, encrypt=False):
|
|
837
|
+
nonlocal check_url, check_data
|
|
838
|
+
check_url = url
|
|
839
|
+
check_data = data_str
|
|
840
|
+
return 200, response
|
|
841
|
+
|
|
842
|
+
client = TPLinkMRClientTest('', '')
|
|
843
|
+
client.set_sms_read(SMS(2, '', '', datetime.now(), True))
|
|
844
|
+
|
|
845
|
+
self.assertIn('http:///cgi_gdpr?_=', check_url)
|
|
846
|
+
self.assertEqual(check_data, '2\r\n[LTE_SMS_RECVMSGENTRY#2,0,0,0,0,0#0,0,0,0,0,0]0,1\r\nunread=0\r\n')
|
|
847
|
+
|
|
848
|
+
def test_delete_sms(self) -> None:
|
|
849
|
+
response = '''
|
|
850
|
+
[error]0
|
|
851
|
+
|
|
852
|
+
'''
|
|
853
|
+
|
|
854
|
+
check_url = ''
|
|
855
|
+
check_data = ''
|
|
856
|
+
|
|
857
|
+
class TPLinkMRClientTest(TPLinkMRClient):
|
|
858
|
+
def _request(self, url, method='POST', data_str=None, encrypt=False):
|
|
859
|
+
nonlocal check_url, check_data
|
|
860
|
+
check_url = url
|
|
861
|
+
check_data = data_str
|
|
862
|
+
return 200, response
|
|
863
|
+
|
|
864
|
+
client = TPLinkMRClientTest('', '')
|
|
865
|
+
client.delete_sms(SMS(2, '', '', datetime.now(), True))
|
|
866
|
+
|
|
867
|
+
self.assertIn('http:///cgi_gdpr?_=', check_url)
|
|
868
|
+
self.assertEqual(check_data, '4\r\n[LTE_SMS_RECVMSGENTRY#2,0,0,0,0,0#0,0,0,0,0,0]0,0\r\n\r\n')
|
|
869
|
+
|
|
870
|
+
def test_get_lte_status(self) -> None:
|
|
871
|
+
response = '''[2,1,0,0,0,0]0
|
|
872
|
+
enable=1
|
|
873
|
+
connectStatus=4
|
|
874
|
+
networkType=3
|
|
875
|
+
roamingStatus=0
|
|
876
|
+
simStatus=3
|
|
877
|
+
[2,0,0,0,0,0]1
|
|
878
|
+
dataLimit=0
|
|
879
|
+
enablePaymentDay=0
|
|
880
|
+
curStatistics=0
|
|
881
|
+
totalStatistics=32779416.0000
|
|
882
|
+
enableDataLimit=0
|
|
883
|
+
limitation=0
|
|
884
|
+
curRxSpeed=85
|
|
885
|
+
curTxSpeed=1492
|
|
886
|
+
[2,1,0,0,0,0]2
|
|
887
|
+
smsUnreadCount=0
|
|
888
|
+
ussdStatus=0
|
|
889
|
+
smsSendResult=3
|
|
890
|
+
sigLevel=0
|
|
891
|
+
rfInfoRsrp=-105
|
|
892
|
+
rfInfoRsrq=-20
|
|
893
|
+
rfInfoSnr=-44
|
|
894
|
+
[2,1,0,0,0,0]3
|
|
895
|
+
spn=Full name
|
|
896
|
+
ispName=Name
|
|
897
|
+
[error]0
|
|
898
|
+
|
|
899
|
+
'''
|
|
900
|
+
|
|
901
|
+
class TPLinkMRClientTest(TPLinkMRClient):
|
|
902
|
+
def _request(self, url, method='POST', data_str=None, encrypt=False):
|
|
903
|
+
return 200, response
|
|
904
|
+
|
|
905
|
+
client = TPLinkMRClientTest('', '')
|
|
906
|
+
status = client.get_lte_status()
|
|
907
|
+
|
|
908
|
+
self.assertIsInstance(status, LTEStatus)
|
|
909
|
+
self.assertEqual(status.enable, 1)
|
|
910
|
+
self.assertEqual(status.connect_status, 4)
|
|
911
|
+
self.assertEqual(status.network_type, 3)
|
|
912
|
+
self.assertEqual(status.sim_status, 3)
|
|
913
|
+
self.assertEqual(status.total_statistics, 32779416)
|
|
914
|
+
self.assertEqual(status.cur_rx_speed, 85)
|
|
915
|
+
self.assertEqual(status.cur_tx_speed, 1492)
|
|
916
|
+
self.assertEqual(status.sms_unread_count, 0)
|
|
917
|
+
self.assertEqual(status.sig_level, 0)
|
|
918
|
+
self.assertEqual(status.rsrp, -105)
|
|
919
|
+
self.assertEqual(status.rsrq, -20)
|
|
920
|
+
self.assertEqual(status.snr, -44)
|
|
921
|
+
self.assertEqual(status.isp_name, 'Name')
|
|
922
|
+
|
|
923
|
+
def test_get_lte_status_wrong(self) -> None:
|
|
924
|
+
response = '''[2,1,0,0,0,0]0
|
|
925
|
+
enable=1
|
|
926
|
+
connectStatus=1
|
|
927
|
+
networkType=2
|
|
928
|
+
roamingStatus=0
|
|
929
|
+
simStatus=1
|
|
930
|
+
[2,0,0,0,0,0]1
|
|
931
|
+
dataLimit=0
|
|
932
|
+
enablePaymentDay=0
|
|
933
|
+
curStatistics=0
|
|
934
|
+
totalStatistics=32779416.0000
|
|
935
|
+
enableDataLimit=0
|
|
936
|
+
limitation=0
|
|
937
|
+
curRxSpeed=0
|
|
938
|
+
curTxSpeed=0
|
|
939
|
+
[2,1,0,0,0,0]2
|
|
940
|
+
smsUnreadCount=0
|
|
941
|
+
ussdStatus=0
|
|
942
|
+
smsSendResult=3
|
|
943
|
+
sigLevel=2
|
|
944
|
+
rfInfoRsrp=0
|
|
945
|
+
rfInfoRsrq=0
|
|
946
|
+
rfInfoSnr=0
|
|
947
|
+
[2,1,0,0,0,0]3
|
|
948
|
+
spn=Full name
|
|
949
|
+
ispName=Name
|
|
950
|
+
[error]0
|
|
951
|
+
|
|
952
|
+
'''
|
|
953
|
+
|
|
954
|
+
class TPLinkMRClientTest(TPLinkMRClient):
|
|
955
|
+
def _request(self, url, method='POST', data_str=None, encrypt=False):
|
|
956
|
+
return 200, response
|
|
957
|
+
|
|
958
|
+
client = TPLinkMRClientTest('', '')
|
|
959
|
+
status = client.get_lte_status()
|
|
960
|
+
|
|
961
|
+
self.assertIsInstance(status, LTEStatus)
|
|
962
|
+
|
|
963
|
+
def test_get_vpn_status(self) -> None:
|
|
964
|
+
response = '''[0,0,0,0,0,0]0
|
|
965
|
+
enable=1
|
|
966
|
+
[0,0,0,0,0,0]1
|
|
967
|
+
enable=0
|
|
968
|
+
[1,0,0,0,0,0]2
|
|
969
|
+
connAct=0
|
|
970
|
+
[2,0,0,0,0,0]2
|
|
971
|
+
connAct=0
|
|
972
|
+
[3,0,0,0,0,0]2
|
|
973
|
+
connAct=0
|
|
974
|
+
[4,0,0,0,0,0]2
|
|
975
|
+
connAct=0
|
|
976
|
+
[5,0,0,0,0,0]2
|
|
977
|
+
connAct=1
|
|
978
|
+
[6,0,0,0,0,0]2
|
|
979
|
+
connAct=1
|
|
980
|
+
[7,0,0,0,0,0]2
|
|
981
|
+
connAct=0
|
|
982
|
+
[8,0,0,0,0,0]2
|
|
983
|
+
connAct=0
|
|
984
|
+
[9,0,0,0,0,0]2
|
|
985
|
+
connAct=0
|
|
986
|
+
[10,0,0,0,0,0]2
|
|
987
|
+
connAct=0
|
|
988
|
+
[1,0,0,0,0,0]3
|
|
989
|
+
connAct=0
|
|
990
|
+
[2,0,0,0,0,0]3
|
|
991
|
+
connAct=0
|
|
992
|
+
[3,0,0,0,0,0]3
|
|
993
|
+
connAct=0
|
|
994
|
+
[4,0,0,0,0,0]3
|
|
995
|
+
connAct=0
|
|
996
|
+
[5,0,0,0,0,0]3
|
|
997
|
+
connAct=0
|
|
998
|
+
[6,0,0,0,0,0]3
|
|
999
|
+
connAct=0
|
|
1000
|
+
[7,0,0,0,0,0]3
|
|
1001
|
+
connAct=0
|
|
1002
|
+
[8,0,0,0,0,0]3
|
|
1003
|
+
connAct=0
|
|
1004
|
+
[9,0,0,0,0,0]3
|
|
1005
|
+
connAct=0
|
|
1006
|
+
[10,0,0,0,0,0]3
|
|
1007
|
+
connAct=0
|
|
1008
|
+
[error]0
|
|
1009
|
+
|
|
1010
|
+
'''
|
|
1011
|
+
|
|
1012
|
+
class TPLinkMRClientTest(TPLinkMRClient):
|
|
1013
|
+
def _request(self, url, method='POST', data_str=None, encrypt=False):
|
|
1014
|
+
return 200, response
|
|
1015
|
+
|
|
1016
|
+
client = TPLinkMRClientTest('', '')
|
|
1017
|
+
status = client.get_vpn_status()
|
|
1018
|
+
|
|
1019
|
+
self.assertIsInstance(status, VPNStatus)
|
|
1020
|
+
self.assertEqual(status.openvpn_enable, True)
|
|
1021
|
+
self.assertEqual(status.pptpvpn_enable, False)
|
|
1022
|
+
self.assertEqual(status.openvpn_clients_total, 2)
|
|
1023
|
+
self.assertEqual(status.pptpvpn_clients_total, 0)
|
|
1024
|
+
|
|
1025
|
+
def test_set_vpn(self) -> None:
|
|
1026
|
+
response = '''
|
|
1027
|
+
[error]0
|
|
1028
|
+
|
|
1029
|
+
'''
|
|
1030
|
+
|
|
1031
|
+
check_url = ''
|
|
1032
|
+
check_data = ''
|
|
1033
|
+
|
|
1034
|
+
class TPLinkMRClientTest(TPLinkMRClient):
|
|
1035
|
+
def _request(self, url, method='POST', data_str=None, encrypt=False):
|
|
1036
|
+
nonlocal check_url, check_data
|
|
1037
|
+
check_url = url
|
|
1038
|
+
check_data = data_str
|
|
1039
|
+
return 200, response
|
|
1040
|
+
|
|
1041
|
+
client = TPLinkMRClientTest('', '')
|
|
1042
|
+
client.set_vpn(VPN.OPEN_VPN, True)
|
|
1043
|
+
|
|
1044
|
+
self.assertIn('http:///cgi_gdpr?_=', check_url)
|
|
1045
|
+
self.assertEqual(check_data, '2\r\n[OPENVPN#0,0,0,0,0,0#0,0,0,0,0,0]0,1\r\nenable=1\r\n')
|
|
1046
|
+
|
|
682
1047
|
|
|
683
1048
|
if __name__ == '__main__':
|
|
684
1049
|
main()
|