33# See LICENSE file for licensing details. 
44
55import  logging 
6- import  os 
76
87import  psycopg2 
98import  pytest 
3130UNIT_IDS  =  [0 , 1 , 2 ]
3231
3332
34- @pytest .mark .skipif ( 
35-     os .environ .get ("PYTEST_SKIP_DEPLOY" , False ), 
36-     reason = "skipping deploy, model expected to be provided." , 
37- ) 
3833@pytest .mark .abort_on_fail  
34+ @pytest .mark .charm_tests  
35+ @pytest .mark .skip_if_deployed  
3936async  def  test_build_and_deploy (ops_test : OpsTest ):
4037    """Build the charm-under-test and deploy it. 
4138
@@ -54,7 +51,7 @@ async def test_build_and_deploy(ops_test: OpsTest):
5451        assert  ops_test .model .applications [APP_NAME ].units [unit_id ].workload_status  ==  "active" 
5552
5653
57- @pytest .mark .charm  
54+ @pytest .mark .charm_tests  
5855async  def  test_application_created_required_resources (ops_test : OpsTest ) ->  None :
5956    # Compare the k8s resources that the charm and Patroni should create with 
6057    # the currently created k8s resources. 
@@ -64,6 +61,7 @@ async def test_application_created_required_resources(ops_test: OpsTest) -> None
6461    assert  set (existing_resources ) ==  set (expected_resources )
6562
6663
64+ @pytest .mark .charm_tests  
6765@pytest .mark .parametrize ("unit_id" , UNIT_IDS ) 
6866async  def  test_labels_consistency_across_pods (ops_test : OpsTest , unit_id : int ) ->  None :
6967    model  =  ops_test .model .info 
@@ -75,6 +73,7 @@ async def test_labels_consistency_across_pods(ops_test: OpsTest, unit_id: int) -
7573    assert  pod .metadata .labels ["cluster-name" ] ==  f"patroni-{ APP_NAME }  
7674
7775
76+ @pytest .mark .charm_tests  
7877@pytest .mark .parametrize ("unit_id" , UNIT_IDS ) 
7978async  def  test_database_is_up (ops_test : OpsTest , unit_id : int ):
8079    # Query Patroni REST API and check the status that indicates 
@@ -84,6 +83,7 @@ async def test_database_is_up(ops_test: OpsTest, unit_id: int):
8483    assert  result .status_code  ==  200 
8584
8685
86+ @pytest .mark .charm_tests  
8787@pytest .mark .parametrize ("unit_id" , UNIT_IDS ) 
8888async  def  test_settings_are_correct (ops_test : OpsTest , unit_id : int ):
8989    password  =  await  get_password (ops_test )
@@ -123,6 +123,7 @@ async def test_settings_are_correct(ops_test: OpsTest, unit_id: int):
123123    assert  settings ["postgresql" ]["use_pg_rewind" ]
124124
125125
126+ @pytest .mark .charm_tests  
126127async  def  test_cluster_is_stable_after_leader_deletion (ops_test : OpsTest ) ->  None :
127128    """Tests that the cluster maintains a primary after the primary is deleted.""" 
128129    # Find the current primary unit. 
@@ -146,6 +147,7 @@ async def test_cluster_is_stable_after_leader_deletion(ops_test: OpsTest) -> Non
146147    assert  await  get_primary (ops_test , other_unit_id ) !=  "None" 
147148
148149
150+ @pytest .mark .charm_tests  
149151async  def  test_scale_down_and_up (ops_test : OpsTest ):
150152    """Test data is replicated to new units after a scale up.""" 
151153    # Ensure the initial number of units in the application. 
@@ -171,6 +173,7 @@ async def test_scale_down_and_up(ops_test: OpsTest):
171173    await  scale_application (ops_test , APP_NAME , initial_scale )
172174
173175
176+ @pytest .mark .charm_tests  
174177async  def  test_persist_data_through_graceful_restart (ops_test : OpsTest ):
175178    """Test data persists through a graceful restart.""" 
176179    primary  =  await  get_primary (ops_test )
@@ -199,6 +202,7 @@ async def test_persist_data_through_graceful_restart(ops_test: OpsTest):
199202            connection .cursor ().execute ("SELECT * FROM gracetest;" )
200203
201204
205+ @pytest .mark .charm_tests  
202206async  def  test_persist_data_through_failure (ops_test : OpsTest ):
203207    """Test data persists through a failure.""" 
204208    primary  =  await  get_primary (ops_test )
@@ -239,6 +243,7 @@ async def test_persist_data_through_failure(ops_test: OpsTest):
239243            connection .cursor ().execute ("SELECT * FROM failtest;" )
240244
241245
246+ @pytest .mark .charm_tests  
242247async  def  test_automatic_failover_after_leader_issue (ops_test : OpsTest ) ->  None :
243248    """Tests that an automatic failover is triggered after an issue happens in the leader.""" 
244249    # Find the current primary unit. 
@@ -256,6 +261,7 @@ async def test_automatic_failover_after_leader_issue(ops_test: OpsTest) -> None:
256261    assert  await  get_primary (ops_test ) !=  "None" 
257262
258263
264+ @pytest .mark .charm_tests  
259265async  def  test_application_removal (ops_test : OpsTest ) ->  None :
260266    # Remove the application to trigger some hooks (like peer relation departed). 
261267    await  ops_test .model .applications [APP_NAME ].remove ()
@@ -281,7 +287,7 @@ async def test_application_removal(ops_test: OpsTest) -> None:
281287    assert  APP_NAME  not  in ops_test .model .applications 
282288
283289
284- @pytest .mark .charm  
290+ @pytest .mark .charm_tests  
285291async  def  test_redeploy_charm_same_model (ops_test : OpsTest ):
286292    """Redeploy the charm in the same model to test that it works.""" 
287293    charm  =  await  ops_test .build_charm ("." )
0 commit comments