Compare commits
7 Commits
8e52e543f9
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 93ff836e08 | |||
| cd47d4aa84 | |||
| 2785d3d6b6 | |||
| f4732836ad | |||
| b0bd579357 | |||
| fd341bd9df | |||
| 4608125fdf |
27
.drone.yml
27
.drone.yml
@@ -5,18 +5,21 @@ name: build
|
||||
steps:
|
||||
- name: build
|
||||
commands:
|
||||
- docker-compose -p pycms build
|
||||
|
||||
- name: test
|
||||
commands:
|
||||
- docker-compose -p pycms up --build --abort-on-container-exit
|
||||
|
||||
- name: push
|
||||
commands:
|
||||
- docker-compose -p pycms build
|
||||
- docker-compose -p pycms push
|
||||
- name: run
|
||||
commands:
|
||||
- docker-compose -p pycms down
|
||||
- docker-compose -p pycms up -d
|
||||
|
||||
---
|
||||
name: test
|
||||
type: docker
|
||||
kind: pipeline
|
||||
steps:
|
||||
- name: run db
|
||||
image: mongo
|
||||
detach: true
|
||||
|
||||
- name: run_tests
|
||||
image: pycms_server
|
||||
commands:
|
||||
- bash ./test.sh
|
||||
depends_on:
|
||||
- build
|
||||
31
main.py
31
main.py
@@ -16,6 +16,10 @@ class Config:
|
||||
- host
|
||||
- port
|
||||
- dbname
|
||||
App:
|
||||
- host
|
||||
- port
|
||||
- debug
|
||||
"""
|
||||
def __init__(self):
|
||||
"""
|
||||
@@ -28,9 +32,8 @@ class Config:
|
||||
print('DB not found, creating')
|
||||
database = mongoclient[self.dbname]
|
||||
|
||||
# TODO: Create table if not exists
|
||||
if 'posts' not in database.list_collection_names():
|
||||
print('Table not fount, creating')
|
||||
print('Table not found, creating')
|
||||
posts = database['posts']
|
||||
self.posts = posts
|
||||
|
||||
@@ -98,20 +101,28 @@ class Back():
|
||||
return str(dict_posts)
|
||||
|
||||
def updatePost(self, name, body):
|
||||
# TODO: return RESTful error/success result
|
||||
# If post exists, update it
|
||||
if posts.find_one({'name': name}):
|
||||
newPost = {'$set': {'text': body}}
|
||||
return str(posts.update_one({'name': name}, newPost))
|
||||
newPostJson = {'$set': {'text': body}}
|
||||
newPost = posts.update_one({'name': name}, newPostJson)
|
||||
result = dict(
|
||||
status=200, state='updated', count=newPost.matched_count
|
||||
)
|
||||
# Else - create new
|
||||
else:
|
||||
newPost = {'name': name, 'text': body,
|
||||
'create_timestamp': str(time.time())}
|
||||
return str(posts.insert_one(newPost).inserted_id)
|
||||
newPostJson = {'name': name, 'text': body,
|
||||
'create_timestamp': str(time.time())}
|
||||
newPost = posts.insert_one(newPostJson).inserted_id
|
||||
result = dict(status=200, state='new')
|
||||
return str(result)
|
||||
|
||||
def deletePost(self, name):
|
||||
# TODO: return RESTful error/success result
|
||||
return bool(posts.delete_one({'name': name}).deleted_count)
|
||||
delete = posts.delete_one({'name': name}).deleted_count
|
||||
if not delete:
|
||||
result = dict(status=500, count=delete)
|
||||
else:
|
||||
result = dict(status=200, count=delete)
|
||||
return str(result)
|
||||
|
||||
|
||||
class Metrics:
|
||||
|
||||
3
test.sh
3
test.sh
@@ -1,5 +1,6 @@
|
||||
#!/bin/bash
|
||||
curl_cmd='curl -s -w "%{http_code}" -o /dev/null'
|
||||
curl_cmd='curl -s -w :%{http_code}'
|
||||
#curl_cmd='curl -s -w "%{http_code}\t%{stdout}" -o /dev/null'
|
||||
url='server:8080'
|
||||
$curl_cmd -X POST $url/admin/post/test -F 'body=testpage' && echo ": Create success" || echo ': create fail'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user