예제 #1
0
 def test_run_raises_with_password_env_var_not_found(self):
     neo4j_task = Neo4jRunCypherQueryTask()
     msg_match = "`env_var` not found in environment variables."
     with pytest.raises(ValueError, match=msg_match):
         neo4j_task.run(server_uri="uri",
                        user="******",
                        password_env_var="env_var")
예제 #2
0
 def test_run_raises_with_no_server_uri_and_env_var(self):
     neo4j_task = Neo4jRunCypherQueryTask()
     msg_match = (
         "Please provide either the `server_uri` or the `server_uri_env_var`."
     )
     with pytest.raises(ValueError, match=msg_match):
         neo4j_task.run()
예제 #3
0
    def test_run_dataframe_return_type(self, mock_run, mock_graph):
        import pandas as pd

        class mockRun:
            def data(self):
                return [{"key1": "value1"}, {"key2": "value2"}]

            def to_data_frame(self):
                return pd.DataFrame([{"key": "value"}])

        class mockGraph:
            def run(self):
                return mockRun()

        mock_graph.return_value = mockGraph
        mock_run.run = mockGraph.run
        neo4j_task = Neo4jRunCypherQueryTask()
        result = neo4j_task.run(
            server_uri="bolt://localhost:7687",
            user="******",
            password="******",
            cypher_query="query",
            return_result_as="dataframe",
        )

        assert result.equals(pd.DataFrame([{"key": "value"}]))
예제 #4
0
 def test_run_raises_fail_on_neo4j_connect(self):
     neo4j_task = Neo4jRunCypherQueryTask()
     msg_match = "Error while connecting to Neo4j."
     with pytest.raises(FAIL, match=msg_match):
         neo4j_task.run(
             server_uri="bolt://uri:9999",
             user="******",
             password="******",
             cypher_query="query",
         )
예제 #5
0
 def test_run_raises_with_illegal_return_result_as(self):
     neo4j_task = Neo4jRunCypherQueryTask()
     msg_match = "Illegal value for `return_result_as`. Illegal value is: illegal."
     with pytest.raises(ValueError, match=msg_match):
         neo4j_task.run(
             server_uri="uri",
             user="******",
             password="******",
             cypher_query="query",
             return_result_as="illegal",
         )
예제 #6
0
    def test_construction_no_values(self):
        neo4j_task = Neo4jRunCypherQueryTask()

        assert neo4j_task.server_uri is None
        assert neo4j_task.user is None
        assert neo4j_task.password is None
        assert neo4j_task.server_uri_env_var is None
        assert neo4j_task.user_env_var is None
        assert neo4j_task.password_env_var is None
        assert neo4j_task.db_name is None
        assert neo4j_task.db_name_env_var is None
        assert neo4j_task.cypher_query is None
        assert neo4j_task.return_result_as == "raw"
예제 #7
0
    def test_run_default_return_type(self, mock_run, mock_graph):
        class mockRun:
            def data(self):
                return [{"key1": "value1"}, {"key2": "value2"}]

        class mockGraph:
            def run(self):
                return mockRun()

        mock_graph.return_value = mockGraph
        mock_run.run = mockGraph.run
        neo4j_task = Neo4jRunCypherQueryTask()
        result = neo4j_task.run(
            server_uri="bolt://localhost:7687",
            user="******",
            password="******",
            cypher_query="query",
        )

        assert result == [{"key1": "value1"}, {"key2": "value2"}]
예제 #8
0
    def test_construction_with_values(self):
        neo4j_task = Neo4jRunCypherQueryTask(
            server_uri="uri",
            user="******",
            password="******",
            db_name="db",
            server_uri_env_var="uri_env",
            user_env_var="user_env",
            password_env_var="pwd_env",
            db_name_env_var="db_env",
            cypher_query="query",
            return_result_as="json",
        )

        assert neo4j_task.server_uri == "uri"
        assert neo4j_task.user == "user"
        assert neo4j_task.password == "pwd"
        assert neo4j_task.db_name == "db"
        assert neo4j_task.server_uri_env_var == "uri_env"
        assert neo4j_task.user_env_var == "user_env"
        assert neo4j_task.password_env_var == "pwd_env"
        assert neo4j_task.db_name_env_var == "db_env"
        assert neo4j_task.cypher_query == "query"
        assert neo4j_task.return_result_as == "json"
예제 #9
0
 def test_run_raises_with_no_cypher_query(self):
     neo4j_task = Neo4jRunCypherQueryTask()
     msg_match = "Please provide a value for `cypher_query`."
     with pytest.raises(ValueError, match=msg_match):
         neo4j_task.run(server_uri="uri", user="******", password="******")
예제 #10
0
 def test_run_raises_with_no_password_and_env_var(self):
     neo4j_task = Neo4jRunCypherQueryTask()
     msg_match = "Please provide either the `password` or the `password_env_var`."
     with pytest.raises(ValueError, match=msg_match):
         neo4j_task.run(server_uri="uri", user="******")