Repository: apache/airflow
File: task-sdk/tests/task_sdk/execution_time/test_cache.py (Python)

Code before:
        SecretCache.reset()
        SecretCache.init()

        SecretCache.save_variable("key", "some_value")  # will be ignored

        # cache is disabled, gets will always "fail"
        with pytest.raises(SecretCache.NotPresentException):
            SecretCache.get_variable("key")

    def test_independence_variable_connection(self):
        SecretCache.save_variable("same_key", "some_value")
        SecretCache.save_connection_uri("same_key", "some_other_value")

        assert SecretCache.get_variable("same_key") == "some_value"
        assert SecretCache.get_connection_uri("same_key") == "some_other_value"

        SecretCache.save_variable("var", "some_value")
        SecretCache.save_connection_uri("conn", "some_other_value")

        # getting the wrong type of thing with a key that exists in the other will not work
        with pytest.raises(SecretCache.NotPresentException):
            SecretCache.get_connection_uri("var")
        with pytest.raises(SecretCache.NotPresentException):
            SecretCache.get_variable("conn")

    def test_independence_teams(self):
        SecretCache.save_variable("key1", "var_value1", "team1")
        SecretCache.save_connection_uri("conn1", "conn_value1", "team1")
        SecretCache.save_variable("key2", "var_value2", "team2")
        SecretCache.save_connection_uri("conn2", "conn_value2", "team2")

        assert SecretCache.get_variable("key1", team_name="team1") == "var_value1"
        assert SecretCache.get_connection_uri("conn1", team_name="team1") == "conn_value1"
        assert SecretCache.get_variable("key2", team_name="team2") == "var_value2"
        assert SecretCache.get_connection_uri("conn2", team_name="team2") == "conn_value2"

        with pytest.raises(SecretCache.NotPresentException):
            SecretCache.get_variable("key1")
        with pytest.raises(SecretCache.NotPresentException):
            SecretCache.get_variable("key2")
        with pytest.raises(SecretCache.NotPresentException):
            SecretCache.get_connection_uri("conn1")
        with pytest.raises(SecretCache.NotPresentException):
            SecretCache.get_connection_uri("conn2")

        with pytest.raises(SecretCache.NotPresentException):
            SecretCache.get_variable("key1", team_name="team2")
        with pytest.raises(SecretCache.NotPresentException):
            SecretCache.get_variable("key2", team_name="team1")
        with pytest.raises(SecretCache.NotPresentException):
            SecretCache.get_connection_uri("conn1", team_name="team2")

Review comment (suggestion):
nit: 

|
```suggestion
    def test_independent_teams(self):
```

Code after:
        SecretCache.reset()
        SecretCache.init()

        SecretCache.save_variable("key", "some_value")  # will be ignored

        # cache is disabled, gets will always "fail"
        with pytest.raises(SecretCache.NotPresentException):
            SecretCache.get_variable("key")

    def test_independence_variable_connection(self):
        SecretCache.save_variable("same_key", "some_value")
        SecretCache.save_connection_uri("same_key", "some_other_value")

        assert SecretCache.get_variable("same_key") == "some_value"
        assert SecretCache.get_connection_uri("same_key") == "some_other_value"

        SecretCache.save_variable("var", "some_value")
        SecretCache.save_connection_uri("conn", "some_other_value")

        # getting the wrong type of thing with a key that exists in the other will not work
        with pytest.raises(SecretCache.NotPresentException):
            SecretCache.get_connection_uri("var")
        with pytest.raises(SecretCache.NotPresentException):
            SecretCache.get_variable("conn")

    def test_independent_teams(self):
        SecretCache.save_variable("key1", "var_value1", "team1")
        SecretCache.save_connection_uri("conn1", "conn_value1", "team1")
        SecretCache.save_variable("key2", "var_value2", "team2")
        SecretCache.save_connection_uri("conn2", "conn_value2", "team2")

        assert SecretCache.get_variable("key1", team_name="team1") == "var_value1"
        assert SecretCache.get_connection_uri("conn1", team_name="team1") == "conn_value1"
        assert SecretCache.get_variable("key2", team_name="team2") == "var_value2"
        assert SecretCache.get_connection_uri("conn2", team_name="team2") == "conn_value2"

        with pytest.raises(SecretCache.NotPresentException):
            SecretCache.get_variable("key1")
        with pytest.raises(SecretCache.NotPresentException):
            SecretCache.get_variable("key2")
        with pytest.raises(SecretCache.NotPresentException):
            SecretCache.get_connection_uri("conn1")
        with pytest.raises(SecretCache.NotPresentException):
            SecretCache.get_connection_uri("conn2")

        with pytest.raises(SecretCache.NotPresentException):
            SecretCache.get_variable("key1", team_name="team2")
        with pytest.raises(SecretCache.NotPresentException):
            SecretCache.get_variable("key2", team_name="team1")
        with pytest.raises(SecretCache.NotPresentException):
            SecretCache.get_connection_uri("conn1", team_name="team2")