def test_has_changes_hash_is_different_stored_hash_updated(self):
        uri_check = UriCheck()
        check = HashCheck(uri_check)
        url_reader_fake = FakeUrlReader('page')

        check.has_changes(url_reader_fake)
        self.assertEqual(uri_check.check_options, HashCheckTests.md_hash_page)
    def test_has_changes_hashTheSame_NoChange(self):
        uri_check = UriCheck()
        uri_check.check_options = HashCheckTests.md_hash_page

        check = HashCheck(uri_check) 
        url_reader_fake = FakeUrlReader('page')

        self.assertFalse(check.has_changes(url_reader_fake))
Exemplo n.º 3
0
def create_or_get_uri_check(db, url):
    if not (url.startswith('http://') or url.startswith('https://')):
        url = 'http://' + url
    
    try:
        found_check = db.query(UriCheck).filter(UriCheck.url == url).one()
        return found_check
    except NoResultFound:
        #Url is not being monitored, ignore the error and create it
        pass

    check = UriCheck()
    check.url = url 
    check.check_options 

    first_monitor = HashCheck(check)
    try:
        url_stream = urllib2.urlopen(check.url)
        first_monitor.has_changes(url_stream)
    except urllib2.URLError, e:
        if not isinstance(e, urllib2.HTTPError):
            log.error(e.reason)
            return None
    def test_has_changes_hashDifferentSame_ReturnsTrue(self):
        uri_check = UriCheck()
        check = HashCheck(uri_check)
        url_reader_fake = FakeUrlReader('page')

        self.assertTrue(check.has_changes(url_reader_fake))