This repository has been archived by the owner on Oct 21, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
test-metaweblog.el
137 lines (113 loc) · 5.98 KB
/
test-metaweblog.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
;;; test-metaweblog.el --- tests for metaweblog.el
;; Copyright (C) 2012 Puneeth Chaganti
(require 'metaweblog)
;;;;; Test env-setup ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq blog-xmlrpc "http://localhost/xmlrpc.php"
blog-user "admin"
blog-pass "test123"
blog-id "1")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Util functions
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun random-string (length)
"Return a random string of given length"
(let ((alpha "abcdefghijklmnopqrstuvwxyz")
(char-list))
(dotimes (char length)
(setq char-list (cons (string (elt "abcdefghijklmnopqrstuvwxyz" (random 25))) char-list)))
(mapconcat 'identity char-list "")))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Tests
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(ert-deftest test-new-category ()
"Test if creating a new category works."
(let* ((category (random-string 8))
;; Add new category
(category-id (wp-new-category blog-xmlrpc blog-user blog-pass blog-id category)))
;; List all categories and check if our category is present that list
(setq categories (metaweblog-get-categories blog-xmlrpc blog-user blog-pass blog-id))
(dolist (cat categories)
(if (equal (cdr (assoc "categoryId" cat)) category-id)
(should (equal (cdr (assoc "categoryName" cat)) category))))))
(ert-deftest test-new-tag ()
"Test if getting tags works. This test does nothing, just
checks if Wordpress version has the API.
FIXME: Make this a real test ..."
(let* ()
(setq tag-list (wp-get-tags blog-xmlrpc blog-user blog-pass blog-id))))
(ert-deftest test-pages ()
"Test if creating, listing, fetching content and deleting pages works."
(let* ((content '(("date" . "20120817T18:30:00+0000")
("title" . "Hello World")
("tags" "org2blog" "emacs")
("categories" "org2blog" "emacs")
("post-id")
("parent" . "0")
("excerpt" . "")
("permalink" . "")
("description" . "<p>Test content.</p>")))
;; Post a new page
(page-id (wp-new-page blog-xmlrpc blog-user blog-pass blog-id content nil))
(fetched-page (metaweblog-get-post blog-xmlrpc blog-user blog-pass page-id))
(new-content "<p>New Content</p>"))
;; Check if fetched-page's content and posted content match
(should (equal (cdr (assoc "description" fetched-page)) (cdr (assoc "description" content))))
;; Change content and post again...
(setcdr (assoc "description" content) new-content)
(wp-edit-page blog-xmlrpc blog-user blog-pass blog-id page-id content nil)
;; Fetch page again and check if content changed
(setq fetched-page (metaweblog-get-post blog-xmlrpc blog-user blog-pass page-id))
(should (equal (cdr (assoc "description" fetched-page)) (cdr (assoc "description" content))))
;; List pages
;; Check if our page is listed in minimal listing
(dolist (page (wp-get-pagelist blog-xmlrpc blog-user blog-pass blog-id))
(if (equal (cdr (assoc "post_id" page)) page-id)
(should (equal (cdr (assoc "page_title" page)) (cdr (assoc "title" content))))))
;; Check if our page is listed in full listing
(dolist (page (wp-get-pages blog-xmlrpc blog-user blog-pass blog-id))
(if (equal (cdr (assoc "post_id" page)) page-id)
(should (equal (cdr (assoc "page_title" page)) (cdr (assoc "title" content))))))
;; Delete page
(wp-delete-page blog-xmlrpc blog-id blog-user blog-pass page-id)))
(ert-deftest test-posts ()
"Test if creating, listing, fetching content and deleting posts works."
(let* ((content '(("date" . "20120817T18:30:00+0000")
("title" . "Hello World")
("tags" "org2blog" "emacs")
("categories" "org2blog" "emacs")
("post-id")
("parent" . "0")
("excerpt" . "")
("permalink" . "")
("description" . "<p>Test content.</p>")))
;; Make a new post
(post-id (metaweblog-new-post blog-xmlrpc blog-user blog-pass blog-id content nil))
(fetched-post (metaweblog-get-post blog-xmlrpc blog-user blog-pass post-id))
(new-content "<p>New Content</p>"))
;; Check if fetched-post's content and posted content match
(should (equal (cdr (assoc "description" fetched-post)) (cdr (assoc "description" content))))
;; Change content and post again...
(setcdr (assoc "description" content) new-content)
(metaweblog-edit-post blog-xmlrpc blog-user blog-pass post-id content nil)
;; Fetch post again and check if content changed
(setq fetched-post (metaweblog-get-post blog-xmlrpc blog-user blog-pass post-id))
(should (equal (cdr (assoc "description" fetched-post)) (cdr (assoc "description" content))))
;; List recent posts and check if our post is listed
(dolist (post (metaweblog-get-recent-posts blog-xmlrpc blog-id blog-user blog-pass 1000))
(when (equal (cdr (assoc "postid" post)) post-id)
(should (equal (cdr (assoc "title" post)) (cdr (assoc "title" content))))
(should (equal (cdr (assoc "description" post)) (cdr (assoc "description" content))))))
;; Delete post
(metaweblog-delete-post blog-xmlrpc blog-user blog-pass post-id)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; FIXME: Write tests for these functions ...
;; (defun get-file-properties (file)
;; "Gets the properties of a file. Returns an assoc list with
;; name - file name
;; bits - data of the file as a base64 encoded string
;; type - mimetype of file deduced from extension.")
;; (defun metaweblog-upload-file (blog-xmlrpc user-name password blog-id file)
;; "Uploads file to the blog. FILE will be an alist name, type,
;; bits, as keys mapped to name of the file, mime type and the
;; data.")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;