|
| 1 | +from simplejustwatchpythonapi.parser import MediaEntry, Offer, parse_search_response |
| 2 | + |
| 3 | +DETAILS_URL = "https://justwatch.com" |
| 4 | +IMAGES_URL = "https://images.justwatch.com" |
| 5 | + |
| 6 | +RESPONSE_NODE_1 = { |
| 7 | + "id": "id1", |
| 8 | + "objectId": 1, |
| 9 | + "objectType": "MOVIE", |
| 10 | + "content": { |
| 11 | + "title": "title 1", |
| 12 | + "fullPath": "/full/path/1/", |
| 13 | + "originalReleaseYear": 2000, |
| 14 | + "originalReleaseDate": "21-06-2000", |
| 15 | + "genres": [{"shortName": "gen1"}, {"shortName": "gen2"}], |
| 16 | + "externalIds": {"imdbId": "imdbId1"}, |
| 17 | + "posterUrl": "/poster/url/1.jpg", |
| 18 | + "backdrops": [ |
| 19 | + {"backdropUrl": "/back/drop/url/1.jpg"}, |
| 20 | + {"backdropUrl": "/back/drop/url/2.jpg"}, |
| 21 | + ], |
| 22 | + }, |
| 23 | + "offers": [ |
| 24 | + { |
| 25 | + "monetizationType": "MON_TYPE_1", |
| 26 | + "presentationType": "HD", |
| 27 | + "standardWebURL": "www.service1.com/offer/url/1/", |
| 28 | + "retailPrice": "$19.99", |
| 29 | + "retailPriceValue": 19.99, |
| 30 | + "currency": "USD", |
| 31 | + "package": { |
| 32 | + "clearName": "Service 1", |
| 33 | + "technicalName": "service1", |
| 34 | + "icon": "/icon/url/service1", |
| 35 | + }, |
| 36 | + }, |
| 37 | + { |
| 38 | + "monetizationType": "MON_TYPE_1", |
| 39 | + "presentationType": "SD", |
| 40 | + "standardWebURL": "www.service1.com/offer/url/1/", |
| 41 | + "retailPrice": "$9.99", |
| 42 | + "retailPriceValue": 9.99, |
| 43 | + "currency": "USD", |
| 44 | + "package": { |
| 45 | + "clearName": "Service 1", |
| 46 | + "technicalName": "service1", |
| 47 | + "icon": "/icon/url/service1", |
| 48 | + }, |
| 49 | + }, |
| 50 | + ], |
| 51 | +} |
| 52 | +PARSED_NODE_1 = MediaEntry( |
| 53 | + "id1", |
| 54 | + 1, |
| 55 | + "MOVIE", |
| 56 | + "title 1", |
| 57 | + DETAILS_URL + "/full/path/1/", |
| 58 | + 2000, |
| 59 | + "21-06-2000", |
| 60 | + ["gen1", "gen2"], |
| 61 | + "imdbId1", |
| 62 | + IMAGES_URL + "/poster/url/1.jpg", |
| 63 | + [IMAGES_URL + "/back/drop/url/1.jpg", IMAGES_URL + "/back/drop/url/2.jpg"], |
| 64 | + [ |
| 65 | + Offer( |
| 66 | + "MON_TYPE_1", |
| 67 | + "HD", |
| 68 | + "www.service1.com/offer/url/1/", |
| 69 | + "$19.99", |
| 70 | + 19.99, |
| 71 | + "USD", |
| 72 | + "Service 1", |
| 73 | + "service1", |
| 74 | + IMAGES_URL + "/icon/url/service1", |
| 75 | + ), |
| 76 | + Offer( |
| 77 | + "MON_TYPE_1", |
| 78 | + "SD", |
| 79 | + "www.service1.com/offer/url/1/", |
| 80 | + "$9.99", |
| 81 | + 9.99, |
| 82 | + "USD", |
| 83 | + "Service 1", |
| 84 | + "service1", |
| 85 | + IMAGES_URL + "/icon/url/service1", |
| 86 | + ), |
| 87 | + ], |
| 88 | +) |
| 89 | + |
| 90 | +RESPONSE_NODE_2 = { |
| 91 | + "id": "id2", |
| 92 | + "objectId": 2, |
| 93 | + "objectType": "TV SHOW", |
| 94 | + "content": { |
| 95 | + "title": "title 2", |
| 96 | + "fullPath": "/full/path/2/", |
| 97 | + "originalReleaseYear": 2010, |
| 98 | + "originalReleaseDate": "11-01-2010", |
| 99 | + "genres": [{"shortName": "gen2"}, {"shortName": "gen3"}], |
| 100 | + "externalIds": {"imdbId": "imdbId2"}, |
| 101 | + "posterUrl": "/poster/url/2.jpg", |
| 102 | + "backdrops": [ |
| 103 | + {"backdropUrl": "/back/drop/url/3.jpg"}, |
| 104 | + ], |
| 105 | + }, |
| 106 | + "offers": [ |
| 107 | + { |
| 108 | + "monetizationType": "MON_TYPE_3", |
| 109 | + "presentationType": "_4K", |
| 110 | + "standardWebURL": "www.service2.com/offer/url/2/", |
| 111 | + "retailPrice": "£199.9", |
| 112 | + "retailPriceValue": 199.9, |
| 113 | + "currency": "GBP", |
| 114 | + "package": { |
| 115 | + "clearName": "Service 2", |
| 116 | + "technicalName": "service2", |
| 117 | + "icon": "/icon/url/service2", |
| 118 | + }, |
| 119 | + }, |
| 120 | + ], |
| 121 | +} |
| 122 | +PARSED_NODE_2 = MediaEntry( |
| 123 | + "id2", |
| 124 | + 2, |
| 125 | + "TV SHOW", |
| 126 | + "title 2", |
| 127 | + DETAILS_URL + "/full/path/2/", |
| 128 | + 2010, |
| 129 | + "11-01-2010", |
| 130 | + ["gen2", "gen3"], |
| 131 | + "imdbId2", |
| 132 | + IMAGES_URL + "/poster/url/2.jpg", |
| 133 | + [IMAGES_URL + "/back/drop/url/3.jpg"], |
| 134 | + [ |
| 135 | + Offer( |
| 136 | + "MON_TYPE_3", |
| 137 | + "_4K", |
| 138 | + "www.service2.com/offer/url/2/", |
| 139 | + "£199.9", |
| 140 | + 199.9, |
| 141 | + "GBP", |
| 142 | + "Service 2", |
| 143 | + "service2", |
| 144 | + IMAGES_URL + "/icon/url/service2", |
| 145 | + ), |
| 146 | + ], |
| 147 | +) |
| 148 | +RESPONSE_NODE_3 = { |
| 149 | + "id": "id3", |
| 150 | + "objectId": 3, |
| 151 | + "objectType": "OTHER", |
| 152 | + "content": { |
| 153 | + "title": "title 3", |
| 154 | + "fullPath": "/full/path/3/", |
| 155 | + "originalReleaseYear": 2020, |
| 156 | + "originalReleaseDate": "12-02-2020", |
| 157 | + "posterUrl": "/poster/url/3.jpg", |
| 158 | + }, |
| 159 | +} |
| 160 | +PARSED_NODE_3 = MediaEntry( |
| 161 | + "id3", |
| 162 | + 3, |
| 163 | + "OTHER", |
| 164 | + "title 3", |
| 165 | + DETAILS_URL + "/full/path/3/", |
| 166 | + 2020, |
| 167 | + "12-02-2020", |
| 168 | + [], |
| 169 | + None, |
| 170 | + IMAGES_URL + "/poster/url/3.jpg", |
| 171 | + [], |
| 172 | + [], |
| 173 | +) |
| 174 | + |
| 175 | +API_RESPONSE_JSON = { |
| 176 | + "data": { |
| 177 | + "popularTitles": { |
| 178 | + "edges": [ |
| 179 | + {"node": RESPONSE_NODE_1}, |
| 180 | + {"node": RESPONSE_NODE_2}, |
| 181 | + {"node": RESPONSE_NODE_3}, |
| 182 | + ] |
| 183 | + } |
| 184 | + } |
| 185 | +} |
| 186 | + |
| 187 | + |
| 188 | +def test_parse() -> None: |
| 189 | + parsed_entries = parse_search_response(API_RESPONSE_JSON) |
| 190 | + assert [PARSED_NODE_1, PARSED_NODE_2, PARSED_NODE_3] == parsed_entries |
0 commit comments