init commit
This commit is contained in:
parent
dd619df7a2
commit
07d201d3ae
|
|
@ -21,4 +21,6 @@
|
|||
#docs/*.md
|
||||
# Then explicitly reverse the ignore rule for a single file:
|
||||
#!docs/README.md
|
||||
openapi_server/controllers/patchnotes_controller.py
|
||||
gen/openapi_server/controllers/patchnotes_controller.py
|
||||
gen/openapi_server/__main__.py
|
||||
gen/openapi_server/encoder.py
|
||||
|
|
|
|||
|
|
@ -3,11 +3,13 @@ FROM python:3-alpine
|
|||
RUN mkdir -p /usr/src/app
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
COPY requirements.txt /usr/src/app/
|
||||
COPY gen/requirements.txt /usr/src/app/
|
||||
|
||||
RUN pip install --upgrade pip
|
||||
|
||||
RUN pip3 install --no-cache-dir -r requirements.txt
|
||||
|
||||
COPY . /usr/src/app
|
||||
COPY gen /usr/src/app
|
||||
|
||||
EXPOSE 8080
|
||||
|
||||
|
|
@ -5,37 +5,10 @@ info:
|
|||
version: 1.0.0
|
||||
paths:
|
||||
/patchnotes:
|
||||
get:
|
||||
tags:
|
||||
- Patchnotes
|
||||
description: returns list of all unseen Patch notes from the user
|
||||
operationId: get_patchnotes
|
||||
requestBody:
|
||||
description: last seen patchnote by the user
|
||||
required: true
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
title: date
|
||||
type: string
|
||||
responses:
|
||||
"200":
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
items:
|
||||
$ref: '#/components/schemas/patch_notes'
|
||||
type: array
|
||||
description: returns list of all unseen Patch notes from the user
|
||||
"404":
|
||||
description: no Patch notes found
|
||||
"500":
|
||||
description: Internal Server error, Failed to get Patch Notes
|
||||
post:
|
||||
tags:
|
||||
- Patchnotes
|
||||
description: creates new Patch notes
|
||||
operationId: post_patchnotes
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
|
|
@ -54,7 +27,6 @@ paths:
|
|||
tags:
|
||||
- Patchnotes
|
||||
description: deletes one Patch note
|
||||
operationId: patch_note_delete
|
||||
parameters:
|
||||
- in: path
|
||||
name: patchID
|
||||
|
|
@ -70,6 +42,35 @@ paths:
|
|||
description: patch not found
|
||||
"500":
|
||||
description: Internal Server Error, Patch not deleted
|
||||
/patchnotes/{date}:
|
||||
get:
|
||||
description: returns list of all unseen Patch notes from the user
|
||||
parameters:
|
||||
- explode: false
|
||||
in: path
|
||||
name: date
|
||||
required: true
|
||||
schema:
|
||||
format: date
|
||||
type: string
|
||||
style: simple
|
||||
example: 2025-01-02
|
||||
responses:
|
||||
"200":
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/patch_notes'
|
||||
description: returns list of all unseen Patch notes from the user
|
||||
"404":
|
||||
description: no Patch notes found
|
||||
"500":
|
||||
description: "Internal Server error, Failed to get Patch Notes"
|
||||
tags:
|
||||
- Patchnotes
|
||||
x-openapi-router-controller: openapi_server.controllers.patchnotes_controller
|
||||
components:
|
||||
schemas:
|
||||
patch_notes:
|
||||
|
|
@ -77,7 +78,7 @@ components:
|
|||
patchID: 29e80bcc-5981-4a52-99e1-373442dea9b9
|
||||
title: Patch note 1
|
||||
changes: changes
|
||||
date: date
|
||||
date: 2025-01-02
|
||||
properties:
|
||||
patchID:
|
||||
format: uuid
|
||||
|
|
@ -94,9 +95,9 @@ components:
|
|||
type: string
|
||||
user:
|
||||
example:
|
||||
lastNoteChecked: f00fa08d-0cd8-4c05-9409-5e75aa2d4f68
|
||||
lastSeenDate: 2025-01-02
|
||||
properties:
|
||||
lastNoteChecked:
|
||||
format: uuid
|
||||
lastSeenDate:
|
||||
format: date
|
||||
title: lastNoteChecked
|
||||
type: string
|
||||
24
app.py
24
app.py
|
|
@ -1,4 +1,4 @@
|
|||
from flask import Flask
|
||||
from flask import Flask, jsonify, request
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
|
|
@ -7,6 +7,28 @@ app = Flask(__name__)
|
|||
def hello_world(): # put application's code here
|
||||
return 'Hello World!'
|
||||
|
||||
@app.route('/patchnotes', methods=['POST'])
|
||||
def post_patchnotes():
|
||||
patch_note = request.get_json()
|
||||
patch_notes_db.append(patch_note)
|
||||
return jsonify(patch_notes_db), 200
|
||||
|
||||
@app.route('/patchnotes/<string:patchID>', methods=['DELETE'])
|
||||
def delete_patchnote(patchID):
|
||||
global patch_notes_db
|
||||
patch_notes_db = [note for note in patch_notes_db if note['patchID'] != patchID]
|
||||
if any(note['patchID'] == patchID for note in patch_notes_db):
|
||||
return jsonify({'error': 'Patch not deleted'}), 500
|
||||
else:
|
||||
return jsonify({'message': 'patch successfully deleted'}), 200
|
||||
|
||||
@app.route('/patchnotes/<string:date>', methods=['GET'])
|
||||
def get_patchnotes(date):
|
||||
unseen_notes = [note for note in patch_notes_db if note['date'] == date]
|
||||
if unseen_notes:
|
||||
return jsonify(unseen_notes), 200
|
||||
else:
|
||||
return jsonify({'error': 'no Patch notes found'}), 404
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run()
|
||||
|
|
|
|||
|
|
@ -21,3 +21,5 @@
|
|||
#docs/*.md
|
||||
# Then explicitly reverse the ignore rule for a single file:
|
||||
#!docs/README.md
|
||||
openapi_server/controllers/patchnotes_controller.py
|
||||
openapi_server/__main__.py
|
||||
|
|
|
|||
|
|
@ -1,28 +1,22 @@
|
|||
.github/workflows/python.yml
|
||||
.dockerignore
|
||||
.gitignore
|
||||
.gitlab-ci.yml
|
||||
.travis.yml
|
||||
Dockerfile
|
||||
README.md
|
||||
docs/PatchNotes.md
|
||||
docs/PatchnotesApi.md
|
||||
docs/User.md
|
||||
git_push.sh
|
||||
openapi_client/__init__.py
|
||||
openapi_client/api/__init__.py
|
||||
openapi_client/api/patchnotes_api.py
|
||||
openapi_client/api_client.py
|
||||
openapi_client/api_response.py
|
||||
openapi_client/configuration.py
|
||||
openapi_client/exceptions.py
|
||||
openapi_client/models/__init__.py
|
||||
openapi_client/models/patch_notes.py
|
||||
openapi_client/models/user.py
|
||||
openapi_client/py.typed
|
||||
openapi_client/rest.py
|
||||
pyproject.toml
|
||||
openapi_server/__init__.py
|
||||
openapi_server/controllers/__init__.py
|
||||
openapi_server/controllers/security_controller.py
|
||||
openapi_server/encoder.py
|
||||
openapi_server/models/__init__.py
|
||||
openapi_server/models/base_model.py
|
||||
openapi_server/models/patch_notes.py
|
||||
openapi_server/models/user.py
|
||||
openapi_server/openapi/openapi.yaml
|
||||
openapi_server/test/__init__.py
|
||||
openapi_server/typing_utils.py
|
||||
openapi_server/util.py
|
||||
requirements.txt
|
||||
setup.cfg
|
||||
setup.py
|
||||
test-requirements.txt
|
||||
test/__init__.py
|
||||
tox.ini
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
7.7.0
|
||||
7.12.0-SNAPSHOT
|
||||
|
|
|
|||
|
|
@ -1,17 +1,14 @@
|
|||
# ref: https://docs.travis-ci.com/user/languages/python
|
||||
language: python
|
||||
python:
|
||||
- "3.2"
|
||||
- "3.3"
|
||||
- "3.4"
|
||||
- "3.5"
|
||||
- "3.6"
|
||||
- "3.7"
|
||||
- "3.8"
|
||||
- "3.9"
|
||||
- "3.10"
|
||||
- "3.11"
|
||||
# uncomment the following if needed
|
||||
#- "3.11-dev" # 3.11 development branch
|
||||
#- "nightly" # nightly build
|
||||
# command to install dependencies
|
||||
install:
|
||||
- "pip install -r requirements.txt"
|
||||
- "pip install -r test-requirements.txt"
|
||||
install: "pip install -r requirements.txt"
|
||||
# command to run tests
|
||||
script: pytest --cov=openapi_client
|
||||
script: nosetests
|
||||
|
|
|
|||
127
gen/README.md
127
gen/README.md
|
|
@ -1,108 +1,49 @@
|
|||
# openapi-client
|
||||
Announcing patchnotes for KanzleiApp
|
||||
# OpenAPI generated server
|
||||
|
||||
This Python package is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project:
|
||||
## Overview
|
||||
This server was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. By using the
|
||||
[OpenAPI-Spec](https://openapis.org) from a remote server, you can easily generate a server stub. This
|
||||
is an example of building a OpenAPI-enabled Flask server.
|
||||
|
||||
- API version: 1.0.0
|
||||
- Package version: 1.0.0
|
||||
- Generator version: 7.7.0
|
||||
- Build package: org.openapitools.codegen.languages.PythonClientCodegen
|
||||
This example uses the [Connexion](https://github.com/zalando/connexion) library on top of Flask.
|
||||
|
||||
## Requirements.
|
||||
## Requirements
|
||||
Python 3.5.2+
|
||||
|
||||
Python 3.7+
|
||||
|
||||
## Installation & Usage
|
||||
### pip install
|
||||
|
||||
If the python package is hosted on a repository, you can install directly using:
|
||||
|
||||
```sh
|
||||
pip install git+https://github.com/GIT_USER_ID/GIT_REPO_ID.git
|
||||
```
|
||||
(you may need to run `pip` with root permission: `sudo pip install git+https://github.com/GIT_USER_ID/GIT_REPO_ID.git`)
|
||||
|
||||
Then import the package:
|
||||
```python
|
||||
import openapi_client
|
||||
```
|
||||
|
||||
### Setuptools
|
||||
|
||||
Install via [Setuptools](http://pypi.python.org/pypi/setuptools).
|
||||
|
||||
```sh
|
||||
python setup.py install --user
|
||||
```
|
||||
(or `sudo python setup.py install` to install the package for all users)
|
||||
|
||||
Then import the package:
|
||||
```python
|
||||
import openapi_client
|
||||
```
|
||||
|
||||
### Tests
|
||||
|
||||
Execute `pytest` to run the tests.
|
||||
|
||||
## Getting Started
|
||||
|
||||
Please follow the [installation procedure](#installation--usage) and then run the following:
|
||||
|
||||
```python
|
||||
|
||||
import openapi_client
|
||||
from openapi_client.rest import ApiException
|
||||
from pprint import pprint
|
||||
|
||||
# Defining the host is optional and defaults to http://localhost
|
||||
# See configuration.py for a list of all supported configuration parameters.
|
||||
configuration = openapi_client.Configuration(
|
||||
host = "http://localhost"
|
||||
)
|
||||
|
||||
|
||||
|
||||
# Enter a context with an instance of the API client
|
||||
with openapi_client.ApiClient(configuration) as api_client:
|
||||
# Create an instance of the API class
|
||||
api_instance = openapi_client.PatchnotesApi(api_client)
|
||||
body = 'body_example' # str | last seen patchnote by the user
|
||||
|
||||
try:
|
||||
api_response = api_instance.get_patchnotes(body)
|
||||
print("The response of PatchnotesApi->get_patchnotes:\n")
|
||||
pprint(api_response)
|
||||
except ApiException as e:
|
||||
print("Exception when calling PatchnotesApi->get_patchnotes: %s\n" % e)
|
||||
## Usage
|
||||
To run the server, please execute the following from the root directory:
|
||||
|
||||
```
|
||||
pip3 install -r requirements.txt
|
||||
python3 -m openapi_server
|
||||
```
|
||||
|
||||
## Documentation for API Endpoints
|
||||
and open your browser to here:
|
||||
|
||||
All URIs are relative to *http://localhost*
|
||||
```
|
||||
http://localhost:8080/ui/
|
||||
```
|
||||
|
||||
Class | Method | HTTP request | Description
|
||||
------------ | ------------- | ------------- | -------------
|
||||
*PatchnotesApi* | [**get_patchnotes**](docs/PatchnotesApi.md#get_patchnotes) | **GET** /patchnotes | gets all unseen Patchnotes from the User
|
||||
*PatchnotesApi* | [**patch_note_delete**](docs/PatchnotesApi.md#patch_note_delete) | **DELETE** /patchnotes/{patchID} | Deletes selected Patchnote
|
||||
*PatchnotesApi* | [**post_patchnotes**](docs/PatchnotesApi.md#post_patchnotes) | **POST** /patchnotes | Creates a new Patchnote
|
||||
Your OpenAPI definition lives here:
|
||||
|
||||
```
|
||||
http://localhost:8080/openapi.json
|
||||
```
|
||||
|
||||
## Documentation For Models
|
||||
To launch the integration tests, use tox:
|
||||
```
|
||||
sudo pip install tox
|
||||
tox
|
||||
```
|
||||
|
||||
- [PatchNotes](docs/PatchNotes.md)
|
||||
- [User](docs/User.md)
|
||||
## Running with Docker
|
||||
|
||||
To run the server on a Docker container, please execute the following from the root directory:
|
||||
|
||||
<a id="documentation-for-authorization"></a>
|
||||
## Documentation For Authorization
|
||||
|
||||
Endpoints do not require authorization.
|
||||
|
||||
|
||||
## Author
|
||||
|
||||
Justin Weins
|
||||
|
||||
```bash
|
||||
# building the image
|
||||
docker build -t openapi_server .
|
||||
|
||||
# starting up a container
|
||||
docker run -p 8080:8080 openapi_server
|
||||
```
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
#!/bin/sh
|
||||
|
||||
PORT=${PORT:-8080}
|
||||
|
||||
gunicorn --workers 4 \
|
||||
--forwarded-allow-ips="*" \
|
||||
--bind 0.0.0.0:$PORT \
|
||||
--worker-class uvicorn.workers.UvicornWorker \
|
||||
--preload \
|
||||
openapi_server.__main__:app
|
||||
|
|
@ -1,20 +1,22 @@
|
|||
#!/usr/bin/env python3
|
||||
import logging
|
||||
|
||||
import connexion
|
||||
|
||||
from openapi_server import encoder
|
||||
from pymongo import MongoClient
|
||||
|
||||
client = MongoClient(host='mongodb://localhost:27017/')
|
||||
db = client["MainDB"]
|
||||
collection = db['patch_notes']
|
||||
|
||||
def main():
|
||||
app = connexion.App(__name__, specification_dir='./openapi/')
|
||||
app.app.json_encoder = encoder.JSONEncoder
|
||||
app.add_api('openapi.yaml',
|
||||
base_path='/api',
|
||||
arguments={'title': 'announcementService'},
|
||||
pythonic_params=True)
|
||||
|
||||
app.run(port=8080)
|
||||
|
||||
app = connexion.App(__name__, specification_dir='./openapi/')
|
||||
app.app.logger.setLevel(logging.DEBUG)
|
||||
app.app.json_encoder = encoder.JSONEncoder
|
||||
app.add_api('openapi.yaml',
|
||||
base_path='/api',
|
||||
arguments={'title': 'announcementService'},
|
||||
pythonic_params=True)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
app.run(port=8080, host='0.0.0.0')
|
||||
|
|
@ -1,25 +1,45 @@
|
|||
import logging
|
||||
|
||||
import connexion
|
||||
from typing import Dict
|
||||
from typing import Tuple
|
||||
from typing import Union
|
||||
|
||||
from bson import json_util
|
||||
from flask import Response
|
||||
from pymongo import MongoClient
|
||||
|
||||
from openapi_server.__main__ import collection
|
||||
from openapi_server.models.patch_notes import PatchNotes # noqa: E501
|
||||
from openapi_server import util
|
||||
|
||||
|
||||
def get_patchnotes(): # noqa: E501
|
||||
"""get_patchnotes
|
||||
|
||||
def patchnotes_date_get(date): # noqa: E501
|
||||
"""patchnotes_date_get
|
||||
|
||||
returns list of all unseen Patch notes from the user # noqa: E501
|
||||
|
||||
:param date:
|
||||
:type date: str
|
||||
|
||||
:rtype: Union[List[PatchNotes], Tuple[List[PatchNotes], int], Tuple[List[PatchNotes], int, Dict[str, str]]
|
||||
"""
|
||||
return 'do some magic!'
|
||||
# TODO Implement this:
|
||||
|
||||
# try:
|
||||
# formatted_date = response_data.strftime('%Y-%m-%d')
|
||||
# logging.error(formatted_date)
|
||||
# logging.info("valid date")
|
||||
# except ValueError:
|
||||
# logging.error("Not valid date")
|
||||
return date
|
||||
# _date = util.deserialize_date(date)
|
||||
# return 'do some magic!'
|
||||
|
||||
|
||||
def patch_note_delete(patch_id): # noqa: E501
|
||||
"""patch_note_delete
|
||||
def patchnotes_patch_iddelete(patch_id): # noqa: E501
|
||||
"""patchnotes_patch_iddelete
|
||||
|
||||
deletes one Patch note # noqa: E501
|
||||
|
||||
|
|
@ -32,8 +52,8 @@ def patch_note_delete(patch_id): # noqa: E501
|
|||
return 'do some magic!'
|
||||
|
||||
|
||||
def post_patchnotes(body=None): # noqa: E501
|
||||
"""post_patchnotes
|
||||
def patchnotes_post(body=None): # TODO done for now
|
||||
"""patchnotes_post
|
||||
|
||||
creates new Patch notes # noqa: E501
|
||||
|
||||
|
|
@ -43,9 +63,11 @@ def post_patchnotes(body=None): # noqa: E501
|
|||
:rtype: Union[List[PatchNotes], Tuple[List[PatchNotes], int], Tuple[List[PatchNotes], int, Dict[str, str]]
|
||||
"""
|
||||
patch_notes = body
|
||||
with conn.cursor() as cur:
|
||||
player_name = player_post_request.name
|
||||
player_id = uuid.uuid4()
|
||||
cur.execute(f"INSERT INTO player VALUES ('{player_id}','{player_name}');")
|
||||
conn.commit() # noqa: E501
|
||||
return 'do some magic!'
|
||||
logging.error('patch notes' + str(patch_notes))
|
||||
if patch_notes is None:
|
||||
return Response(json_util.dumps({'error': 'No patch notes provided'}), status=400)
|
||||
# Insert the document into the MongoDB collection
|
||||
posted_patch_id = collection.insert_one(patch_notes)
|
||||
|
||||
return Response(json_util.dumps(f'patch with ID: {posted_patch_id} was created'), mimetype='application/json',
|
||||
status=200)
|
||||
|
|
@ -1,9 +1,8 @@
|
|||
from connexion.apps.flask_app import FlaskJSONEncoder
|
||||
|
||||
from connexion.jsonifier import JSONEncoder as ConnexionJSONEncoder
|
||||
from openapi_server.models.base_model import Model
|
||||
|
||||
|
||||
class JSONEncoder(FlaskJSONEncoder):
|
||||
class JSONEncoder(ConnexionJSONEncoder):
|
||||
include_nulls = False
|
||||
|
||||
def default(self, o):
|
||||
|
|
@ -16,4 +15,4 @@ class JSONEncoder(FlaskJSONEncoder):
|
|||
attr = o.attribute_map[attr]
|
||||
dikt[attr] = value
|
||||
return dikt
|
||||
return FlaskJSONEncoder.default(self, o)
|
||||
return ConnexionJSONEncoder.default(self, o)
|
||||
|
|
@ -12,21 +12,21 @@ class User(Model):
|
|||
Do not edit the class manually.
|
||||
"""
|
||||
|
||||
def __init__(self, last_note_checked=None): # noqa: E501
|
||||
def __init__(self, last_seen_date=None): # noqa: E501
|
||||
"""User - a model defined in OpenAPI
|
||||
|
||||
:param last_note_checked: The last_note_checked of this User. # noqa: E501
|
||||
:type last_note_checked: str
|
||||
:param last_seen_date: The last_seen_date of this User. # noqa: E501
|
||||
:type last_seen_date: date
|
||||
"""
|
||||
self.openapi_types = {
|
||||
'last_note_checked': str
|
||||
'last_seen_date': date
|
||||
}
|
||||
|
||||
self.attribute_map = {
|
||||
'last_note_checked': 'lastNoteChecked'
|
||||
'last_seen_date': 'lastSeenDate'
|
||||
}
|
||||
|
||||
self._last_note_checked = last_note_checked
|
||||
self._last_seen_date = last_seen_date
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, dikt) -> 'User':
|
||||
|
|
@ -40,22 +40,22 @@ class User(Model):
|
|||
return util.deserialize_model(dikt, cls)
|
||||
|
||||
@property
|
||||
def last_note_checked(self) -> str:
|
||||
"""Gets the last_note_checked of this User.
|
||||
def last_seen_date(self) -> date:
|
||||
"""Gets the last_seen_date of this User.
|
||||
|
||||
|
||||
:return: The last_note_checked of this User.
|
||||
:rtype: str
|
||||
:return: The last_seen_date of this User.
|
||||
:rtype: date
|
||||
"""
|
||||
return self._last_note_checked
|
||||
return self._last_seen_date
|
||||
|
||||
@last_note_checked.setter
|
||||
def last_note_checked(self, last_note_checked: str):
|
||||
"""Sets the last_note_checked of this User.
|
||||
@last_seen_date.setter
|
||||
def last_seen_date(self, last_seen_date: date):
|
||||
"""Sets the last_seen_date of this User.
|
||||
|
||||
|
||||
:param last_note_checked: The last_note_checked of this User.
|
||||
:type last_note_checked: str
|
||||
:param last_seen_date: The last_seen_date of this User.
|
||||
:type last_seen_date: date
|
||||
"""
|
||||
|
||||
self._last_note_checked = last_note_checked
|
||||
self._last_seen_date = last_seen_date
|
||||
|
|
|
|||
|
|
@ -4,31 +4,12 @@ info:
|
|||
title: announcementService
|
||||
version: 1.0.0
|
||||
servers:
|
||||
- url: /
|
||||
- url: http://127.0.0.1:8080/api
|
||||
paths:
|
||||
/patchnotes:
|
||||
get:
|
||||
description: returns list of all unseen Patch notes from the user
|
||||
operationId: get_patchnotes
|
||||
responses:
|
||||
"200":
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
items:
|
||||
$ref: '#/components/schemas/patch_notes'
|
||||
type: array
|
||||
description: returns list of all unseen Patch notes from the user
|
||||
"404":
|
||||
description: no Patch notes found
|
||||
"500":
|
||||
description: "Internal Server error, Failed to get Patch Notes"
|
||||
tags:
|
||||
- Patchnotes
|
||||
x-openapi-router-controller: openapi_server.controllers.patchnotes_controller
|
||||
post:
|
||||
description: creates new Patch notes
|
||||
operationId: post_patchnotes
|
||||
operationId: patchnotes_post
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
|
|
@ -46,10 +27,40 @@ paths:
|
|||
tags:
|
||||
- Patchnotes
|
||||
x-openapi-router-controller: openapi_server.controllers.patchnotes_controller
|
||||
/patchnotes/{date}:
|
||||
get:
|
||||
description: returns list of all unseen Patch notes from the user
|
||||
operationId: patchnotes_date_get
|
||||
parameters:
|
||||
- example: 2025-01-02
|
||||
explode: false
|
||||
in: path
|
||||
name: date
|
||||
required: true
|
||||
schema:
|
||||
format: date
|
||||
type: string
|
||||
style: simple
|
||||
responses:
|
||||
"200":
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
items:
|
||||
$ref: '#/components/schemas/patch_notes'
|
||||
type: array
|
||||
description: returns list of all unseen Patch notes from the user
|
||||
"404":
|
||||
description: no Patch notes found
|
||||
"500":
|
||||
description: "Internal Server error, Failed to get Patch Notes"
|
||||
tags:
|
||||
- Patchnotes
|
||||
x-openapi-router-controller: openapi_server.controllers.patchnotes_controller
|
||||
/patchnotes/{patchID}:
|
||||
delete:
|
||||
description: deletes one Patch note
|
||||
operationId: patch_note_delete
|
||||
operationId: patchnotes_patch_iddelete
|
||||
parameters:
|
||||
- explode: false
|
||||
in: path
|
||||
|
|
@ -76,7 +87,7 @@ components:
|
|||
patchID: 29e80bcc-5981-4a52-99e1-373442dea9b9
|
||||
title: Patch note 1
|
||||
changes: changes
|
||||
date: date
|
||||
date: 2025-01-02
|
||||
properties:
|
||||
patchID:
|
||||
format: uuid
|
||||
|
|
@ -94,9 +105,9 @@ components:
|
|||
title: patch_notes
|
||||
user:
|
||||
example:
|
||||
lastNoteChecked: f00fa08d-0cd8-4c05-9409-5e75aa2d4f68
|
||||
lastSeenDate: 2025-01-02
|
||||
properties:
|
||||
lastNoteChecked:
|
||||
format: uuid
|
||||
lastSeenDate:
|
||||
format: date
|
||||
title: lastNoteChecked
|
||||
type: string
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ class BaseTestCase(TestCase):
|
|||
|
||||
def create_app(self):
|
||||
logging.getLogger('connexion.operation').setLevel('ERROR')
|
||||
app = connexion.App(__name__, specification_dir='../openapi/')
|
||||
app = connexion.App(__name__ , specification_dir='../openapi/')
|
||||
app.app.json_encoder = JSONEncoder
|
||||
app.add_api('openapi.yaml', pythonic_params=True)
|
||||
app.add_api('openapi.yaml', pythonic_params=True, base_path='/api')
|
||||
return app.app
|
||||
|
|
|
|||
|
|
@ -2,10 +2,12 @@ import unittest
|
|||
|
||||
from flask import json
|
||||
|
||||
import openapi_server
|
||||
from openapi_server.models.patch_notes import PatchNotes # noqa: E501
|
||||
from openapi_server.test import BaseTestCase
|
||||
|
||||
|
||||
|
||||
class TestDefaultController(BaseTestCase):
|
||||
"""DefaultController integration test stubs"""
|
||||
|
||||
|
|
@ -23,7 +25,8 @@ class TestDefaultController(BaseTestCase):
|
|||
headers=headers)
|
||||
self.assert200(response,
|
||||
'Response body is : ' + response.data.decode('utf-8'))
|
||||
|
||||
response = self.client.get('/patchnotes',)
|
||||
assert response.status_code == 200
|
||||
def test_patch_note_delete(self):
|
||||
"""Test case for patch_note_delete
|
||||
|
||||
|
|
|
|||
|
|
@ -1,62 +1,167 @@
|
|||
import datetime
|
||||
import logging
|
||||
import unittest
|
||||
import unittest.mock as mock
|
||||
from datetime import datetime
|
||||
|
||||
from flask import json
|
||||
from flask import json, url_for
|
||||
|
||||
import openapi_server
|
||||
from openapi_server.models.patch_notes import PatchNotes # noqa: E501
|
||||
import app
|
||||
from openapi_server.test import BaseTestCase
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
|
||||
|
||||
class TestPatchnotesController(BaseTestCase):
|
||||
"""PatchnotesController integration test stubs"""
|
||||
|
||||
def test_get_patchnotes(self):
|
||||
def setUp(self):
|
||||
self.app = app.app
|
||||
self.app.config['SERVER_NAME'] = '127.0.0.1:8080'
|
||||
|
||||
print('url map:' + str(self.app.url_map))
|
||||
|
||||
@unittest.mock.patch(
|
||||
'openapi_server.controllers.patchnotes_controller.patchnotes_date_get')
|
||||
def test_get_patchnotes(self, mock_get_patchnotes):
|
||||
"""Test case for get_patchnotes
|
||||
|
||||
|
||||
"""
|
||||
headers = {
|
||||
headers = {
|
||||
'Accept': 'application/json',
|
||||
}
|
||||
logging.error('self client:' + str(self.client))
|
||||
logging.error('mock get patchnotes' + str(mock_get_patchnotes))
|
||||
response = self.client.open(
|
||||
'/patchnotes',
|
||||
'/patchnotes/2025-01-02',
|
||||
method='GET',
|
||||
headers=headers)
|
||||
self.assert200(response,
|
||||
'Response body is : ' + response.data.decode('utf-8'))
|
||||
headers=headers
|
||||
)
|
||||
response_data = response.data.decode('utf-8').strip().strip('\"')
|
||||
logging.error(response_data + "response_data")
|
||||
response_data_type = type(response_data)
|
||||
logging.error("response_data_type:" + str(response_data_type))
|
||||
logging.error("response data" + response_data)
|
||||
response_data = datetime.strptime(response_data, '%Y-%m-%d').date()
|
||||
logging.error(str(response_data) + "response_data after format")
|
||||
try:
|
||||
formatted_date = response_data.strftime('%Y-%m-%d')
|
||||
logging.error(formatted_date)
|
||||
logging.info("valid date")
|
||||
except ValueError:
|
||||
logging.error("Not valid date")
|
||||
self.assert200(response, 'Response body is : ' + response.data.decode('utf-8'))
|
||||
|
||||
@unittest.mock.patch('openapi_server.controllers.patchnotes_controller.patchnotes_date_get')
|
||||
def test_get_patchnotes_404(self, mock_get_patchnotes): # DONE
|
||||
"""Test case for get_patchnotes
|
||||
|
||||
"""
|
||||
|
||||
headers = {
|
||||
'Accept': 'application/json',
|
||||
}
|
||||
|
||||
with self.app.test_request_context():
|
||||
full_url = url_for('get_patchnotes', date='2023-01-01', _external=True)
|
||||
logging.error("Full URL: " + full_url)
|
||||
url = '/api/patchnotes/{date}'.format(date='2023-01-01')
|
||||
logging.error(f"request URL: {url}")
|
||||
logging.error('self client:' + str(self.client))
|
||||
logging.error('mock get patchnotes' + str(mock_get_patchnotes))
|
||||
logging.error('self name stuff:' + str(self.app.config['SERVER_NAME']))
|
||||
response = self.client.open(
|
||||
url,
|
||||
method='GET',
|
||||
headers=headers
|
||||
)
|
||||
logging.error(f"Response Status Code: {response.status_code}")
|
||||
logging.error(f"Response Data: {response.data.decode('utf-8')}")
|
||||
self.assert404(response, 'Response body is : ' + response.data.decode('utf-8'))
|
||||
|
||||
@unittest.mock.patch('openapi_server.controllers.patchnotes_controller.patchnotes_patch_iddelete')
|
||||
def test_patch_note_delete(self, balala):
|
||||
|
||||
def test_patch_note_delete(self):
|
||||
"""Test case for patch_note_delete
|
||||
|
||||
|
||||
"""
|
||||
headers = {
|
||||
headers = {
|
||||
}
|
||||
response = self.client.open(
|
||||
'/patchnotes/{patch_id}'.format(patch_id='patch_id_example'),
|
||||
method='DELETE',
|
||||
headers=headers)
|
||||
self.assert200(response,
|
||||
'Response body is : ' + response.data.decode('utf-8'))
|
||||
|
||||
def test_post_patchnotes(self):
|
||||
patch_note_mock = {
|
||||
"changes": "test changes",
|
||||
"date": "2025-01-02",
|
||||
"patchID": "29e80bcc-5981-4a52-99e1-373442dea9b9",
|
||||
"title": "test patch"
|
||||
}
|
||||
|
||||
self.client.open(
|
||||
'/patchnotes',
|
||||
method='POST',
|
||||
headers=headers,
|
||||
data=json.dumps(patch_note_mock),
|
||||
content_type='application/json'
|
||||
)
|
||||
|
||||
response = self.client.open(
|
||||
'/patchnotes/{patch_id}'.format(patch_id=patch_note_mock['patchID']),
|
||||
method='DELETE',
|
||||
headers=headers
|
||||
)
|
||||
|
||||
self.assert200(response, 'Response body is : ' + response.data.decode('utf-8'))
|
||||
|
||||
@unittest.mock.patch('openapi_server.controllers.patchnotes_controller.patchnotes_patch_iddelete')
|
||||
def test_patch_note_delete_not_found(self, balala):
|
||||
|
||||
"""Test case for patch_note_delete
|
||||
|
||||
"""
|
||||
headers = {
|
||||
}
|
||||
|
||||
patch_note_mock = {
|
||||
"changes": "test changes",
|
||||
"date": "2025-01-02",
|
||||
"patchID": "29e80bcc-5981-4a52-99e1-373442dea9b9",
|
||||
"title": "test patch"
|
||||
}
|
||||
|
||||
response = self.client.open(
|
||||
'/patchnotes/{patch_id}'.format(patch_id=''),
|
||||
method='DELETE',
|
||||
headers=headers
|
||||
)
|
||||
|
||||
self.assert404(response, 'Response body is : ' + response.data.decode('utf-8'))
|
||||
|
||||
@unittest.mock.patch('openapi_server.controllers.patchnotes_controller.patchnotes_post')
|
||||
def test_post_patchnotes(self, balala):
|
||||
"""Test case for post_patchnotes
|
||||
|
||||
|
||||
"""
|
||||
patch_notes = openapi_server.PatchNotes()
|
||||
headers = {
|
||||
|
||||
post_patchnotes_mock = {
|
||||
"changes": "test changes",
|
||||
"date": "2025-01-02",
|
||||
"patchID": "29e80bcc-5981-4a52-99e1-373442dea9b9",
|
||||
"title": "test patch"
|
||||
}
|
||||
headers = {
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
}
|
||||
|
||||
response = self.client.open(
|
||||
'/patchnotes',
|
||||
method='POST',
|
||||
headers=headers,
|
||||
data=json.dumps(patch_notes),
|
||||
content_type='application/json')
|
||||
self.assert200(response,
|
||||
'Response body is : ' + response.data.decode('utf-8'))
|
||||
data=json.dumps(post_patchnotes_mock),
|
||||
content_type='application/json'
|
||||
)
|
||||
|
||||
self.assert200(response, 'Response body is : ' + response.data.decode('utf-8'))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
python_dateutil >= 2.5.3
|
||||
connexion[swagger-ui, flask, uvicorn] >= 3.2.0
|
||||
werkzeug == 3.1.3
|
||||
swagger-ui-bundle >= 0.0.2
|
||||
python_dateutil >= 2.6.0
|
||||
setuptools >= 21.0.0
|
||||
urllib3 >= 1.25.3, < 2.1.0
|
||||
pydantic >= 2
|
||||
typing-extensions >= 4.7.1
|
||||
Flask >= 3.1.0
|
||||
Flask-PyMongo >= 3.0.1
|
||||
pymongo >= 4.11.3
|
||||
|
|
|
|||
44
gen/setup.py
44
gen/setup.py
|
|
@ -1,18 +1,8 @@
|
|||
# coding: utf-8
|
||||
import sys
|
||||
from setuptools import setup, find_packages
|
||||
|
||||
"""
|
||||
announcementService
|
||||
|
||||
Announcing patchnotes for KanzleiApp
|
||||
|
||||
The version of the OpenAPI document: 1.0.0
|
||||
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
||||
|
||||
Do not edit the class manually.
|
||||
""" # noqa: E501
|
||||
|
||||
|
||||
from setuptools import setup, find_packages # noqa: H301
|
||||
NAME = "openapi_server"
|
||||
VERSION = "1.0.0"
|
||||
|
||||
# To install the library, run the following
|
||||
#
|
||||
|
|
@ -20,30 +10,28 @@ from setuptools import setup, find_packages # noqa: H301
|
|||
#
|
||||
# prerequisite: setuptools
|
||||
# http://pypi.python.org/pypi/setuptools
|
||||
NAME = "openapi-client"
|
||||
VERSION = "1.0.0"
|
||||
PYTHON_REQUIRES = ">=3.7"
|
||||
|
||||
REQUIRES = [
|
||||
"urllib3 >= 1.25.3, < 2.1.0",
|
||||
"python-dateutil",
|
||||
"pydantic >= 2",
|
||||
"typing-extensions >= 4.7.1",
|
||||
"connexion>=2.0.2",
|
||||
"swagger-ui-bundle>=0.0.2",
|
||||
"python_dateutil>=2.6.0"
|
||||
]
|
||||
|
||||
setup(
|
||||
name=NAME,
|
||||
version=VERSION,
|
||||
description="announcementService",
|
||||
author="OpenAPI Generator community",
|
||||
author_email="team@openapitools.org",
|
||||
author_email="",
|
||||
url="",
|
||||
keywords=["OpenAPI", "OpenAPI-Generator", "announcementService"],
|
||||
keywords=["OpenAPI", "announcementService"],
|
||||
install_requires=REQUIRES,
|
||||
packages=find_packages(exclude=["test", "tests"]),
|
||||
packages=find_packages(),
|
||||
package_data={'': ['openapi/openapi.yaml']},
|
||||
include_package_data=True,
|
||||
long_description_content_type='text/markdown',
|
||||
entry_points={
|
||||
'console_scripts': ['openapi_server=openapi_server.__main__:main']},
|
||||
long_description="""\
|
||||
Announcing patchnotes for KanzleiApp
|
||||
""", # noqa: E501
|
||||
package_data={"openapi_client": ["py.typed"]},
|
||||
"""
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
pytest~=7.1.3
|
||||
pytest~=7.1.0
|
||||
pytest-cov>=2.8.1
|
||||
pytest-randomly>=3.12.0
|
||||
mypy>=1.4.1
|
||||
types-python-dateutil>=2.8.19
|
||||
pytest-randomly>=1.2.3
|
||||
Flask-Testing==0.8.1
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
[tox]
|
||||
envlist = py3
|
||||
skipsdist=True
|
||||
|
||||
[testenv]
|
||||
deps=-r{toxinidir}/requirements.txt
|
||||
-r{toxinidir}/test-requirements.txt
|
||||
{toxinidir}
|
||||
|
||||
commands=
|
||||
pytest --cov=openapi_client
|
||||
pytest --cov=openapi_server
|
||||
|
|
|
|||
|
|
@ -3,7 +3,10 @@ setuptools >= 21.0.0
|
|||
urllib3 >= 2.2.2, < 2.3.0
|
||||
pydantic >= 2
|
||||
typing-extensions >= 4.7.1
|
||||
Flask
|
||||
pymongo[srv]
|
||||
Flask-PyMongo
|
||||
connexion[swagger-ui] >= 2.6.6
|
||||
Flask >= 3.1.0
|
||||
Flask-PyMongo >= 3.0.1
|
||||
pymongo >= 4.11.3
|
||||
connexion[swagger-ui, flask] >= 3.2.0
|
||||
werkzeug == 3.1.3
|
||||
swagger-ui-bundle >= 0.0.2
|
||||
uvicorn >= 0.21.1
|
||||
Loading…
Reference in New Issue