@@ -83,80 +83,68 @@ def test_call_secret_fqdn_ip1_ip2(self, update: mock.Mock) -> None:
83
83
84
84
class TestUpdateByPath :
85
85
@staticmethod
86
- def _url (path : str ) -> str :
86
+ def url (path : str ) -> str :
87
87
return f"/update-by-path/12345678/test.dyndns1.dev/{ path } "
88
88
89
89
def test_ipv4_update (self , client : TestClient ) -> None :
90
- client .delete_record ("test" , "A" )
91
90
client .add_record ("test" , "A" , "1.2.3.4" )
92
91
assert (
93
- client .get (self ._url ("1.2.3.5" ))
94
- == "UPDATED: test.dyndns1.dev. A 1.2.3.4 -> 1.2.3.5\n UNCHANGED: test.dyndns1.dev. AAAA None\n "
92
+ client .get (self .url ("1.2.3.5" ))
93
+ == "UPDATED: test.dyndns1.dev. A 1.2.3.4 -> 1.2.3.5\n "
94
+ + "UNCHANGED: test.dyndns1.dev. AAAA None\n "
95
95
)
96
+ assert client .read_record ("test" , "A" ) == "1.2.3.5"
96
97
97
-
98
- class TestUpdateByPathOld (TestIntegration ):
99
- """Test the path ``update-by-path`` of the Flask web app."""
100
-
101
- @staticmethod
102
- def _url (path : str ) -> str :
103
- return f"/update-by-path/12345678/www.dyndns1.dev/{ path } "
104
-
105
- @pytest .mark .skip
106
- def test_ipv6_update (self ) -> None :
107
- self .get (self ._url ("1::3" ), [["1::2" ], ["1::3" ]])
108
- self .mock_update .delete .assert_called_with ("www.example.com." , "AAAA" )
109
- self .mock_update .add .assert_called_with ("www.example.com." , 300 , "AAAA" , "1::3" )
98
+ def test_ipv6_update (self , client : TestClient ) -> None :
99
+ client .add_record ("test" , "AAAA" , "1::2" )
110
100
assert (
111
- self .data == "UPDATED: fqdn: www.example.com. old_ip: 1::2 new_ip: 1::3\n "
101
+ client .get (self .url ("1::3" ))
102
+ == "UNCHANGED: test.dyndns1.dev. A None\n "
103
+ + "UPDATED: test.dyndns1.dev. AAAA 1::2 -> 1::3\n "
112
104
)
105
+ assert client .read_record ("test" , "AAAA" ) == "1::3"
113
106
114
- @pytest .mark .skip
115
- def test_ipv4_ipv6_update (self ) -> None :
116
- self .get (
117
- self ._url ("1.2.3.5/1::3" ), [["1.2.3.4" ], ["1.2.3.5" ], ["1::2" ], ["1::3" ]]
118
- )
119
- self .mock_update .delete .assert_called_with ("www.example.com." , "AAAA" )
120
- self .mock_update .add .assert_called_with ("www.example.com." , 300 , "AAAA" , "1::3" )
107
+ def test_ipv4_ipv6_update (self , client : TestClient ) -> None :
108
+ client .add_record ("test" , "A" , "1.2.3.4" )
109
+ client .add_record ("test" , "AAAA" , "1::2" )
121
110
assert (
122
- self .data
123
- == "UPDATED: fqdn: www.example.com. old_ip: 1.2.3.4 new_ip: 1.2.3.5\n "
124
- "UPDATED: fqdn: www.example.com. old_ip: 1::2 new_ip: 1::3\n "
111
+ client . get ( self .url ( "1.2.3.5/1::3" ))
112
+ == "UPDATED: test.dyndns1.dev. A 1.2.3.4 -> 1.2.3.5\n "
113
+ + "UPDATED: test.dyndns1.dev. AAAA 1::2 -> 1::3\n "
125
114
)
115
+ assert client .read_record ("test" , "A" ) == "1.2.3.5"
116
+ assert client .read_record ("test" , "AAAA" ) == "1::3"
126
117
127
- @pytest .mark .skip
128
- def test_ipv6_ipv4_update (self ) -> None :
129
- self .get (
130
- self ._url ("1::3/1.2.3.5" ), [["1.2.3.4" ], ["1.2.3.5" ], ["1::2" ], ["1::3" ]]
118
+ def test_wrong_secret (self , client : TestClient ) -> None :
119
+ response = client .get_response (
120
+ "/update-by-path/wrong-secret/test.example.com/1.2.3.4"
131
121
)
132
- self .mock_update .delete .assert_called_with ("www.example.com." , "AAAA" )
133
- self .mock_update .add .assert_called_with ("www.example.com." , 300 , "AAAA" , "1::3" )
122
+ assert response .status_code == 456
134
123
assert (
135
- self .data
136
- == "UPDATED: fqdn: www.example.com. old_ip: 1.2.3.4 new_ip: 1.2.3.5\n "
137
- "UPDATED: fqdn: www.example.com. old_ip: 1::2 new_ip: 1::3\n "
124
+ response .data .decode ()
125
+ == "PARAMETER_ERROR: You specified a wrong secret key.\n "
138
126
)
139
127
140
- def test_wrong_secret (self ) -> None :
141
- self .get ("/update-by-path/wrong-secret/test.example.com/1.2.3.4" )
142
- assert self .response .status_code == 456
128
+ assert client .read_record ("test" , "A" ) is None
129
+ assert client .read_record ("test" , "AAAA" ) is None
130
+
131
+ def test_wrong_fqdn (self , client : TestClient ) -> None :
132
+ response = client .get_response (
133
+ "/update-by-path/12345678/test.wrong-domain.de/1.2.3.4"
134
+ )
135
+ assert response .status_code == 453
143
136
assert (
144
- b"PARAMETER_ERROR: You specified a wrong secret key." in self .response .data
137
+ response .data .decode ()
138
+ == "DNS_NAME_ERROR: The fully qualified domain name 'test.wrong-domain.de.' could not be split into a record and a zone name.\n "
145
139
)
146
140
147
- def test_wrong_fqdn (self ) -> None :
148
- self .get ( "/update-by-path/12345678/test.wrong-domain.de/ 1.2.3.4" )
149
- assert self . response .status_code == 453
141
+ def test_wrong_ip (self , client : TestClient ) -> None :
142
+ response = client . get_response ( self .url ( " 1.2.3" ) )
143
+ assert response .status_code == 454
150
144
assert (
151
- b'DNS_NAME_ERROR: The fully qualified domain name "test.wrong-domain.de." could not be split into a record and a zone name.\n '
152
- in self .response .data
145
+ response .data .decode () == "IP_ADDRESS_ERROR: Invalid IP address '1.2.3'.\n "
153
146
)
154
147
155
- def test_wrong_ip (self ) -> None :
156
- self .get ("/update-by-path/12345678/test.example.com/1.2.3" )
157
- assert self .response .status_code == 454
158
- assert b'IP_ADDRESS_ERROR: Invalid ip address "1.2.3"\n ' in self .response .data
159
-
160
148
161
149
class TestUpdateByQuery (TestIntegration ):
162
150
"""Test the path ``update-by-query`` of the Flask web app."""
@@ -224,7 +212,7 @@ def test_ip_1_ip_2_update(self) -> None:
224
212
225
213
def test_invalid_ipv4 (self ) -> None :
226
214
self .get (self ._url ("ipv4=1.2.3.4.5" ))
227
- assert self .data == ' IP_ADDRESS_ERROR: Invalid ip address " 1.2.3.4.5" \n '
215
+ assert self .data == " IP_ADDRESS_ERROR: Invalid IP address ' 1.2.3.4.5'. \n "
228
216
229
217
@pytest .mark .skip
230
218
def test_ttl (self ) -> None :
@@ -252,13 +240,11 @@ def test_deletion(self) -> None:
252
240
assert self .data == 'UPDATED: Deleted "www.example.com.".\n '
253
241
254
242
255
- class TestMultiplePaths (TestIntegration ):
256
- def test_home (self , flask_client : FlaskClient ) -> None :
257
- response = flask_client .get ("/" )
258
- assert b"dyndns" in response .data
243
+ class TestMultiplePaths :
244
+ def test_home (self , client : TestClient ) -> None :
245
+ assert client .get ("/" ) == "dyndns\n "
259
246
260
- def test_check (self , flask_client : FlaskClient ) -> None :
261
- response = flask_client .get ("/check" )
262
- content = response .data .decode ()
247
+ def test_check (self , client : TestClient ) -> None :
248
+ content : str = client .get ("/check" )
263
249
assert "could be updated on the zone 'dyndns1.dev.'" in content
264
250
assert "could be updated on the zone 'dyndns2.dev.'" in content
0 commit comments