|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +"""\ |
| 3 | +This is a python port of "Goose" orignialy licensed to Gravity.com |
| 4 | +under one or more contributor license agreements. See the NOTICE file |
| 5 | +distributed with this work for additional information |
| 6 | +regarding copyright ownership. |
| 7 | +
|
| 8 | +Python port was written by Xavier Grangier for Recrutae |
| 9 | +
|
| 10 | +Gravity.com licenses this file |
| 11 | +to you under the Apache License, Version 2.0 (the "License"); |
| 12 | +you may not use this file except in compliance |
| 13 | +with the License. You may obtain a copy of the License at |
| 14 | +
|
| 15 | +http://www.apache.org/licenses/LICENSE-2.0 |
| 16 | +
|
| 17 | +Unless required by applicable law or agreed to in writing, software |
| 18 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 19 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 20 | +See the License for the specific language governing permissions and |
| 21 | +limitations under the License. |
| 22 | +""" |
| 23 | +import os |
| 24 | +import json |
| 25 | +import hashlib |
| 26 | +import unittest |
| 27 | + |
| 28 | +from base import MockResponse |
| 29 | +from extractors import TestExtractionBase |
| 30 | + |
| 31 | +from goose.configuration import Configuration |
| 32 | +from goose.images.image import ImageDetails |
| 33 | +from goose.images.utils import ImageUtils |
| 34 | +from goose.utils import FileHelper |
| 35 | + |
| 36 | +CURRENT_PATH = os.path.dirname(os.path.abspath(__file__)) |
| 37 | + |
| 38 | + |
| 39 | +class MockResponseVideos(MockResponse): |
| 40 | + def content(self, req): |
| 41 | + current_test = self.cls._get_current_testname() |
| 42 | + path = os.path.join(CURRENT_PATH, "data", "videos", "%s.html" % current_test) |
| 43 | + path = os.path.abspath(path) |
| 44 | + content = FileHelper.loadResourceFile(path) |
| 45 | + return content |
| 46 | + |
| 47 | + |
| 48 | +class ImageExtractionTests(TestExtractionBase): |
| 49 | + """\ |
| 50 | + Base Mock test case |
| 51 | + """ |
| 52 | + callback = MockResponseVideos |
| 53 | + |
| 54 | + def assert_movies(self, field, expected_value, result_value): |
| 55 | + # check if result_value is a list |
| 56 | + self.assertTrue(isinstance(result_value, list)) |
| 57 | + # check number of videos |
| 58 | + self.assertEqual(len(expected_value), len(result_value)) |
| 59 | + |
| 60 | + # check values |
| 61 | + for c, video in enumerate(result_value): |
| 62 | + expected = expected_value[c] |
| 63 | + for k, v in expected.items(): |
| 64 | + r = getattr(video, k) |
| 65 | + self.assertEqual(r, v) |
| 66 | + |
| 67 | + def loadData(self): |
| 68 | + """\ |
| 69 | +
|
| 70 | + """ |
| 71 | + suite, module, cls, func = self.id().split('.') |
| 72 | + path = os.path.join(CURRENT_PATH, "data", module, "%s.json" % func) |
| 73 | + path = os.path.abspath(path) |
| 74 | + content = FileHelper.loadResourceFile(path) |
| 75 | + self.data = json.loads(content) |
| 76 | + |
| 77 | + def test_embed(self): |
| 78 | + article = self.getArticle() |
| 79 | + fields = ['movies'] |
| 80 | + self.runArticleAssertions(article=article, fields=fields) |
| 81 | + |
| 82 | + def test_iframe(self): |
| 83 | + article = self.getArticle() |
| 84 | + fields = ['movies'] |
| 85 | + self.runArticleAssertions(article=article, fields=fields) |
| 86 | + |
| 87 | + |
0 commit comments