Skip to content

Commit

Permalink
feat: add read yml file function (#14)
Browse files Browse the repository at this point in the history
* feat: add adapter module

* test: checking if sam is an instance of fastapi

* refactor: sort imports

* build: add pyyaml dependency

* feat: add read yaml file function

* test: add read yaml file test

* refactor: transform intrinsic cloud formation into yaml valid template

* refactor: improve tests

* refactor: use relative path

* feat: add pyyaml to package's depencies

* wip: create cloudformation template loader module

* feat: add constructor SAM class

* test: add sam class initialization tests

* chore: delete templete.yaml file

* test: add test initialization without template

* refactor: deleting duplicate tests

---------

Co-authored-by: Gabriel Figueiredo <[email protected]>
Co-authored-by: Juliano Fernandes <[email protected]>
  • Loading branch information
3 people authored Nov 28, 2023
1 parent 3c74bfe commit 55a9d57
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
8 changes: 7 additions & 1 deletion src/adapter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
from typing import Optional

from fastapi import FastAPI

import cloudformation


class SAM(FastAPI):
...
def __init__(self, template: Optional[str] = None, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
self._cloudformation = cloudformation.load(template)
30 changes: 26 additions & 4 deletions tests/test_adapter.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,33 @@
import unittest

from fastapi import FastAPI
from pathlib import Path

from adapter import SAM
from cloudformation import CFTemplateNotFound


class TestSAMAdapter(unittest.TestCase):
def test_sam_instance_of_fastapi(self):
def setUp(self) -> None:
self.path_templates = "tests/fixtures/templates"

def test_initialization_with_template(self):
sam = SAM(f"{self.path_templates}/example1.yml")

self.assertIsNotNone(sam._cloudformation)
self.assertIsInstance(sam._cloudformation, dict)
self.assertIn("Resources", sam._cloudformation)

def test_initialization_without_template(self):
symlink = Path("template.yml")
symlink.symlink_to("tests/fixtures/templates/example1.yml")

sam = SAM()
self.assertIsInstance(sam, FastAPI)

symlink.unlink()

self.assertIsNotNone(sam._cloudformation)
self.assertIsInstance(sam._cloudformation, dict)
self.assertIn("Resources", sam._cloudformation)

def test_initialization_without_template_exception(self):
with self.assertRaises(CFTemplateNotFound):
SAM()

0 comments on commit 55a9d57

Please sign in to comment.