示例#1
0
    def setUp(self):

        WebSite.drop_collection()
        Article.drop_collection()

        self.ws1 = WebSite(url='http://test1.com').save()
        self.ws2 = WebSite(url='http://test2.com').save()
示例#2
0
    def setUp(self):

        WebSite.drop_collection()
        Article.drop_collection()

        self.ws1 = WebSite(url='http://test1.com').save()
        self.ws2 = WebSite(url='http://test2.com').save()
示例#3
0
    def test_get_from_url(self):

        wt1 = WebSite.get_from_url('http://test1.com/example-article')
        wt2 = WebSite.get_from_url('http://test1.com/example-article2')

        self.assertEquals(wt1, self.ws1)
        self.assertEquals(wt1, self.ws1)
        self.assertEquals(wt1, wt2)
示例#4
0
    def test_get_from_url(self):

        wt1 = WebSite.get_from_url('http://test1.com/example-article')
        wt2 = WebSite.get_from_url('http://test1.com/example-article2')

        self.assertEquals(wt1, self.ws1)
        self.assertEquals(wt1, self.ws1)
        self.assertEquals(wt1, wt2)
示例#5
0
def synchronize_statsd_websites_gauges(full=False):

    with benchmark('synchronize statsd gauges for WebSite.*'):

        statsd.gauge('websites.counts.total', WebSite._get_collection().count())

        if full:
            duplicates = WebSite.objects(duplicate_of__ne=None).no_cache()
            statsd.gauge('websites.counts.duplicates', duplicates.count())
示例#6
0
    def test_register_duplicate_not_again(self):

        wt1, created = WebSite.get_or_create_website('http://other.test1.com')

        self.ws1.register_duplicate(wt1)

        self.assertTrue(created)
        self.assertEquals(wt1.duplicate_of, self.ws1)

        wt2, created = WebSite.get_or_create_website('http://other.test1.com')

        self.assertFalse(created)
        self.assertNotEquals(wt2, wt1)
        self.assertEquals(wt2, self.ws1)
示例#7
0
    def test_register_duplicate_not_again(self):

        wt1, created = WebSite.get_or_create_website('http://other.test1.com')

        self.ws1.register_duplicate(wt1)

        self.assertTrue(created)
        self.assertEquals(wt1.duplicate_of, self.ws1)

        wt2, created = WebSite.get_or_create_website('http://other.test1.com')

        self.assertFalse(created)
        self.assertNotEquals(wt2, wt1)
        self.assertEquals(wt2, self.ws1)
示例#8
0
    def test_get_or_create_website(self):

        wt1, created = WebSite.get_or_create_website('http://test1.com')

        self.assertFalse(created)
        self.assertEquals(wt1, self.ws1)

        wt3, created = WebSite.get_or_create_website('http://test3.com')

        self.assertTrue(created)
        self.assertNotEquals(wt3, self.ws1)
        self.assertNotEquals(wt3, self.ws2)

        wt4, created = WebSite.get_or_create_website('http://test3.com')

        self.assertFalse(created)
        self.assertEquals(wt3, wt4)

        wt5, created = WebSite.get_or_create_website('http://test3.com/')

        self.assertTrue(created)
        self.assertNotEquals(wt5, wt4)
示例#9
0
    def test_get_or_create_website(self):

        wt1, created = WebSite.get_or_create_website('http://test1.com')

        self.assertFalse(created)
        self.assertEquals(wt1, self.ws1)

        wt3, created = WebSite.get_or_create_website('http://test3.com')

        self.assertTrue(created)
        self.assertNotEquals(wt3, self.ws1)
        self.assertNotEquals(wt3, self.ws2)

        wt4, created = WebSite.get_or_create_website('http://test3.com')

        self.assertFalse(created)
        self.assertEquals(wt3, wt4)

        wt5, created = WebSite.get_or_create_website('http://test3.com/')

        self.assertTrue(created)
        self.assertNotEquals(wt5, wt4)
示例#10
0
 def tearDown(self):
     WebSite.drop_collection()
     Article.drop_collection()
示例#11
0
class WebSitesTest(TestCase):
    def setUp(self):

        WebSite.drop_collection()
        Article.drop_collection()

        self.ws1 = WebSite(url='http://test1.com').save()
        self.ws2 = WebSite(url='http://test2.com').save()

    def tearDown(self):
        WebSite.drop_collection()
        Article.drop_collection()

    def test_get_or_create_website(self):

        wt1, created = WebSite.get_or_create_website('http://test1.com')

        self.assertFalse(created)
        self.assertEquals(wt1, self.ws1)

        wt3, created = WebSite.get_or_create_website('http://test3.com')

        self.assertTrue(created)
        self.assertNotEquals(wt3, self.ws1)
        self.assertNotEquals(wt3, self.ws2)

        wt4, created = WebSite.get_or_create_website('http://test3.com')

        self.assertFalse(created)
        self.assertEquals(wt3, wt4)

        wt5, created = WebSite.get_or_create_website('http://test3.com/')

        self.assertTrue(created)
        self.assertNotEquals(wt5, wt4)

    def test_get_from_url(self):

        wt1 = WebSite.get_from_url('http://test1.com/example-article')
        wt2 = WebSite.get_from_url('http://test1.com/example-article2')

        self.assertEquals(wt1, self.ws1)
        self.assertEquals(wt1, self.ws1)
        self.assertEquals(wt1, wt2)

    def test_register_duplicate_not_again(self):

        wt1, created = WebSite.get_or_create_website('http://other.test1.com')

        self.ws1.register_duplicate(wt1)

        self.assertTrue(created)
        self.assertEquals(wt1.duplicate_of, self.ws1)

        wt2, created = WebSite.get_or_create_website('http://other.test1.com')

        self.assertFalse(created)
        self.assertNotEquals(wt2, wt1)
        self.assertEquals(wt2, self.ws1)

        # should fail.
        #self.ws2.register_duplicate(wt1)

        #
        # TODO: finish this test case.
        #

    def test_websites_duplicates(self):
        pass
示例#12
0
# Use the test database not to pollute the production/development one.
RedisStatsCounter.REDIS = TEST_REDIS

TEST_REDIS.flushdb()

connect_mongodb_testsuite()

# Empty the database before starting in case an old test failed to tearDown().
Article.drop_collection()
Read.drop_collection()
User.drop_collection()
Group.drop_collection()
Feed.drop_collection()
Tag.drop_collection()
Folder.drop_collection()
WebSite.drop_collection()
Author.drop_collection()


class ThrottleIntervalTest(TestCase):

    def test_lower_interval_with_etag_or_modified(self):

        t = Feed.throttle_fetch_interval

        some_news = 10
        no_dupe   = 0
        no_mutual = 0

        self.assertEquals(t(1000, some_news, no_mutual, no_dupe,
                          'etag', 'last_modified'), 540.0)
示例#13
0
 def tearDown(self):
     WebSite.drop_collection()
     Article.drop_collection()
示例#14
0
class WebSitesTest(TestCase):
    def setUp(self):

        WebSite.drop_collection()
        Article.drop_collection()

        self.ws1 = WebSite(url='http://test1.com').save()
        self.ws2 = WebSite(url='http://test2.com').save()

    def tearDown(self):
        WebSite.drop_collection()
        Article.drop_collection()

    def test_get_or_create_website(self):

        wt1, created = WebSite.get_or_create_website('http://test1.com')

        self.assertFalse(created)
        self.assertEquals(wt1, self.ws1)

        wt3, created = WebSite.get_or_create_website('http://test3.com')

        self.assertTrue(created)
        self.assertNotEquals(wt3, self.ws1)
        self.assertNotEquals(wt3, self.ws2)

        wt4, created = WebSite.get_or_create_website('http://test3.com')

        self.assertFalse(created)
        self.assertEquals(wt3, wt4)

        wt5, created = WebSite.get_or_create_website('http://test3.com/')

        self.assertTrue(created)
        self.assertNotEquals(wt5, wt4)

    def test_get_from_url(self):

        wt1 = WebSite.get_from_url('http://test1.com/example-article')
        wt2 = WebSite.get_from_url('http://test1.com/example-article2')

        self.assertEquals(wt1, self.ws1)
        self.assertEquals(wt1, self.ws1)
        self.assertEquals(wt1, wt2)

    def test_register_duplicate_not_again(self):

        wt1, created = WebSite.get_or_create_website('http://other.test1.com')

        self.ws1.register_duplicate(wt1)

        self.assertTrue(created)
        self.assertEquals(wt1.duplicate_of, self.ws1)

        wt2, created = WebSite.get_or_create_website('http://other.test1.com')

        self.assertFalse(created)
        self.assertNotEquals(wt2, wt1)
        self.assertEquals(wt2, self.ws1)

        # should fail.
        #self.ws2.register_duplicate(wt1)

        #
        # TODO: finish this test case.
        #

    def test_websites_duplicates(self):
        pass
示例#15
0
# Use the test database not to pollute the production/development one.
RedisStatsCounter.REDIS = TEST_REDIS

TEST_REDIS.flushdb()

connect_mongodb_testsuite()

# Empty the database before starting in case an old test failed to tearDown().
Article.drop_collection()
Read.drop_collection()
User.drop_collection()
Group.drop_collection()
Feed.drop_collection()
Tag.drop_collection()
Folder.drop_collection()
WebSite.drop_collection()
Author.drop_collection()


class ThrottleIntervalTest(TestCase):
    def test_lower_interval_with_etag_or_modified(self):

        t = Feed.throttle_fetch_interval

        some_news = 10
        no_dupe = 0
        no_mutual = 0

        self.assertEquals(
            t(1000, some_news, no_mutual, no_dupe, 'etag', 'last_modified'),
            540.0)