Skip to content

Commit

Permalink
Release version 0.1.4 📣
Browse files Browse the repository at this point in the history
Changed project architecture
  • Loading branch information
ycd committed Aug 16, 2020
2 parents ce0ef14 + 6e87333 commit c7561d4
Show file tree
Hide file tree
Showing 12 changed files with 98 additions and 63 deletions.
21 changes: 17 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

**Source Code**: View it on [Github](https://github.com/ycd/manage-fastapi/)


**Installation**: `pip install manage-fastapi`
---


Expand All @@ -44,12 +44,19 @@
<img src="docs_assets/startproject.png" width=700>


## Example folder structure for more check [documentation](https://ycd.github.io/manage-fastapi/)
## Example folder structure with two commands :open_file_folder:

```
manage-fastapi startproject fastproject
manage-fastapi startapp v1
```
newproject/


```
fastproject/
├── __init__.py
├── main.py
├── newproject
├── core
│   ├── models
│   │   ├── database.py
│   │   └── __init__.py
Expand Down Expand Up @@ -79,6 +86,12 @@ newproject/

### Latest Changes

### 0.1.4

* Changed project architecture
* Increased travis tests


### 0.1.3

* Make database optional
Expand Down
4 changes: 2 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@

## Example folder structure 📦
```
newproject/
fastproject/
├── __init__.py
├── main.py
├── newproject
├── core
│   ├── models
│   │   ├── database.py
│   │   └── __init__.py
Expand Down
6 changes: 3 additions & 3 deletions docs/managing_apps/startapp.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ Application v1 created successfully!
Let's see what it created. Now we have a new folder called **v1** and another folder called **v1** under our **tests** folder. Let's see what they have.

```python
newproject/
fastproject/
├── __init__.py
├── main.py
├── newproject
├── core
│   ├── models
│   │   ├── database.py
│   │   └── __init__.py
Expand All @@ -41,7 +41,7 @@ newproject/
└── __init__.py
```

In our **`myproject/myapp`** we have new **1 directory and 4 files**, let's see what they have.
In our **`fastproject/v1`** we have new **1 directory and 4 files**, let's see what they have.

In our `endpoints` folder we are going create all the endpoints for this app, also `endpoints.py` comes with a basic Hello world router,

Expand Down
18 changes: 9 additions & 9 deletions docs/managing_projects/startproject.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ To start a new project with Manage FastAPI, you can use this:

* `manage-fastapi startproject [project-name]` - Create a new project.

This will create create **4 directories and 8 files** for you. Let's see what it includes, for instance i'm creating a new project called **newproject**
This will create create **4 directories and 8 files** for you. Let's see what it includes, for instance i'm creating a new project called **fastproject**

```shell
manage-fastapi startproject newproject
manage-fastapi startproject fastproject

Project newproject created successfully!
Project fastproject created successfully!
```

The command we ran above, created a `main.py` that will include all our external app's. A folder called **models** for our database stuff, another folder called **schemas** for our Pydantic models etc and a `settings.py` file.

```shell
newproject/
fastproject/
├── __init__.py
├── main.py
├── newproject
├── core
│   ├── models
│   │   ├── database.py
│   │   └── __init__.py
Expand All @@ -35,8 +35,8 @@ Our **`main.py`** gonna be our controller. It will include all the routers other
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware

from newproject.settings import settings
from newproject.models.database import database
from fastproject.settings import settings
from fastproject.models.database import database

app = FastAPI(title=settings.PROJECT_NAME)

Expand Down Expand Up @@ -68,7 +68,7 @@ from pydantic import BaseSettings, AnyHttpUrl, HttpUrl, validator


class Settings(BaseSettings):
PROJECT_NAME: str = "newproject"
PROJECT_NAME: str = "fastproject"

BACKEND_CORS_ORIGINS: List[AnyHttpUrl] = [
"http://localhost",
Expand Down Expand Up @@ -113,7 +113,7 @@ In **`models/database.py`** we create all our database stuff, If you don't need

```python
import sqlalchemy
from newproject.settings import settings
from fastproject.settings import settings
import databases

database = databases.Database(settings.DATABASE_URL)
Expand Down
6 changes: 6 additions & 0 deletions docs/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

### Latest Changes

### 0.1.4

* Changed project architecture
* Increased travis tests


### 0.1.3

* Make database optional
Expand Down
2 changes: 1 addition & 1 deletion manage_fastapi/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.1.3"
__version__ = "0.1.4"
18 changes: 9 additions & 9 deletions manage_fastapi/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,11 @@ def test_read_items():
tortoise_main_template = """from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from {project_name}.{project_name}.models.database import Example
from {project_name}.core.models.database import Example
from tortoise.contrib.fastapi import HTTPNotFoundError, register_tortoise
from {project_name}.{project_name}.settings import settings
from {project_name}.core.settings import settings
app = FastAPI(title=settings.PROJECT_NAME)
Expand Down Expand Up @@ -182,7 +182,7 @@ class PydanticMeta:
empty_main_template = """from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from {project_name}.settings import settings
from {project_name}.core.settings import settings
if settings.BACKEND_CORS_ORIGINS:
app.add_middleware(
Expand All @@ -199,8 +199,8 @@ class PydanticMeta:
async_sql_main_template = """from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from {project_name}.{project_name}.settings import settings
from {project_name}.{project_name}.models.database import database
from {project_name}.core.settings import settings
from {project_name}.core.models.database import database
app = FastAPI(title=settings.PROJECT_NAME)
Expand All @@ -224,7 +224,7 @@ async def disconnect_database():
"""

async_sql_database_template = """import sqlalchemy
from {project_name}.{project_name}.settings import settings
from {project_name}.core.settings import settings
import databases
database = databases.Database(settings.DATABASE_URL)
Expand All @@ -246,8 +246,8 @@ async def disconnect_database():
mongo_main_template = """from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from {project_name}.{project_name}.settings import settings
from {project_name}.{project_name}.models.utils import connect_to_mongo, close_mongo_connection
from {project_name}.core.settings import settings
from {project_name}.core.models.utils import connect_to_mongo, close_mongo_connection
app = FastAPI()
Expand Down Expand Up @@ -283,7 +283,7 @@ async def get_database() -> AsyncIOMotorClient:
mongo_utils_template = """import logging
from motor.motor_asyncio import AsyncIOMotorClient
from {project_name}.{project_name}.models.database import db
from {project_name}.core.models.database import db
logger = logging.getLogger(__name__)
Expand Down
5 changes: 4 additions & 1 deletion manage_fastapi/tests/test_utils_startapp.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from typer.testing import CliRunner

import os
from manage_fastapi.main import app

runner = CliRunner()
Expand All @@ -9,6 +9,9 @@ def test_startapp_single():
result = runner.invoke(app, ["startapp", "myapp"])
assert result.exit_code == 0
assert "Application myapp created successfully!" in result.stdout
os.path.exists("./myapp")
os.path.exists("./tests/myapp")
os.path.exists("./myapp/endpoints")


def test_startapp_duplicate():
Expand Down
28 changes: 23 additions & 5 deletions manage_fastapi/tests/test_utils_startproject.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,38 @@

from manage_fastapi.main import app

import os

runner = CliRunner()


def test_startproject_single():
result = runner.invoke(app, ["startproject", "myproject"], "0")
result = runner.invoke(app, ["startproject", "test_one"], "0")
result_two = runner.invoke(app, ["startproject", "test_two"], "1")
assert result.exit_code == 0
assert (
"Project myproject created successfully!\nWe created requirements file for your project needs."
"Project test_one created successfully!\nWe created requirements file for your project needs."
in result.stdout
)
assert result_two.exit_code == 0
assert (
"Project test_two created successfully!\nWe created requirements file for your project needs."
in result_two.stdout
)
assert os.path.isdir("./test_one")
assert os.path.isdir("./test_one/core")
assert os.path.isdir("./test_one/core/models")
assert os.path.isdir("./test_one/core/schemas")
assert os.path.isdir("./test_two")
assert os.path.isdir("./test_two/core")
assert os.path.isdir("./test_two/core/models")
assert os.path.isdir("./test_two/core/schemas")


def test_startproject_duplicate():
result = runner.invoke(app, ["startproject", "myproject"], "2")
result = runner.invoke(app, ["startproject", "test_one"], "2")
result_two = runner.invoke(app, ["startproject", "test_two"], "9")
assert result.exit_code == 0
assert "Project myproject already exists!" in result.stdout

assert "Project test_one already exists!" in result.stdout
assert result_two.exit_code == 0
assert "Project test_two already exists!" in result_two.stdout
2 changes: 1 addition & 1 deletion manage_fastapi/tests/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@


def test_version():
assert __version__ == "0.1.3"
assert __version__ == "0.1.4"

0 comments on commit c7561d4

Please sign in to comment.