Skip to content

Commit e8bfbca

Browse files
committed
video iframe and embed tests
1 parent de01b00 commit e8bfbca

5 files changed

Lines changed: 215 additions & 0 deletions

File tree

tests/data/videos/test_embed.html

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/loose.dtd"><html>
2+
<html>
3+
<head>
4+
<title>test video</title>
5+
</head>
6+
7+
<body>
8+
<div>
9+
<p>
10+
TextNode 1 - The Scala supported IDE is one of the few pain points of developers who want to start using Scala in their Java project. On existing long term project developed by a team its hard to step in and introduce a new language that is not supported by the existing IDE. On way to go about it is to hid the fact that you use Scala from the Java world by using one way dependency injection. Still, if you wish to truly absorb Scala into your existing java environment then you'll soon introduced cross language dependencies.
11+
</p>
12+
<p>
13+
<object width="640" height="390">
14+
<param name="movie" value="https://www.youtube.com/v/M7lc1UVf-VE?version=3&autoplay=1"></param>
15+
<param name="allowScriptAccess" value="always"></param>
16+
<embed src="https://www.youtube.com/v/M7lc1UVf-VE?version=3&autoplay=1"
17+
type="application/x-shockwave-flash"
18+
allowscriptaccess="always"
19+
width="640" height="390"></embed>
20+
</object>
21+
</p>
22+
<p>
23+
Most of our team is using Eclipse as the main IDE, its incrimental compilation in Java with its tight JUnit integration are great for fast TDD programming. Unfortunately the Eclipse Scala plugin is not there yet, it may hangs the IDE and messes up Java compilation - especially in large (more then 1000 source files) Java/Scala projects. Though the plugin is getting better over time some developers would find the plugin as a majore drag on their productivity.
24+
For developers who do not write Scala at all or rather edit Scala with other editors, you can use this alternate path which lets them work on their Java or Scala code without messing with the plugin.
25+
</p>
26+
<p>
27+
Paragraph 1 - The Following script is using the Fast Scala Compiler (fsc). The fsc is a compilation server which always run in the background, as in a warm scalac always ready to receive new work. Is will reduce compilation time dramatically.
28+
</p>
29+
<p>
30+
<object width="640" height="390">
31+
<param name="movie" value="https://www.youtube.com/v/M7lc1UVf-VE?version=3&autoplay=1"></param>
32+
<param name="allowScriptAccess" value="always"></param>
33+
<embed src="https://www.youtube.com/v/M7lc1UVf-VE?version=3&autoplay=1"
34+
type="application/x-shockwave-flash"
35+
allowscriptaccess="always"
36+
width="640" height="390"></embed>
37+
</object>
38+
</p>
39+
<p>
40+
TextNode 2 - As you may know, kaChing is an test driven engineering organization. Test driven is not an option, its a must. We move fast and push code to production few dozens of times a day in a five minutes release cycle, so we must have high confidence in our code.
41+
In complex systems there is no end to testings, each test system is an another line of defense which eventually gets broken but the more you have, the less chances bugs will reach production. We do not have QA team and do not want to have one, the reasoning is that if a human is involved in testing then there is a higher chance of missing things and you simply can't test all the site dozens of times a day.
42+
</p>
43+
<p>
44+
Paragraph 2 - In the next few weeks we are adding a new rule from the "not critical" list every few days. The goal is to have all the rules we think are important without the common "its to noisy, lets ignore it" approche. Only after we're done with that we're going to add the next static analysis tool to build. The good thing about these tools and hudson is that you can run them in parallel to the unit/integration tests, on another machine, so they won't slow down the overall release cycle.
45+
</p>
46+
</div>
47+
</body>
48+
</html>

tests/data/videos/test_embed.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"url": "http://foo.bar/index.html",
3+
"expected": {
4+
"movies": [
5+
{
6+
"src": "https://www.youtube.com/v/M7lc1UVf-VE?version=3&autoplay=1",
7+
"embed_code": "<embed src=\"https://www.youtube.com/v/M7lc1UVf-VE?version=3&amp;autoplay=1\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" width=\"640\" height=\"390\"/>",
8+
"height": "390",
9+
"width": "640",
10+
"provider": "youtube",
11+
"embed_type": "embed"
12+
},
13+
{
14+
"src": "https://www.youtube.com/v/M7lc1UVf-VE?version=3&autoplay=1",
15+
"embed_code": "<embed src=\"https://www.youtube.com/v/M7lc1UVf-VE?version=3&amp;autoplay=1\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" width=\"640\" height=\"390\"/>",
16+
"height": "390",
17+
"width": "640",
18+
"provider": "youtube",
19+
"embed_type": "embed"
20+
}
21+
]
22+
}
23+
}

tests/data/videos/test_iframe.html

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/loose.dtd"><html>
2+
<html>
3+
<head>
4+
<title>test video</title>
5+
</head>
6+
7+
<body>
8+
<div>
9+
<p>
10+
TextNode 1 - The Scala supported IDE is one of the few pain points of developers who want to start using Scala in their Java project. On existing long term project developed by a team its hard to step in and introduce a new language that is not supported by the existing IDE. On way to go about it is to hid the fact that you use Scala from the Java world by using one way dependency injection. Still, if you wish to truly absorb Scala into your existing java environment then you'll soon introduced cross language dependencies.
11+
</p>
12+
<p>
13+
<iframe frameborder="0" width="480" height="270" src="http://www.dailymotion.com/embed/video/x130bpf"></iframe>
14+
</p>
15+
<p>
16+
Most of our team is using Eclipse as the main IDE, its incrimental compilation in Java with its tight JUnit integration are great for fast TDD programming. Unfortunately the Eclipse Scala plugin is not there yet, it may hangs the IDE and messes up Java compilation - especially in large (more then 1000 source files) Java/Scala projects. Though the plugin is getting better over time some developers would find the plugin as a majore drag on their productivity.
17+
For developers who do not write Scala at all or rather edit Scala with other editors, you can use this alternate path which lets them work on their Java or Scala code without messing with the plugin.
18+
</p>
19+
<p>
20+
Paragraph 1 - The Following script is using the Fast Scala Compiler (fsc). The fsc is a compilation server which always run in the background, as in a warm scalac always ready to receive new work. Is will reduce compilation time dramatically.
21+
</p>
22+
<p>
23+
<iframe frameborder="0" width="480" height="270" src="http://www.dailymotion.com/embed/video/x130bpf"></iframe>
24+
</p>
25+
<p>
26+
TextNode 2 - As you may know, kaChing is an test driven engineering organization. Test driven is not an option, its a must. We move fast and push code to production few dozens of times a day in a five minutes release cycle, so we must have high confidence in our code.
27+
In complex systems there is no end to testings, each test system is an another line of defense which eventually gets broken but the more you have, the less chances bugs will reach production. We do not have QA team and do not want to have one, the reasoning is that if a human is involved in testing then there is a higher chance of missing things and you simply can't test all the site dozens of times a day.
28+
</p>
29+
<p>
30+
Paragraph 2 - In the next few weeks we are adding a new rule from the "not critical" list every few days. The goal is to have all the rules we think are important without the common "its to noisy, lets ignore it" approche. Only after we're done with that we're going to add the next static analysis tool to build. The good thing about these tools and hudson is that you can run them in parallel to the unit/integration tests, on another machine, so they won't slow down the overall release cycle.
31+
</p>
32+
</div>
33+
</body>
34+
</html>

tests/data/videos/test_iframe.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"url": "http://foo.bar/index.html",
3+
"expected": {
4+
"movies": [
5+
{
6+
"src": "http://www.dailymotion.com/embed/video/x130bpf",
7+
"embed_code": "<iframe frameborder=\"0\" width=\"480\" height=\"270\" src=\"http://www.dailymotion.com/embed/video/x130bpf\"/>\n ",
8+
"height": "270",
9+
"width": "480",
10+
"provider": "dailymotion",
11+
"embed_type": "iframe"
12+
},
13+
{
14+
"src": "http://www.dailymotion.com/embed/video/x130bpf",
15+
"embed_code": "<iframe frameborder=\"0\" width=\"480\" height=\"270\" src=\"http://www.dailymotion.com/embed/video/x130bpf\"/>\n ",
16+
"height": "270",
17+
"width": "480",
18+
"provider": "dailymotion",
19+
"embed_type": "iframe"
20+
}
21+
]
22+
}
23+
}

tests/videos.py

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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

Comments
 (0)