Skip to content

Commit

Permalink
Merge pull request #200 from wu-wenxiang/master
Browse files Browse the repository at this point in the history
feat: add API for endpoint & metadata
  • Loading branch information
qiaolei1 authored Apr 12, 2023
2 parents a97260d + 3375800 commit a8ad67d
Show file tree
Hide file tree
Showing 14 changed files with 1,925 additions and 63 deletions.
118 changes: 63 additions & 55 deletions apitest/endpoint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,64 +64,72 @@ tests:
$.vendor: "vendor_A"
$.description: "service_A_description"

# - name: create_endpoint
# url: /api/v1/endpoints
# method: POST
# request_headers:
# Authorization: Bearer $HISTORY['user_login'].$RESPONSE['$.access_token']
# data:
# name: "name_A"
# service_id: $HISTORY['create_service'].$RESPONSE['$.id']
# version: "version_A"
# url: "url_A"
# metadatas:
# - key: "key_A"
# value: "value_A"
# - key: "key_B"
# value: "value_B"
# status: 201
# response_json_paths:
# $.name: "name_A"
# $.service_id: $HISTORY['create_service'].$RESPONSE['$.id']
# $.version: "version_A"
# $.url: "url_A"
- name: create_endpoint
url: /api/v1/endpoints
method: POST
request_headers:
Authorization: Bearer $HISTORY['user_login'].$RESPONSE['$.access_token']
data:
service_id: $HISTORY['create_service'].$RESPONSE['$.id']
enabled: true
url: "url_A"
status: 201
response_json_paths:
$.service_id: $HISTORY['create_service'].$RESPONSE['$.id']
$.enabled: true
$.url: "url_A"

- name: endpoint_get
url: /api/v1/endpoints/$HISTORY['create_endpoint'].$RESPONSE['$.id']
method: GET
request_headers:
Authorization: Bearer $HISTORY['user_login'].$RESPONSE['$.access_token']
status: 200
response_json_paths:
$.service_id: $HISTORY['create_service'].$RESPONSE['$.id']
$.enabled: true
$.url: "url_A"

- name: endpoint_list
url: /api/v1/endpoints
method: GET
request_headers:
Authorization: Bearer $HISTORY['user_login'].$RESPONSE['$.access_token']
status: 200
response_json_paths:
$.total: 1
$.data[0].service_id: $HISTORY['create_service'].$RESPONSE['$.id']
$.data[0].enabled: true
$.data[0].url: "url_A"

# - name: endpoint_get
# url: /api/v1/endpoints/$HISTORY['create_endpoint'].$RESPONSE['$.id']
# method: GET
# request_headers:
# Authorization: Bearer $HISTORY['user_login'].$RESPONSE['$.access_token']
# status: 200
# response_json_paths:
# $.name: "name_A"
# $.service_id: $HISTORY['create_service'].$RESPONSE['$.id']
# $.version: "version_A"
# $.url: "url_A"
# $.metadatas.len: 2
# $.metadatas[0].key: "key_A"
# $.metadatas[0].value: "value_A"
# $.metadatas[1].key: "key_B"
# $.metadatas[1].value: "value_B"
- name: endpoint_update
url: /api/v1/endpoints/$HISTORY['create_endpoint'].$RESPONSE['$.id']
method: PUT
request_headers:
Authorization: Bearer $HISTORY['user_login'].$RESPONSE['$.access_token']
data:
service_id: $HISTORY['create_service'].$RESPONSE['$.id']
enabled: false
url: "url_B"
status: 200

# - name: endpoint_list
# url: /api/v1/endpoints
# method: GET
# request_headers:
# Authorization: Bearer $HISTORY['user_login'].$RESPONSE['$.access_token']
# status: 200
# response_json_paths:
# $.total: 1
# $.data[0].name: "name_A"
# $.data[0].service_id: $HISTORY['create_service'].$RESPONSE['$.id']
# $.data[0].version: "version_A"
# $.data[0].url: "url_A"
- name: endpoint_get
url: /api/v1/endpoints/$HISTORY['create_endpoint'].$RESPONSE['$.id']
method: GET
request_headers:
Authorization: Bearer $HISTORY['user_login'].$RESPONSE['$.access_token']
status: 200
response_json_paths:
$.service_id: $HISTORY['create_service'].$RESPONSE['$.id']
$.enabled: false
$.url: "url_B"

# - name: delete_endpoint
# url: /api/v1/endpoints/$HISTORY['create_endpoint'].$RESPONSE['$.id']
# method: DELETE
# request_headers:
# Authorization: Bearer $HISTORY['user_login'].$RESPONSE['$.access_token']
# status: 204
- name: delete_endpoint
url: /api/v1/endpoints/$HISTORY['create_endpoint'].$RESPONSE['$.id']
method: DELETE
request_headers:
Authorization: Bearer $HISTORY['user_login'].$RESPONSE['$.access_token']
status: 204

- name: delete_service
url: /api/v1/services/$HISTORY['create_service'].$RESPONSE['$.id']
Expand Down
175 changes: 175 additions & 0 deletions apitest/endpoint_metadata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
fixtures:
- ConfigFixture
- SampleDataFixture

defaults:
ssl: False
request_headers:
content-type: application/json
accept: application/json

vars:
- &username 'gabbi_user'
- &password 'dandelion'

tests:
- name: create_user
url: /api/v1/users
method: POST
data:
username: *username
password: *password
is_active: true
status: 200
response_json_paths:
$.username: *username

- name: user_login
url: /api/v1/login
method: POST
data:
username: *username
password: *password
status: 200
response_json_paths:
$.token_type: bearer

- name: create_service_type
url: /api/v1/service_types
method: POST
request_headers:
Authorization: Bearer $HISTORY['user_login'].$RESPONSE['$.access_token']
data:
name: "service_type_A"
description: "service_type_A_description"
status: 201
response_json_paths:
$.name: "service_type_A"
$.description: "service_type_A_description"

- name: create_service
url: /api/v1/services
method: POST
request_headers:
Authorization: Bearer $HISTORY['user_login'].$RESPONSE['$.access_token']
data:
name: "service_A"
type_id: $HISTORY['create_service_type'].$RESPONSE['$.id']
vendor: "vendor_A"
description: "service_A_description"
status: 201
response_json_paths:
$.name: "service_A"
$.type_id: $HISTORY['create_service_type'].$RESPONSE['$.id']
$.vendor: "vendor_A"
$.description: "service_A_description"

- name: create_endpoint
url: /api/v1/endpoints
method: POST
request_headers:
Authorization: Bearer $HISTORY['user_login'].$RESPONSE['$.access_token']
data:
service_id: $HISTORY['create_service'].$RESPONSE['$.id']
enabled: true
url: "url_A"
status: 201
response_json_paths:
$.service_id: $HISTORY['create_service'].$RESPONSE['$.id']
$.enabled: true
$.url: "url_A"

- name: create_endpoint_metadata
url: /api/v1/endpoint_metadatas
method: POST
request_headers:
Authorization: Bearer $HISTORY['user_login'].$RESPONSE['$.access_token']
data:
endpoint_id: $HISTORY['create_endpoint'].$RESPONSE['$.id']
key: "key_A"
value: "value_A"
status: 201
response_json_paths:
$.endpoint_id: $HISTORY['create_endpoint'].$RESPONSE['$.id']
$.key: "key_A"
$.value: "value_A"

- name: endpoint_metadata_get
url: /api/v1/endpoint_metadatas/$HISTORY['create_endpoint_metadata'].$RESPONSE['$.id']
method: GET
request_headers:
Authorization: Bearer $HISTORY['user_login'].$RESPONSE['$.access_token']
status: 200
response_json_paths:
$.endpoint_id: $HISTORY['create_endpoint'].$RESPONSE['$.id']
$.key: "key_A"
$.value: "value_A"

- name: endpoint_metadata_list
url: /api/v1/endpoint_metadatas
method: GET
request_headers:
Authorization: Bearer $HISTORY['user_login'].$RESPONSE['$.access_token']
status: 200
response_json_paths:
$.total: 1
$.data[0].endpoint_id: $HISTORY['create_endpoint'].$RESPONSE['$.id']
$.data[0].key: "key_A"
$.data[0].value: "value_A"

- name: endpoint_metadata_update
url: /api/v1/endpoint_metadatas/$HISTORY['create_endpoint_metadata'].$RESPONSE['$.id']
method: PUT
request_headers:
Authorization: Bearer $HISTORY['user_login'].$RESPONSE['$.access_token']
data:
endpoint_id: $HISTORY['create_endpoint'].$RESPONSE['$.id']
key: "key_B"
value: "value_B"
status: 200

- name: endpoint_get
url: /api/v1/endpoint_metadatas/$HISTORY['create_endpoint_metadata'].$RESPONSE['$.id']
method: GET
request_headers:
Authorization: Bearer $HISTORY['user_login'].$RESPONSE['$.access_token']
status: 200
response_json_paths:
$.endpoint_id: $HISTORY['create_endpoint'].$RESPONSE['$.id']
$.key: "key_B"
$.value: "value_B"

- name: delete_endpoint_metadata
url: /api/v1/endpoint_metadatas/$HISTORY['create_endpoint_metadata'].$RESPONSE['$.id']
method: DELETE
request_headers:
Authorization: Bearer $HISTORY['user_login'].$RESPONSE['$.access_token']
status: 204

- name: delete_endpoint
url: /api/v1/endpoints/$HISTORY['create_endpoint'].$RESPONSE['$.id']
method: DELETE
request_headers:
Authorization: Bearer $HISTORY['user_login'].$RESPONSE['$.access_token']
status: 204

- name: delete_service
url: /api/v1/services/$HISTORY['create_service'].$RESPONSE['$.id']
method: DELETE
request_headers:
Authorization: Bearer $HISTORY['user_login'].$RESPONSE['$.access_token']
status: 204

- name: delete_service_type
url: /api/v1/service_types/$HISTORY['create_service_type'].$RESPONSE['$.id']
method: DELETE
request_headers:
Authorization: Bearer $HISTORY['user_login'].$RESPONSE['$.access_token']
status: 204

- name: delete_user
url: /api/v1/users/$HISTORY['create_user'].$RESPONSE['$.id']
method: DELETE
request_headers:
Authorization: Bearer $HISTORY['user_login'].$RESPONSE['$.access_token']
status: 204
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""add enabled field in endpoint
Revision ID: 556f61d01468
Revises: 94cf9906bb71
Create Date: 2023-04-12 14:10:58.954762
"""
import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import mysql

# revision identifiers, used by Alembic.
revision = "556f61d01468"
down_revision = "94cf9906bb71"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column("endpoint", sa.Column("enabled", sa.Boolean(), nullable=False))
op.drop_index("name", table_name="endpoint")
op.drop_column("endpoint", "version")
op.drop_column("endpoint", "name")
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column("endpoint", sa.Column("name", mysql.VARCHAR(length=64), nullable=False))
op.add_column("endpoint", sa.Column("version", mysql.VARCHAR(length=64), nullable=True))
op.create_index("name", "endpoint", ["name"], unique=False)
op.drop_column("endpoint", "enabled")
# ### end Alembic commands ###
6 changes: 6 additions & 0 deletions dandelion/api/api_v1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
countries,
edge_nodes,
edge_site,
endpoint_metadatas,
endpoints,
lidars,
login,
map_rsus,
Expand Down Expand Up @@ -111,5 +113,9 @@

api_router.include_router(algos.router, prefix="/algos", tags=["Algo"])

api_router.include_router(endpoints.router, prefix="/endpoints", tags=["Service"])
api_router.include_router(
endpoint_metadatas.router, prefix="/endpoint_metadatas", tags=["Service"]
)
api_router.include_router(services.router, prefix="/services", tags=["Service"])
api_router.include_router(service_types.router, prefix="/service_types", tags=["Service"])
Loading

0 comments on commit a8ad67d

Please sign in to comment.