def setUp(self):
     self.redis = Redis(db=TEST_DB)
     existing_keys = self.redis.keys('*')
     self.assertFalse(
         existing_keys,
         'Redis database "%s" must be empty to run these tests' %
         (TEST_DB, ))
     self.curator = Curator('curator', 'tests/sample_lua', self.redis)
예제 #2
0
def test_add_entry_for_unique_url():
    curator = Curator(TEST_URL)
    dao_mock = Mock()
    dao_mock.entry_visited = Mock(return_value=None)
    curator.dao = dao_mock
    entry = {'link': TEST_URL}
    curator._Curator__add_entry_if_unique(entry)
    assert len(curator.entries_to_keep) == 1
    assert curator.entries_to_keep[0] == entry
예제 #3
0
def test_add_entry_for_unique_url():
    curator = Curator(TEST_URL)
    dao_mock = Mock()
    dao_mock.entry_visited = Mock(return_value=None) 
    curator.dao = dao_mock
    entry = {'link' : TEST_URL}
    curator._Curator__add_entry_if_unique(entry)
    assert len(curator.entries_to_keep) == 1
    assert curator.entries_to_keep[0] == entry
예제 #4
0
 def setUp(self):
     self.redis = Redis(db=TEST_DB)
     existing_keys = self.redis.keys('*')
     self.assertFalse(
         existing_keys,
         'Redis database "%s" must be empty to run these tests' % (TEST_DB,)
     )
     self.curator = Curator('curator', 'tests/sample_lua', self.redis)
예제 #5
0
class ScriptLoadingTests(unittest2.TestCase):

    def setUp(self):
        self.redis = Redis(db=TEST_DB)
        existing_keys = self.redis.keys('*')
        self.assertFalse(
            existing_keys,
            'Redis database "%s" must be empty to run these tests' % (TEST_DB,)
        )
        self.curator = Curator('curator', 'tests/sample_lua', self.redis)

    def tearDown(self):
        self.redis.flushdb()
        self.redis.script_flush()

    def test_load_mexists(self):
        result = self.curator.util.exists.mexists(
            keys=['key0', 'key2', 'key3'],
        )
        self.assertEqual(result, [0, 0, 0])

    def test_util_mexists(self):
        self.redis.set('key1', 'value')
        result = self.curator.util.exists.mexists(
            keys=['key0', 'key1', 'key2'],
        )
        self.assertEqual(result, [0, 1, 0])

    def test_load_lua_include_partial(self):
        result = self.curator.util.include()
        self.assertEqual(result, 1)

    def test_load_mexists_from_cache(self):
        # calling it the first time should put it in the cache
        result = self.curator.util.exists.mexists(keys=['key0', 'key1'])
        with mock.patch.object(Template, 'render') as mock_render:
            mock_render.return_value = 'test'
            cached_result = self.curator.util.exists.mexists(
                keys=['key0', 'key1'],
            )
            self.assertEqual(result, cached_result)
            # render should not have been called since we fetched from cache
            self.assertEqual(mock_render.call_count, 0)

    def test_access_nonexistant_script(self):
        with self.assertRaises(ScriptNotFound) as e:
            self.curator.invalid.path.to.script(keys=['key1'])
        self.assertEqual(e.exception.path, 'invalid/path/to/script')

    def test_load_script_base_dir(self):
        result = self.curator.base()
        self.assertEqual(result, 1)
예제 #6
0
파일: news.py 프로젝트: robertarles/rabot
 def get_trends(self):
     trend_list = []
     driver = webdriver.PhantomJS(executable_path="/usr/local/bin/phantomjs")
     try:
         driver.get("https://www.google.com/trends/hottrends")
         trends = driver.find_elements_by_css_selector("div.hottrends-single-trend-container")
         # response = requests.get("https://www.google.com/trends/hottrends")
         # soup = BeautifulSoup(content, 'html.parser')
         # trends = soup.find_all("div")#, "hottrends-single-trend-container")
         for trend in trends:
             search_term = trend.find_element_by_css_selector("span.hottrends-single-trend-title").text
             article_href = trend.find_element_by_tag_name("a").get_attribute("href")
             search_count = trend.find_element_by_css_selector("span.hottrends-single-trend-info-line-number").text
             search_count = int(search_count.replace("+", "").replace(",", ""))
             trend_list.append({"search_term": search_term, "search_count": search_count, "href": article_href})
         curator = Curator()
         curator.process_trends(trend_list, ["`store`", "trends"], "rabot32")
     except:
         print("exception in get_trends() running webdriver?")
     finally:
         driver.close()
     return trend_list
class ScriptLoadingTests(unittest2.TestCase):
    def setUp(self):
        self.redis = Redis(db=TEST_DB)
        existing_keys = self.redis.keys('*')
        self.assertFalse(
            existing_keys,
            'Redis database "%s" must be empty to run these tests' %
            (TEST_DB, ))
        self.curator = Curator('curator', 'tests/sample_lua', self.redis)

    def tearDown(self):
        self.redis.flushdb()
        self.redis.script_flush()

    def test_load_mexists(self):
        result = self.curator.util.exists.mexists(
            keys=['key0', 'key2', 'key3'], )
        self.assertEqual(result, [0, 0, 0])

    def test_util_mexists(self):
        self.redis.set('key1', 'value')
        result = self.curator.util.exists.mexists(
            keys=['key0', 'key1', 'key2'], )
        self.assertEqual(result, [0, 1, 0])

    def test_load_lua_include_partial(self):
        result = self.curator.util.include()
        self.assertEqual(result, 1)

    def test_load_mexists_from_cache(self):
        # calling it the first time should put it in the cache
        result = self.curator.util.exists.mexists(keys=['key0', 'key1'])
        with mock.patch.object(Template, 'render') as mock_render:
            mock_render.return_value = 'test'
            cached_result = self.curator.util.exists.mexists(
                keys=['key0', 'key1'], )
            self.assertEqual(result, cached_result)
            # render should not have been called since we fetched from cache
            self.assertEqual(mock_render.call_count, 0)

    def test_access_nonexistant_script(self):
        with self.assertRaises(ScriptNotFound) as e:
            self.curator.invalid.path.to.script(keys=['key1'])
        self.assertEqual(e.exception.path, 'invalid/path/to/script')

    def test_load_script_base_dir(self):
        result = self.curator.base()
        self.assertEqual(result, 1)
예제 #8
0
#!/usr/bin/env python

import os
import sys

from curator import Curator
from curatorpublisher import CuratorPublisher


def get_feed_url_from_args():
    return sys.argv[1]


# Command Line
if len(sys.argv) < 2:
    sys.exit('usage: %s feed_name_or_url' % sys.argv[0])

url = get_feed_url_from_args()
curator = Curator(url)
curator.curate()
content = curator.generate_template()
publisher = CuratorPublisher(url)
publisher.publish_feed_to_s3(content)
예제 #9
0
파일: tests.py 프로젝트: stencila/hub
#  the Free Software Foundation, either version 3 of the License, or
#  (at your option) any later version.
#  
#  Stencila Hub 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 Affero General Public License for more details.
#  
#  You should have received a copy of the GNU Affero General Public License
#  along with Stencila Hub.  If not, see <http://www.gnu.org/licenses/>.

import unittest

from curator import Curator

curator = Curator()
curator.store_temporary()
print curator.store


class ComponentTests(unittest.TestCase):

    def test_init(self):
        curator.init('foo', 'stencil')

        meta = curator.meta('foo')
        self.assertEqual(
            meta['type'],
            'stencil'
        )
        self.assertEqual(
예제 #10
0
#!/usr/bin/env python

import os
import sys

from curator import Curator
from curatorpublisher import CuratorPublisher

def get_feed_url_from_args():
    return sys.argv[1]


# Command Line
if len(sys.argv) < 2:
    sys.exit('usage: %s feed_name_or_url' % sys.argv[0])
    
url = get_feed_url_from_args()
curator = Curator(url)
curator.curate()
content = curator.generate_template() 
publisher = CuratorPublisher(url)
publisher.publish_feed_to_s3(content)

예제 #11
0
from code_reviewer import CodeReviewer
from curator import Curator
from human import Human
from mentor import Mentor
from student import Student
from weather_man import WeatherMan

student = Student("Тимофей")
curator = Curator("Марина")
mentor = Mentor("Ира")
reviewer = CodeReviewer("Евгений")
friend = Human("Виталя")
weather_man = WeatherMan("Игорь")
# weather_man2 = WeatherMan("Игорь")

print(student.ask_question(curator, 'мне грустненько, что делать?'))
print(student.ask_question(friend, 'Как твое имя?'))
print(student.ask_question(mentor, 'мне грустненько, что делать?'))
print(student.ask_question(reviewer, 'когда каникулы?'))
print(student.ask_question(reviewer, 'что не так с моим проектом?'))
print(student.ask_question(friend, 'как устроиться на работу питонистом?'))
print(student.ask_question(mentor, 'как устроиться работать питонистом?'))
print(student.ask_question(mentor, 'как с погодой?'))

print(student.ask_question(weather_man, 'как с погодой?'))
print(student.ask_question(friend, 'Сколько у меня наследников?'))
예제 #12
0
def test_entry_is_unique_when_dao_says_so():
    curator = Curator(TEST_URL)
    curator.dao = Mock()
    curator.dao.entry_visited = Mock(return_value=None)
    assert curator._Curator__is_entry_unique(TEST_URL) == True
예제 #13
0
from curator import Curator
from mock import Mock, patch

TEST_URL = 'http://test.com/rss'
curator = Curator(TEST_URL)


def test_add_entry_for_unique_url():
    curator = Curator(TEST_URL)
    dao_mock = Mock()
    dao_mock.entry_visited = Mock(return_value=None)
    curator.dao = dao_mock
    entry = {'link': TEST_URL}
    curator._Curator__add_entry_if_unique(entry)
    assert len(curator.entries_to_keep) == 1
    assert curator.entries_to_keep[0] == entry


def test_entry_is_unique_when_dao_says_so():
    curator = Curator(TEST_URL)
    curator.dao = Mock()
    curator.dao.entry_visited = Mock(return_value=None)
    assert curator._Curator__is_entry_unique(TEST_URL) == True


def test_cleanup_link_with_trailing_slash():
    assert curator._Curator__cleanup_link_url(TEST_URL + '/') == TEST_URL


def test_cleanup_link_with_no_trailing_slash():
    assert curator._Curator__cleanup_link_url(TEST_URL) == TEST_URL
예제 #14
0
def test_entry_is_unique_when_dao_says_so():
    curator = Curator(TEST_URL)
    curator.dao = Mock()
    curator.dao.entry_visited = Mock(return_value=None)
    assert curator._Curator__is_entry_unique(TEST_URL) == True