mik-laj commented on a change in pull request #9273:
URL: https://github.com/apache/airflow/pull/9273#discussion_r440946856



##########
File path: tests/api_connexion/endpoints/test_variable_endpoint.py
##########
@@ -29,38 +30,133 @@ def setUpClass(cls) -> None:
 
     def setUp(self) -> None:
         self.client = self.app.test_client()  # type:ignore
+        with create_session() as session:
+            session.query(Variable).delete()
+
+    def tearDown(self) -> None:
+        clear_db_connections()
 
 
 class TestDeleteVariable(TestVariableEndpoint):
-    @pytest.mark.skip(reason="Not implemented yet")
-    def test_should_response_200(self):
-        response = self.client.delete("/api/v1/variables/TEST_VARIABLE_KEY")
+    def test_should_response_204(self):
+        Variable.set("delete_var1", 1)
+        response = self.client.delete("/api/v1/variables/delete_var1")
+        print(response.data)
         assert response.status_code == 204
+        # make sure variable is deleted
+        response = self.client.get("/api/v1/variables/delete_var1")
+        assert response.status_code == 404
 
 
 class TestGetVariable(TestVariableEndpoint):
-    @pytest.mark.skip(reason="Not implemented yet")
+
     def test_should_response_200(self):
+        expected_value = '{"foo": 1}'
+        Variable.set("TEST_VARIABLE_KEY", expected_value)
         response = self.client.get("/api/v1/variables/TEST_VARIABLE_KEY")
         assert response.status_code == 200
+        assert response.json == {"key": "TEST_VARIABLE_KEY", "value": 
expected_value}
+
+    def test_should_response_404_if_not_found(self):
+        response = self.client.get("/api/v1/variables/NONEXIST_VARIABLE_KEY")
+        assert response.status_code == 404
 
 
 class TestGetVariables(TestVariableEndpoint):
-    @pytest.mark.skip(reason="Not implemented yet")
-    def test_should_response_200(self):
-        response = self.client.get("/api/v1/variables")
+    def test_should_get_list_variables(self):
+        Variable.set("var1", 1)
+        Variable.set("var2", "foo")
+        Variable.set("var3", "[100, 101]")
+        response = self.client.get("/api/v1/variables?limit=2&offset=0")
         assert response.status_code == 200
+        assert response.json == {
+            "variables": [
+                {"key": "var1", "value": "1"},
+                {"key": "var2", "value": "foo"},
+            ],
+            "total_entries": 2,
+        }
 
+        response = self.client.get("/api/v1/variables?limit=2&offset=1")
+        assert response.status_code == 200
+        assert response.json == {
+            "variables": [
+                {"key": "var3", "value": "[100, 101]"},
+            ],
+            "total_entries": 1,
+        }
 
-class TestPatchVariable(TestVariableEndpoint):
-    @pytest.mark.skip(reason="Not implemented yet")
-    def test_should_response_200(self):
-        response = self.client.patch("/api/v1/variables/TEST_VARIABLE_KEY")
+        response = self.client.get("/api/v1/variables?limit=1&offset=2")
         assert response.status_code == 200
+        assert response.json == {
+            "variables": [
+                {"key": "var3", "value": "[100, 101]"},
+            ],
+            "total_entries": 1,
+        }
+
+
+class TestPatchVariable(TestVariableEndpoint):
+    def test_should_update_variable(self):
+        Variable.set("var1", "foo")
+        response = self.client.patch("/api/v1/variables/var1", json={
+            "key": "var1",
+            "value": "updated",
+        })
+        assert response.status_code == 204
+        response = self.client.get("/api/v1/variables/var1")
+        assert response.json == {
+            "key": "var1",
+            "value": "updated",
+        }
+
+    def test_should_reject_invalid_update(self):
+        Variable.set("var1", "foo")
+        response = self.client.patch("/api/v1/variables/var1", json={
+            "key": "var2",
+            "value": "updated",
+        })
+        assert response.status_code == 400
+        assert response.json == {
+            "title": "Invalid post body",
+            "status": 400,
+            "type": "about:blank",
+            "detail": "key from request body doesn't match uri parameter",
+        }
+
+        response = self.client.patch("/api/v1/variables/var1", json={
+            "key": "var2",
+        })
+        assert response.json == {
+            "title": "Invalid Variable schema",
+            "status": 400,
+            "type": "about:blank",

Review comment:
       I do not have a specific plan yet, but I will try to prepare a reference 
documentation that will be generated in Swagger UI or Redoc and add links where 
possible. 
   Here is issue about docs: https://github.com/apache/airflow/issues/8143




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to