summaryrefslogtreecommitdiff
path: root/tests/operations.scm
blob: 3cd8d1a060cbe526de114f46f89a4c39e4e43783 (about) (plain)
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
;;; Guile-Debbugs --- Guile bindings for Debbugs
;;; Copyright © 2017 Ricardo Wurmus <rekado@elephly.net>
;;;
;;; This file is part of Guile-Debbugs.
;;;
;;; Guile-Debbugs is free software; you can redistribute it and/or
;;; modify it under the terms of the GNU General Public License as
;;; published by the Free Software Foundation; either version 3 of the
;;; License, or (at your option) any later version.
;;;
;;; Guile-Debbugs is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
;;; General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with Guile-Debbugs.  If not, see <http://www.gnu.org/licenses/>.

(define-module (test-operations)
  #:use-module (debbugs operations)
  #:use-module (debbugs soap)
  #:use-module (debbugs bug)
  #:use-module (srfi srfi-1)
  #:use-module (srfi srfi-64)
  #:use-module (ice-9 rdelim)
  #:use-module (sxml simple))

(test-begin "operations")

(define (asset name)
  (with-input-from-file (string-append (getenv "abs_top_srcdir")
                                       "/tests/" name)
    read-string))


(test-assert "newest-bugs generates soap request"
  (soap-request? (newest-bugs 2)))

(test-equal "newest-bugs generates XML"
  (string-trim-both (asset "requests/newest-bugs.xml"))
  (let ((op (newest-bugs 2)))
    (with-output-to-string
      (lambda _ (sxml->xml (soap-request-body op))))))

(test-equal "newest-bugs parses response"
  ((soap-request-callback (newest-bugs 3))
   (xml->sxml (asset "responses/newest-bugs1.xml")))
  (list 881351 881352 881353))


(test-equal "get-status generates soap request XML"
  (string-trim-both (asset "requests/get-status.xml"))
  (with-output-to-string
    (lambda _ (sxml->xml (soap-request-body (get-status (list 1 2 3)))))))

(test-assert "get-status parses response as bugs"
  (every bug?
         ((soap-request-callback (get-status (list 1 2 3)))
          (xml->sxml (asset "responses/get-status1.xml")
                     #:trim-whitespace? #t))))

(test-equal "get-status parses base64 fields"
  (map bug-originator ((soap-request-callback (get-status (list 1 2 3)))
                       (xml->sxml (asset "responses/get-status1.xml")
                                  #:trim-whitespace? #t)))
  '("Héllo Wörld <ümail@gnü.org>" "test <test@gnu.org>"))



(test-equal "get-bugs generates soap request XML"
  (string-trim-both (asset "requests/get-bugs.xml"))
  (with-output-to-string
    (lambda _
      (sxml->xml
       (soap-request-body (get-bugs '(("package" . "guix-patches")
                                      ("package" . "guix"))))))))

(test-end "operations")