File: fix-memento_find.t

package info (click to toggle)
libcatmandu-identifier-perl 0.15-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 292 kB
  • sloc: perl: 978; makefile: 2
file content (106 lines) | stat: -rw-r--r-- 2,463 bytes parent folder | download
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
#!/usr/bin/env perl

use strict;
use Test::More;
use Test::Exception;
use Encode;
use HTTP::Response;
use Test::LWP::UserAgent;

my $pkg;

BEGIN {
    $pkg = 'Catmandu::Fix::memento_find';
    use_ok $pkg;
}
require_ok $pkg;

user_agent();

dies_ok {$pkg->new()->fix({})} "path required";

dies_ok {$pkg->new('my.field')->fix({})} "date required";

my $data = {url => 'http://lib.ugent.be'};

lives_ok {$pkg->new('url', '2014')->fix($data)} "execute memento";

done_testing;

sub user_agent {
    my $ua = Test::LWP::UserAgent->new;

    my $example = <<EOF;
{
	"original_uri":"http://lib.ugent.be",
	"mementos":{
		"last":{
			"datetime":"2015-06-02T07:47:06Z",
			"uri":[
			   "http://wayback.archive-it.org/all/20150602074706/http://lib.ugent.be/"
			]
	    },
	    "next":{
	    	"datetime":"2013-01-06T10:51:03Z",
	    	"uri":[
	    		"http://web.archive.org/web/20130106105103/http://lib.ugent.be/",
	    		"http://wayback.archive-it.org/all/20130106105103/http://lib.ugent.be/"
	    	]
	    },
	    "closest":{
	    	"datetime":"2013-01-01T12:16:43Z",
	    	"uri":[
	    		"http://web.archive.org/web/20130101121643/http://lib.ugent.be/",
	    		"http://wayback.archive-it.org/all/20130101121643/http://lib.ugent.be/"
	    	]
	    },
	    "first":{
	    	"datetime":"2003-04-08T13:31:25Z",
	    	"uri":[
	    		"http://web.archive.org/web/20030408133125/http://www.lib.ugent.be/"
	    	]
	    },
	    "prev":{
	    	"datetime":"2012-12-31T07:28:20Z",
	    	"uri":[
	    		"http://archive.is/20121231072820/http://lib.ugent.be/"
	    	]
	    }
	},
	"timegate_uri":"http://timetravel.mementoweb.org/timegate/http://lib.ugent.be",
	"timemap_uri":{
		"json_format":"http://timetravel.mementoweb.org/timemap/json/http://lib.ugent.be",
		"link_format":"http://timetravel.mementoweb.org/timemap/link/http://lib.ugent.be"
	}
}
EOF

    add_response(
        $ua,
        '200',
        'OK',
        'http://timetravel.mementoweb.org/api/json/2013/http://lib.ugent.be',
        'application/json',
        $example
    );

    $LWP::Simple::ua = $ua;
}

sub add_response {
    my $ua           = shift;
    my $code         = shift;
    my $msg          = shift;
    my $url          = shift;
    my $content_type = shift;
    my $content      = shift;

    $ua->map_response(
        qr{^\Q$url\E$},
        HTTP::Response->new(
            $code, $msg,
            ['Content-Type' => $content_type],
            Encode::encode_utf8($content)
        )
    );
}