55from __future__ import annotations
66
77import json
8- import os
9- from pathlib import Path
108
11- import boto3
129import pytest
1310from moto import mock_aws
1411from typer .testing import CliRunner
@@ -67,10 +64,14 @@ def test_init_success(self, aws_env):
6764 result = runner .invoke (
6865 app ,
6966 [
70- "dynamo" , "init" ,
71- "--table-name" , "test-zebra-config" ,
72- "--s3-bucket" , "test-backup-bucket" ,
73- "--region" , "us-east-1" ,
67+ "dynamo" ,
68+ "init" ,
69+ "--table-name" ,
70+ "test-zebra-config" ,
71+ "--s3-bucket" ,
72+ "test-backup-bucket" ,
73+ "--region" ,
74+ "us-east-1" ,
7475 ],
7576 )
7677 assert result .exit_code == 0 , result .output
@@ -94,10 +95,14 @@ def test_init_with_s3_config_file(self, aws_env, tmp_path):
9495 result = runner .invoke (
9596 app ,
9697 [
97- "dynamo" , "init" ,
98- "--table-name" , "test-zebra-config" ,
99- "--region" , "us-east-1" ,
100- "--s3-config-file" , str (cfg ),
98+ "dynamo" ,
99+ "init" ,
100+ "--table-name" ,
101+ "test-zebra-config" ,
102+ "--region" ,
103+ "us-east-1" ,
104+ "--s3-config-file" ,
105+ str (cfg ),
101106 ],
102107 )
103108 assert result .exit_code == 0 , result .output
@@ -110,11 +115,16 @@ def test_init_s3_bucket_flag_overrides_config_file(self, aws_env, tmp_path):
110115 result = runner .invoke (
111116 app ,
112117 [
113- "dynamo" , "init" ,
114- "--table-name" , "test-zebra-config" ,
115- "--region" , "us-east-1" ,
116- "--s3-bucket" , "flag-bucket" ,
117- "--s3-config-file" , str (cfg ),
118+ "dynamo" ,
119+ "init" ,
120+ "--table-name" ,
121+ "test-zebra-config" ,
122+ "--region" ,
123+ "us-east-1" ,
124+ "--s3-bucket" ,
125+ "flag-bucket" ,
126+ "--s3-config-file" ,
127+ str (cfg ),
118128 ],
119129 )
120130 assert result .exit_code == 0 , result .output
@@ -127,10 +137,14 @@ def test_init_bad_s3_config_file(self, aws_env, tmp_path):
127137 result = runner .invoke (
128138 app ,
129139 [
130- "dynamo" , "init" ,
131- "--table-name" , "test-zebra-config" ,
132- "--region" , "us-east-1" ,
133- "--s3-config-file" , str (cfg ),
140+ "dynamo" ,
141+ "init" ,
142+ "--table-name" ,
143+ "test-zebra-config" ,
144+ "--region" ,
145+ "us-east-1" ,
146+ "--s3-config-file" ,
147+ str (cfg ),
134148 ],
135149 )
136150 assert result .exit_code == 1
@@ -140,10 +154,14 @@ def test_init_nonexistent_s3_config_file(self, aws_env):
140154 result = runner .invoke (
141155 app ,
142156 [
143- "dynamo" , "init" ,
144- "--table-name" , "test-zebra-config" ,
145- "--region" , "us-east-1" ,
146- "--s3-config-file" , "/tmp/no-such-file-12345.json" ,
157+ "dynamo" ,
158+ "init" ,
159+ "--table-name" ,
160+ "test-zebra-config" ,
161+ "--region" ,
162+ "us-east-1" ,
163+ "--s3-config-file" ,
164+ "/tmp/no-such-file-12345.json" ,
147165 ],
148166 )
149167 assert result .exit_code == 1
@@ -154,24 +172,35 @@ def test_init_shows_permission_checks(self, aws_env):
154172 result = runner .invoke (
155173 app ,
156174 [
157- "dynamo" , "init" ,
158- "--table-name" , "test-zebra-config" ,
159- "--s3-bucket" , "test-backup-bucket" ,
160- "--region" , "us-east-1" ,
175+ "dynamo" ,
176+ "init" ,
177+ "--table-name" ,
178+ "test-zebra-config" ,
179+ "--s3-bucket" ,
180+ "test-backup-bucket" ,
181+ "--region" ,
182+ "us-east-1" ,
161183 ],
162184 )
163185 assert result .exit_code == 0 , result .output
164- assert "permission checks passed" in result .output .lower () or "Checking AWS" in result .output
186+ assert (
187+ "permission checks passed" in result .output .lower ()
188+ or "Checking AWS" in result .output
189+ )
165190
166191 def test_init_skip_checks (self , aws_env ):
167192 with mock_aws ():
168193 result = runner .invoke (
169194 app ,
170195 [
171- "dynamo" , "init" ,
172- "--table-name" , "test-zebra-config" ,
173- "--s3-bucket" , "test-backup-bucket" ,
174- "--region" , "us-east-1" ,
196+ "dynamo" ,
197+ "init" ,
198+ "--table-name" ,
199+ "test-zebra-config" ,
200+ "--s3-bucket" ,
201+ "test-backup-bucket" ,
202+ "--region" ,
203+ "us-east-1" ,
175204 "--skip-checks" ,
176205 ],
177206 )
@@ -225,9 +254,12 @@ def test_bootstrap_with_config_and_templates(self, aws_env, tmp_path):
225254 result = runner .invoke (
226255 app ,
227256 [
228- "dynamo" , "bootstrap" ,
229- "--config-file" , str (cfg ),
230- "--templates-dir" , str (tpl_dir ),
257+ "dynamo" ,
258+ "bootstrap" ,
259+ "--config-file" ,
260+ str (cfg ),
261+ "--templates-dir" ,
262+ str (tpl_dir ),
231263 "--no-include-package" ,
232264 ],
233265 )
@@ -237,8 +269,6 @@ def test_bootstrap_with_config_and_templates(self, aws_env, tmp_path):
237269 assert "Backup written" in result .output
238270
239271
240-
241-
242272# ---------------------------------------------------------------------------
243273# export
244274# ---------------------------------------------------------------------------
@@ -381,7 +411,6 @@ def test_destroy_success(self, aws_env):
381411 assert "Backups preserved" in result .output
382412
383413
384-
385414# ---------------------------------------------------------------------------
386415# Interactive S3 bucket prompt
387416# ---------------------------------------------------------------------------
@@ -398,9 +427,7 @@ def test_status_prompts_for_bucket_interactively(self, aws_env, monkeypatch):
398427 with mock_aws ():
399428 _provision_resources ()
400429 # Provide bucket name via CliRunner input
401- result = runner .invoke (
402- app , ["dynamo" , "status" ], input = "test-backup-bucket\n "
403- )
430+ result = runner .invoke (app , ["dynamo" , "status" ], input = "test-backup-bucket\n " )
404431 assert result .exit_code == 0 , result .output
405432 assert "test-zebra-config" in result .output
406433
@@ -429,9 +456,7 @@ def test_backup_prompts_for_bucket(self, aws_env, monkeypatch):
429456 with mock_aws ():
430457 backend = _provision_resources ()
431458 backend .save_config ({"labs" : {}})
432- result = runner .invoke (
433- app , ["dynamo" , "backup" ], input = "test-backup-bucket\n "
434- )
459+ result = runner .invoke (app , ["dynamo" , "backup" ], input = "test-backup-bucket\n " )
435460 assert result .exit_code == 0 , result .output
436461 assert "Backup written" in result .output
437462
@@ -443,9 +468,12 @@ def test_init_prompts_for_bucket(self, aws_env, monkeypatch):
443468 result = runner .invoke (
444469 app ,
445470 [
446- "dynamo" , "init" ,
447- "--table-name" , "test-zebra-config" ,
448- "--region" , "us-east-1" ,
471+ "dynamo" ,
472+ "init" ,
473+ "--table-name" ,
474+ "test-zebra-config" ,
475+ "--region" ,
476+ "us-east-1" ,
449477 ],
450478 input = "test-backup-bucket\n " ,
451479 )
@@ -467,6 +495,7 @@ def test_status_create_s3_if_missing(self, aws_env, monkeypatch):
467495 _provision_resources ()
468496 # Delete the bucket so it doesn't exist
469497 import boto3
498+
470499 s3 = boto3 .client ("s3" , region_name = "us-east-1" )
471500 # Empty and delete the bucket
472501 try :
@@ -479,9 +508,7 @@ def test_status_create_s3_if_missing(self, aws_env, monkeypatch):
479508
480509 # Use a new bucket name via env
481510 monkeypatch .setenv ("ZEBRA_DAY_S3_BACKUP_BUCKET" , "new-auto-bucket" )
482- result = runner .invoke (
483- app , ["dynamo" , "status" , "--create-s3-if-missing" ]
484- )
511+ result = runner .invoke (app , ["dynamo" , "status" , "--create-s3-if-missing" ])
485512 assert result .exit_code == 0 , result .output
486513 # Bucket should have been created
487514 assert "created" in result .output .lower () or "test-zebra-config" in result .output
@@ -494,9 +521,7 @@ def test_backup_create_s3_if_missing(self, aws_env, monkeypatch):
494521
495522 # Point to a new bucket that doesn't exist
496523 monkeypatch .setenv ("ZEBRA_DAY_S3_BACKUP_BUCKET" , "auto-backup-bucket" )
497- result = runner .invoke (
498- app , ["dynamo" , "backup" , "--create-s3-if-missing" ]
499- )
524+ result = runner .invoke (app , ["dynamo" , "backup" , "--create-s3-if-missing" ])
500525 assert result .exit_code == 0 , result .output
501526 assert "Backup written" in result .output
502527
@@ -510,11 +535,13 @@ def test_bootstrap_create_s3_if_missing(self, aws_env, monkeypatch, tmp_path):
510535 result = runner .invoke (
511536 app ,
512537 [
513- "dynamo" , "bootstrap" ,
514- "--config-file" , str (cfg ),
538+ "dynamo" ,
539+ "bootstrap" ,
540+ "--config-file" ,
541+ str (cfg ),
515542 "--no-include-package" ,
516543 "--create-s3-if-missing" ,
517544 ],
518545 )
519546 assert result .exit_code == 0 , result .output
520- assert "created" in result .output .lower () or "Config uploaded" in result .output
547+ assert "created" in result .output .lower () or "Config uploaded" in result .output
0 commit comments