From 2e3ceb247fa63db0bbf9ba71f06be50eeda74445 Mon Sep 17 00:00:00 2001 From: Michael McVady Date: Sun, 29 Oct 2023 16:45:51 -0500 Subject: Refactor: `post` -> `entry` --- README.md | 2 +- assets/entry.html | 12 +++ assets/entry_edit.html | 11 +++ assets/post.html | 12 --- assets/post_edit.html | 11 --- assets/static/css/default.css | 30 +++---- conf/clog.conf | 28 +++---- db/data.sql | 84 +++++++++---------- src/clog.c | 188 +++++++++++++++++++++--------------------- src/queries.h | 25 +++--- tests.py | 56 ++++++------- 11 files changed, 229 insertions(+), 230 deletions(-) create mode 100644 assets/entry.html create mode 100644 assets/entry_edit.html delete mode 100644 assets/post.html delete mode 100644 assets/post_edit.html diff --git a/README.md b/README.md index e207f02..d1a07a6 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ Use `psql` and load `db/db.sql` for models, ## TODO 1. ~Only do HTTP stuff at the edge.~ -2. ~`PUT`~/`PATCH`? posts. +2. ~`PUT`~/`PATCH`? entries. 3. pagination 4. HTML form for edits 5. Make

first class markdown citizen diff --git a/assets/entry.html b/assets/entry.html new file mode 100644 index 0000000..445d2ce --- /dev/null +++ b/assets/entry.html @@ -0,0 +1,12 @@ + +
+
+
+

%s

+%s +
+
+%s +
+
+
diff --git a/assets/entry_edit.html b/assets/entry_edit.html new file mode 100644 index 0000000..cd2f920 --- /dev/null +++ b/assets/entry_edit.html @@ -0,0 +1,11 @@ +
+
+

id

+
+

title

+
+

body

+
+
+
+
diff --git a/assets/post.html b/assets/post.html deleted file mode 100644 index bb94b36..0000000 --- a/assets/post.html +++ /dev/null @@ -1,12 +0,0 @@ - -
-
-
-

%s

-%s -
-
-%s -
-
-
diff --git a/assets/post_edit.html b/assets/post_edit.html deleted file mode 100644 index cd2f920..0000000 --- a/assets/post_edit.html +++ /dev/null @@ -1,11 +0,0 @@ -
-
-

id

-
-

title

-
-

body

-
-
-
-
diff --git a/assets/static/css/default.css b/assets/static/css/default.css index c6dcf9a..02cb982 100644 --- a/assets/static/css/default.css +++ b/assets/static/css/default.css @@ -9,7 +9,7 @@ body { margin-right: auto; } -.post { +.entry { position: center; color: rgb(0,0,0); margin-top: 1em; @@ -19,25 +19,25 @@ body { border-color: rgb(0,0,0); } -.post .head { +.entry .head { border-bottom-style: solid; border-width: 1px; padding: 1px; } -.post .head h2 { +.entry .head h2 { padding: 0.1em; } -.post .title { +.entry .title { font-weight: bold; } -.post .title a { +.entry .title a { text-decoration: none; } -.post .date { +.entry .date { font-weight: bold; color: rgb(230,230,255); background-color: rgb(0,0,0); @@ -46,37 +46,37 @@ body { padding-left: 0.5em } -.post .tag { +.entry .tag { /* display: none;*/ text-align: right; color: rgb(230,230,255); } -.post .tag span { +.entry .tag span { background-color: rgb(0,0,0); padding: 0.1em 0.2em; font-weight: bold; color: rgb(230,230,255); } -.post .tag a { +.entry .tag a { color: rgb(230,230,255); } -.post .body { +.entry .body { padding: 0.5em; } -.post .body p { +.entry .body p { margin: 1em; } -.post .body code { +.entry .body code { /* background-color: rgb(115,115,127);*/ /* color: rgb(230,230,255);*/ } -.post .body pre { +.entry .body pre { background-color: rgb(115,115,127); color: rgb(230,230,255); margin: 1em; @@ -84,11 +84,11 @@ body { overflow-x: auto; } -.post .body h3 { +.entry .body h3 { margin: 1em; } -.post .foot { +.entry .foot { border-top-style: solid; border-width: 1px; margin: 0em; diff --git a/conf/clog.conf b/conf/clog.conf index 9a5e340..3476b52 100644 --- a/conf/clog.conf +++ b/conf/clog.conf @@ -12,7 +12,7 @@ privsep worker { root /var/chroot/clog - skip chroot + # skip chroot } seccomp_tracing no @@ -27,43 +27,43 @@ domain * { filemap /static/ assets/static route / { - handler get_posts + handler get_entries methods get } - route /posts { - handler get_posts + route /entries { + handler get_entries methods get } - route /posts { - handler post_posts + route /entries { + handler post_entry methods post } - route ^/posts/[a-z0-9\-]+$ { - handler get_posts_resource + route ^/entries/[a-z0-9\-]+$ { + handler get_entry methods get } - route ^/posts/[a-z0-9\-]+$ { - handler put_posts + route ^/entries/[a-z0-9\-]+$ { + handler put_entry methods put } - route ^/posts/[a-z0-9\-]+$ { - handler delete_posts + route ^/entries/[a-z0-9\-]+$ { + handler delete_entry methods delete } # toy endpoint route ^/form { - handler get_form + handler get_entry_form methods get } route ^/form { - handler post_form + handler post_entry_form methods post validate post id v_uuid diff --git a/db/data.sql b/db/data.sql index b9b0b61..f1c426d 100644 --- a/db/data.sql +++ b/db/data.sql @@ -1,5 +1,5 @@ -INSERT INTO posts ( +INSERT INTO entries ( id, -- draft, title, @@ -649,47 +649,47 @@ And now to test that packaging works by packaging a project: ( 'b2fa3458-5457-4ade-8ce4-bd973bce7da5', 'SQLite Cheat Sheet', - 'Some notes on using SQLite - -Opening a database - - mcvady@b:/tmp$ sqlite3 sqlite.db - -Show tables - - sqlite> .tables - seq name file - --- --------------- ---------------------------------------------------------- - 0 main /tmp/sqlite.db - sqlite> .tables - acc globalblacklist purplemap - active_watchers grp re_grp - address htable rls_presentity - aliases imc_members rls_watchers - carrier_name imc_rooms sca_subscriptions - carrierfailureroute lcr_gw silo - carrierroute lcr_rule sip_trace - cpl lcr_rule_target speed_dial - -Describe a table - - sqlite> .schema TABLENAME - -Create a table - - sqlite> CREATE TABLE connection(connection_id BIGINT, username STRING); - -Insert into a table - - sqlite> INSERT INTO connection (connection_id, username) VALUES (1, ''mcvady''); - -Dump output into a file - - sqlite> .output SCHEMA_DUMP - sqlite> .schema - -Run SQL commands from file into a DB - + 'Some notes on using SQLite + +Opening a database + + mcvady@b:/tmp$ sqlite3 sqlite.db + +Show tables + + sqlite> .tables + seq name file + --- --------------- ---------------------------------------------------------- + 0 main /tmp/sqlite.db + sqlite> .tables + acc globalblacklist purplemap + active_watchers grp re_grp + address htable rls_presentity + aliases imc_members rls_watchers + carrier_name imc_rooms sca_subscriptions + carrierfailureroute lcr_gw silo + carrierroute lcr_rule sip_trace + cpl lcr_rule_target speed_dial + +Describe a table + + sqlite> .schema TABLENAME + +Create a table + + sqlite> CREATE TABLE connection(connection_id BIGINT, username STRING); + +Insert into a table + + sqlite> INSERT INTO connection (connection_id, username) VALUES (1, ''mcvady''); + +Dump output into a file + + sqlite> .output SCHEMA_DUMP + sqlite> .schema + +Run SQL commands from file into a DB + $ sqlite3 sqlite3.db < schema.sql', '2015-10-14 00:00:00', '2015-10-14 00:00:00' diff --git a/src/clog.c b/src/clog.c index 4bb5945..87129e5 100644 --- a/src/clog.c +++ b/src/clog.c @@ -27,7 +27,7 @@ enum content_type { CONTENT_JSON, CONTENT_X_WWW_FORM_URLENCODED }; enum query_status { QUERY_STATUS_OK, QUERY_STATUS_ERROR, QUERY_STATUS_NOT_FOUND }; -struct post_query { +struct entry_query { char *id; int status; @@ -44,8 +44,8 @@ static const char * const error_msg[] = { [HTTP_STATUS_INTERNAL_ERROR] = "There was an error processing the request.", // 500 }; -void post_query_init(struct post_query *pq, const char *id); -void post_query_cleanup(struct post_query *pq); +void entry_query_init(struct entry_query *eq, const char *id); +void entry_query_cleanup(struct entry_query *eq); int validate_uuid(const char *uuid); @@ -62,44 +62,44 @@ int http_err_resp( int redirect(struct http_request *req); -int get_posts(struct http_request *req); -int get_posts_resource(struct http_request *req); -int post_posts(struct http_request *req); -int put_posts(struct http_request *req); -int delete_posts(struct http_request *req); +int get_entries(struct http_request *req); +int get_entry(struct http_request *req); +int post_entry(struct http_request *req); +int put_entry(struct http_request *req); +int delete_entry(struct http_request *req); int v_example_func(struct http_request *req, char *data); -int get_form(struct http_request *req); -int post_form(struct http_request *req); +int get_entry_form(struct http_request *req); +int post_entry_form(struct http_request *req); -int sql_select_posts(struct post_query *pq); -int sql_update_posts(const char *id, const char *title, const char *body); -int sql_delete_posts(const char *id); -int sql_insert_posts(const char *id, const char *title, const char *body); -int sql_render_posts(struct kore_pgsql *sql, struct post_query *pq); +int sql_select_entries(struct entry_query *eq); +int sql_update_entry(const char *id, const char *title, const char *body); +int sql_delete_entry(const char *id); +int sql_insert_entry(const char *id, const char *title, const char *body); +int sql_render_entry(struct kore_pgsql *sql, struct entry_query *eq); static void process_md_output(const MD_CHAR *, MD_SIZE size, void *); static int render_md(const char *, struct kore_buf *); -void post_query_init(struct post_query *pq, const char *id) { +void entry_query_init(struct entry_query *eq, const char *id) { if (id != NULL) - pq->id = kore_strdup(id); + eq->id = kore_strdup(id); else - pq->id = NULL; + eq->id = NULL; - pq->status = QUERY_STATUS_OK; - pq->result = kore_buf_alloc(0); + eq->status = QUERY_STATUS_OK; + eq->result = kore_buf_alloc(0); } -void post_query_cleanup(struct post_query *pq) { - if (pq->id != NULL) - kore_free((void *) pq->id); - pq->id = NULL; +void entry_query_cleanup(struct entry_query *eq) { + if (eq->id != NULL) + kore_free((void *) eq->id); + eq->id = NULL; - if (pq->result != NULL) - kore_buf_free(pq->result); - pq->result = NULL; + if (eq->result != NULL) + kore_buf_free(eq->result); + eq->result = NULL; } int validate_uuid(const char *uuid) { @@ -193,13 +193,13 @@ int v_example_func(struct http_request *req, char *data) { return KORE_RESULT_OK; } -int get_form(struct http_request *req) { +int get_entry_form(struct http_request *req) { struct kore_buf *resp_buf = kore_buf_alloc(0); kore_buf_append( resp_buf, - (const char *) asset_post_edit_html, - asset_len_post_edit_html + (const char *) asset_entry_edit_html, + asset_len_entry_edit_html ); http_ok_resp(req, HTTP_STATUS_OK, resp_buf); @@ -210,7 +210,7 @@ int get_form(struct http_request *req) { } -int post_form(struct http_request *req) { +int post_entry_form(struct http_request *req) { struct kore_buf *html_buf = kore_buf_alloc(0); struct kore_buf *resp_buf = kore_buf_alloc(0); @@ -236,14 +236,14 @@ int post_form(struct http_request *req) { // Render MD. (void) render_md(body, html_buf); // if (err == KORE_RESULT_ERROR) { - // kore_log(LOG_ERR, "Error rendering markdown for post %s.", id); + // kore_log(LOG_ERR, "Error rendering markdown for entry %s.", id); // continue; // } - // Append rendered MD post. + // Append rendered MD entry. kore_buf_appendf( resp_buf, - (const char *) asset_post_html, + (const char *) asset_entry_html, id, title, "1981-12-23 06:02:00", @@ -259,54 +259,54 @@ int post_form(struct http_request *req) { } -int get_posts(struct http_request *req) { - struct post_query pq; +int get_entries(struct http_request *req) { + struct entry_query eq; - post_query_init(&pq, NULL); + entry_query_init(&eq, NULL); - (void) sql_select_posts(&pq); - if (pq.status != QUERY_STATUS_OK) + (void) sql_select_entries(&eq); + if (eq.status != QUERY_STATUS_OK) http_err_resp(req, HTTP_STATUS_INTERNAL_ERROR); else - http_ok_resp(req, HTTP_STATUS_OK, pq.result); + http_ok_resp(req, HTTP_STATUS_OK, eq.result); - post_query_cleanup(&pq); + entry_query_cleanup(&eq); return KORE_RESULT_OK; } -int get_posts_resource(struct http_request *req) { +int get_entry(struct http_request *req) { int err = 0; - struct post_query pq; + struct entry_query eq; - post_query_init(&pq, req->path + strlen("/posts/")); + entry_query_init(&eq, req->path + strlen("/entries/")); // Check for valid resource UUID - kore_log(LOG_DEBUG, "Resource id /posts/%s.", pq.id); - err = validate_uuid(pq.id); + kore_log(LOG_DEBUG, "Resource id /entries/%s.", eq.id); + err = validate_uuid(eq.id); if (err == KORE_RESULT_ERROR) { - kore_log(LOG_ERR, "Invalid post id %s.", pq.id); + kore_log(LOG_ERR, "Invalid entry id %s.", eq.id); http_err_resp(req, HTTP_STATUS_NOT_FOUND); goto out; } - (void) sql_select_posts(&pq); - if (pq.status == QUERY_STATUS_NOT_FOUND) + (void) sql_select_entries(&eq); + if (eq.status == QUERY_STATUS_NOT_FOUND) http_err_resp(req, HTTP_STATUS_NOT_FOUND); - else if (pq.status == QUERY_STATUS_ERROR) + else if (eq.status == QUERY_STATUS_ERROR) http_err_resp(req, HTTP_STATUS_INTERNAL_ERROR); else - http_ok_resp(req, HTTP_STATUS_OK, pq.result); + http_ok_resp(req, HTTP_STATUS_OK, eq.result); out: ; - post_query_cleanup(&pq); + entry_query_cleanup(&eq); return KORE_RESULT_OK; } -int post_posts(struct http_request *req) { +int post_entry(struct http_request *req) { int err = 0; int status = HTTP_STATUS_CREATED; @@ -334,7 +334,7 @@ int post_posts(struct http_request *req) { err = validate_uuid(id); if (err == KORE_RESULT_ERROR) { status = HTTP_STATUS_BAD_REQUEST; - kore_log(LOG_ERR, "Invalid post UUID %s.", id); + kore_log(LOG_ERR, "Invalid entry UUID %s.", id); goto out; } } @@ -359,7 +359,7 @@ int post_posts(struct http_request *req) { goto out; } - err = sql_insert_posts(id, title, body); + err = sql_insert_entry(id, title, body); if (err == KORE_RESULT_ERROR) { status = HTTP_STATUS_INTERNAL_ERROR; @@ -375,7 +375,7 @@ out: ; return KORE_RESULT_OK; } -int put_posts(struct http_request *req) { +int put_entry(struct http_request *req) { int err = 0; int status = HTTP_STATUS_OK; @@ -389,13 +389,13 @@ int put_posts(struct http_request *req) { kore_json_init(&json, req->http_body->data, req->http_body->length); - id = req->path + strlen("/posts/"); + id = req->path + strlen("/entries/"); // Check for valid resource UUID - kore_log(LOG_DEBUG, "Resource id /posts/%s.", id); + kore_log(LOG_DEBUG, "Resource id /entries/%s.", id); err = validate_uuid(id); if (err == KORE_RESULT_ERROR) { - kore_log(LOG_ERR, "Invalid post id %s.", id); + kore_log(LOG_ERR, "Invalid entry id %s.", id); http_err_resp(req, HTTP_STATUS_NOT_FOUND); goto out; } @@ -426,7 +426,7 @@ int put_posts(struct http_request *req) { goto out; } - err = sql_update_posts(id, title, body); + err = sql_update_entry(id, title, body); if (err == KORE_RESULT_ERROR) { status = HTTP_STATUS_INTERNAL_ERROR; @@ -442,54 +442,54 @@ out: ; return KORE_RESULT_OK; } -int sql_select_posts(struct post_query *pq) { +int sql_select_entries(struct entry_query *eq) { int err = KORE_RESULT_OK; struct kore_pgsql sql; kore_pgsql_init(&sql); - pq->status = QUERY_STATUS_OK; + eq->status = QUERY_STATUS_OK; // Set up synchronous database handle. err = kore_pgsql_setup(&sql, database, KORE_PGSQL_SYNC); if (err == KORE_RESULT_ERROR) { - pq->status = QUERY_STATUS_ERROR; + eq->status = QUERY_STATUS_ERROR; kore_pgsql_logerror(&sql); goto out; } - // Query for posts, check for error. - if (pq->id != NULL) { - // Query a post. + // Query for entries, check for error. + if (eq->id != NULL) { + // Query an entry. err = kore_pgsql_query_params( &sql, - q_select_post, + q_select_entry, 0, // return string data 1, // param count - KORE_PGSQL_PARAM_TEXT(pq->id) + KORE_PGSQL_PARAM_TEXT(eq->id) ); } else { - // Query all posts. + // Query all entries. err = kore_pgsql_query( &sql, - q_select_posts + q_select_entries ); } if (err == KORE_RESULT_ERROR) { - pq->status = QUERY_STATUS_ERROR; + eq->status = QUERY_STATUS_ERROR; kore_pgsql_logerror(&sql); goto out; } // TODO: Add test for this; When database is empty, don't return 404 for base request. - if (pq->id != NULL && kore_pgsql_ntuples(&sql) == 0) { - pq->status = QUERY_STATUS_NOT_FOUND; + if (eq->id != NULL && kore_pgsql_ntuples(&sql) == 0) { + eq->status = QUERY_STATUS_NOT_FOUND; goto out; } - (void) sql_render_posts(&sql, pq); + (void) sql_render_entry(&sql, eq); out: ; @@ -498,28 +498,28 @@ out: ; return err; } -int delete_posts(struct http_request *req) { +int delete_entry(struct http_request *req) { int err = 0; - const char *id = req->path + strlen("/posts/"); + const char *id = req->path + strlen("/entries/"); // Check for valid resource UUID - kore_log(LOG_DEBUG, "Resource id /posts/%s.", id); + kore_log(LOG_DEBUG, "Resource id /entries/%s.", id); err = validate_uuid(id); if (err == KORE_RESULT_ERROR) { - kore_log(LOG_ERR, "Invalid post id %s.", id); + kore_log(LOG_ERR, "Invalid entry id %s.", id); http_err_resp(req, HTTP_STATUS_NOT_FOUND); goto out; } - err = sql_delete_posts(id); + err = sql_delete_entry(id); // FIXME: should 404 if id doesn't exist. - // if (pq.status == QUERY_STATUS_NOT_FOUND) + // if (eq.status == QUERY_STATUS_NOT_FOUND) // http_err_resp(req, HTTP_STATUS_NOT_FOUND); if (err == KORE_RESULT_ERROR) http_err_resp(req, HTTP_STATUS_INTERNAL_ERROR); else - // TODO: test this, it should explode. + // TODO: test this; the test should explode. http_err_resp(req, HTTP_STATUS_OK); out: ; @@ -527,7 +527,7 @@ out: ; return KORE_RESULT_OK; } -int sql_render_posts(struct kore_pgsql *sql, struct post_query *pq) { +int sql_render_entry(struct kore_pgsql *sql, struct entry_query *eq) { int err = KORE_RESULT_OK; int row = 0, rows = 0; @@ -542,7 +542,7 @@ int sql_render_posts(struct kore_pgsql *sql, struct post_query *pq) { // Allocate a buffer to render the markdown as HTML into. html_buf = kore_buf_alloc(0); - // Iterate over posts and render them. + // Iterate over entries and render them. rows = kore_pgsql_ntuples(sql); for (row = 0; row < rows; row++) { // Reset buffer. @@ -558,14 +558,14 @@ int sql_render_posts(struct kore_pgsql *sql, struct post_query *pq) { // Render MD. err = render_md(body, html_buf); if (err == KORE_RESULT_ERROR) { - kore_log(LOG_ERR, "Error rendering markdown for post %s.", id); + kore_log(LOG_ERR, "Error rendering markdown for entry %s.", id); continue; } - // Append rendered MD post. + // Append rendered MD entry. kore_buf_appendf( - pq->result, - (const char *) asset_post_html, + eq->result, + (const char *) asset_entry_html, id, title, created_at, @@ -579,7 +579,7 @@ int sql_render_posts(struct kore_pgsql *sql, struct post_query *pq) { return KORE_RESULT_OK; } -int sql_insert_posts(const char *id, const char *title, const char *body) { +int sql_insert_entry(const char *id, const char *title, const char *body) { int err = KORE_RESULT_OK; struct kore_pgsql sql; @@ -594,7 +594,7 @@ int sql_insert_posts(const char *id, const char *title, const char *body) { if (id == NULL) { err = kore_pgsql_query_params( &sql, - q_insert_posts, + q_insert_entry, 0, 2, KORE_PGSQL_PARAM_TEXT(title), @@ -603,7 +603,7 @@ int sql_insert_posts(const char *id, const char *title, const char *body) { } else { err = kore_pgsql_query_params( &sql, - q_insert_posts_with_id, + q_insert_entry_with_id, 0, 3, KORE_PGSQL_PARAM_TEXT(id), @@ -623,7 +623,7 @@ out: ; return err; } -int sql_update_posts(const char *id, const char *title, const char *body) { +int sql_update_entry(const char *id, const char *title, const char *body) { int err = KORE_RESULT_OK; struct kore_pgsql sql; @@ -637,7 +637,7 @@ int sql_update_posts(const char *id, const char *title, const char *body) { err = kore_pgsql_query_params( &sql, - q_update_posts, + q_update_entry, 0, 3, KORE_PGSQL_PARAM_TEXT(title), @@ -656,7 +656,7 @@ out: ; return err; } -int sql_delete_posts(const char *id) { +int sql_delete_entry(const char *id) { int err = KORE_RESULT_OK; struct kore_pgsql sql; @@ -670,7 +670,7 @@ int sql_delete_posts(const char *id) { err = kore_pgsql_query_params( &sql, - q_delete_posts, + q_delete_entry, 0, 1, KORE_PGSQL_PARAM_TEXT(id) diff --git a/src/queries.h b/src/queries.h index ffc9c7b..986f180 100644 --- a/src/queries.h +++ b/src/queries.h @@ -1,36 +1,35 @@ -const char *q_select_post = +const char *q_select_entry = "SELECT id, title, created_at::DATE, body " -"FROM posts " +"FROM entries " "WHERE id = $1;"; -const char *q_select_posts = +const char *q_select_entries = "SELECT id, title, created_at::DATE, body " -"FROM posts " +"FROM entries " "ORDER BY updated_at DESC;"; - -const char *q_insert_posts = -"INSERT INTO posts " +const char *q_insert_entry = +"INSERT INTO entries " "(title, body) " "VALUES " "($1, $2) " "RETURNING id;"; -const char *q_insert_posts_with_id = -"INSERT INTO posts " +const char *q_insert_entry_with_id = +"INSERT INTO entries " "(id, title, body) " "VALUES " "($1, $2, $3) " "RETURNING id;"; -const char *q_update_posts = -"UPDATE posts " +const char *q_update_entry = +"UPDATE entries " "SET title = $1, body = $2, updated_at = NOW() " "WHERE id = $3 " "RETURNING id;"; -const char *q_delete_posts = +const char *q_delete_entry = "DELETE " -"FROM posts " +"FROM entries " "WHERE id = $1 " "RETURNING id;"; diff --git a/tests.py b/tests.py index 675aab6..032406e 100755 --- a/tests.py +++ b/tests.py @@ -6,9 +6,9 @@ import uuid import requests BASE_URL = "http://localhost:8888" -POSTS_URL = f"{BASE_URL}/posts" +ENTRIES_URL = f"{BASE_URL}/entries" -FONT_RENDERING_POST_UUID = "6d011855-6b0d-4202-a243-4d9db9807f14" +FONT_RENDERING_ENTRY_UUID = "6d011855-6b0d-4202-a243-4d9db9807f14" BAD_UUID = "00000000-0000-1111-0000-000000000000" INVALID_UUID = "0" @@ -25,8 +25,8 @@ def test_redirect(): assert r.headers["Location"] == "/" -def test_get_post(): - r = requests.get(f"{POSTS_URL}/{FONT_RENDERING_POST_UUID}") +def test_get_entry(): + r = requests.get(f"{ENTRIES_URL}/{FONT_RENDERING_ENTRY_UUID}") assert r.status_code == 200 assert "A Solid Breakdown of the Linux Font Rendering Stack" in r.text assert "hinting and anti-aliasing" in r.text @@ -43,8 +43,8 @@ def test_get_base_url(): assert "Debugging CGI / CGit" in r.text -def test_get_posts(): - r = requests.get(POSTS_URL) +def test_get_entries(): + r = requests.get(ENTRIES_URL) assert r.status_code == 200 assert "A Solid Breakdown of the Linux Font Rendering Stack" in r.text assert "hinting and anti-aliasing" in r.text @@ -52,94 +52,94 @@ def test_get_posts(): assert "Debugging CGI / CGit" in r.text -def test_get_post_not_found(): - r = requests.get(f"{POSTS_URL}/{BAD_UUID}") +def test_get_entry_not_found(): + r = requests.get(f"{ENTRIES_URL}/{BAD_UUID}") assert r.status_code == 404 assert "Resource not found" in r.text - r = requests.get(f"{POSTS_URL}/{INVALID_UUID}") + r = requests.get(f"{ENTRIES_URL}/{INVALID_UUID}") assert r.status_code == 404 assert "Resource not found" in r.text -def test_post_posts(): +def test_post_entry(): uuid_ = str(uuid.uuid4()) title = "Moby Dick" body = "Call me Ismael" data = {"id": uuid_, "title": title, "body": body} - r = requests.post(POSTS_URL, headers=JSON_ACCEPT_HEADER, json=data) + r = requests.post(ENTRIES_URL, headers=JSON_ACCEPT_HEADER, json=data) assert r.status_code == 201 assert "Resource created successfully." in r.text - posts_uuid_url = f"{POSTS_URL}/{uuid_}" - r = requests.get(posts_uuid_url) + entry_url = f"{ENTRIES_URL}/{uuid_}" + r = requests.get(entry_url) assert r.status_code == 200 assert title in r.text assert body in r.text - r = requests.delete(posts_uuid_url) + r = requests.delete(entry_url) assert r.status_code == 200 -def test_put_posts(): +def test_put_entry(): uuid_ = str(uuid.uuid4()) r = requests.post( - POSTS_URL, + ENTRIES_URL, headers=JSON_ACCEPT_HEADER, json={"id": uuid_, "title": "title", "body": "body"}, ) assert r.status_code == 201 assert "Resource created successfully." in r.text - post_uuid_url = f"{POSTS_URL}/{uuid_}" - r = requests.get(post_uuid_url) + entry_url = f"{ENTRIES_URL}/{uuid_}" + r = requests.get(entry_url) assert r.status_code == 200 assert "title" in r.text assert "body" in r.text r = requests.put( - post_uuid_url, + entry_url, headers=JSON_ACCEPT_HEADER, json={"title": "title2", "body": "body2"}, ) assert r.status_code == 200 assert "OK" in r.text - r = requests.get(post_uuid_url) + r = requests.get(entry_url) assert r.status_code == 200 # assert len(j) == 1 assert "title2" in r.text assert "body2" in r.text - r = requests.delete(post_uuid_url) + r = requests.delete(entry_url) assert r.status_code == 200 assert "OK" in r.text -def test_delete_posts(): +def test_delete_entry(): uuid_ = str(uuid.uuid4()) - post_uuid_url = f"{POSTS_URL}/{uuid_}" + entry_url = f"{ENTRIES_URL}/{uuid_}" - # Delete POST if exists - r = requests.delete(post_uuid_url) + # Delete entry if exists + r = requests.delete(entry_url) assert r.status_code in (200, 404) # FIXME: Still JSON title = "Hackers" body = "Hack the planet!" r = requests.post( - POSTS_URL, + ENTRIES_URL, headers=JSON_ACCEPT_HEADER, json={"id": uuid_, "title": title, "body": body}, ) assert r.status_code == 201, f"Unexpected status code: {r.status_code} == 201" assert "Resource created successfully" in r.text - r = requests.delete(post_uuid_url) + r = requests.delete(entry_url) assert r.status_code == 200 assert "OK" in r.text - r = requests.get(post_uuid_url) + r = requests.get(entry_url) assert r.status_code == 404 assert "Resource not found" in r.text -- cgit v1.2.3