def setUp(self): mongo_db = mock.MagicMock() mongo_db.connection = self.cluster.mongo.conn mongo_db.name = 'pminifier' self.m = SimplerMinifier(mongo_db, self.cluster.redis.conn, 'groupkey')
class SimplerMinifierTests(PMinifierIntegrationTest): def setUp(self): mongo_db = mock.MagicMock() mongo_db.connection = self.cluster.mongo.conn mongo_db.name = 'pminifier' self.m = SimplerMinifier(mongo_db, self.cluster.redis.conn, 'groupkey') def test_retrieve_bad_urls(self): self.assertRaises(Minifier.DoesNotExist, self.m.get_string, "AfTea") def test_store_and_retrieve_same_url(self): o_id = self.m.get_id("http://www.youtube.com/") self.assertEqual(o_id, self.m.get_id("http://www.youtube.com/")) def test_counter(self): counter_value = self.m._get_current_counter_value() self.assertTrue(isinstance(counter_value, int)) def test_cache_keys(self): try: self.m._cache_key_names('str', ['string based key']) except: self.fail('_cache_key_names threw an exception') def test_cache_key_unicode(self): try: self.m._cache_key_names('str', [u'nīcē ūnīcōde']) except: self.fail('_cache_key_names died on unicode') def test_cache_key_equality(self): keys_first = self.m._cache_key_names('str', ['string based key']) keys_second = self.m._cache_key_names('str', ['string based key']) self.assertIsInstance(keys_first, dict) self.assertEqual(set(keys_first.keys()), set(keys_second.keys())) keys_third = self.m._cache_key_names('str', ['another thing']) self.assertNotEqual(set(keys_first.keys()), set(keys_third.keys())) keys_fourth = self.m._cache_key_names('id', ['another thing']) self.assertNotEqual(set(keys_third.keys()), set(keys_fourth.keys())) def test_store_and_retrieve_urls(self): urls_oid = [] urls = ["http://google.com", "http://www.google.com", "https://mail.google.com/mail/u/0/#drafts", "https://www.google.com/#hl=en&output=search&sclient=psy-ab&q=parsely&qscrl=1&oq=parsely&aq=f&aqi=g-s4&aql=&gs_l=hp.3..0i10l4.2183l11396l0l11570l18l18l0l0l0l0l172l1787l10j8l18l0.frgbld.&pbx=1&bav=on.2,or.r_gc.r_pw.r_qf.,cf.osb&fp=3a4c3f9900aaf4a9&biw=1920&bih=982", "http://174.143.148.90/", "174.143.148.90", "potato", "potato"] for url in urls: url = unicode(url) o_id = self.m.get_id(url) self.assertEqual(url, self.m.get_string(o_id)) # Check integrity of IDs urls_oid.append((o_id, url)) for check_id, check_url in urls_oid: self.assertEqual(check_url, self.m.get_string(check_id))
class SimplerMinifierTests(PMinifierIntegrationTest): def setUp(self): mongo_db = mock.MagicMock() mongo_db.connection = self.cluster.mongo.conn mongo_db.name = 'pminifier' self.m = SimplerMinifier(mongo_db, self.cluster.redis.conn, 'groupkey') def test_retrieve_bad_urls(self): self.assertRaises(Minifier.DoesNotExist, self.m.get_string, "AfTea") def test_store_and_retrieve_same_url(self): o_id = self.m.get_id("http://www.youtube.com/") self.assertEqual(o_id, self.m.get_id("http://www.youtube.com/")) def test_counter(self): counter_value = self.m._get_current_counter_value() self.assertTrue(isinstance(counter_value, int)) def test_cache_keys(self): try: self.m._cache_key_names('str', ['string based key']) except: self.fail('_cache_key_names threw an exception') def test_cache_key_unicode(self): try: self.m._cache_key_names('str', [u'nīcē ūnīcōde']) except: self.fail('_cache_key_names died on unicode') def test_cache_key_equality(self): keys_first = self.m._cache_key_names('str', ['string based key']) keys_second = self.m._cache_key_names('str', ['string based key']) self.assertIsInstance(keys_first, dict) self.assertEqual(set(keys_first.keys()), set(keys_second.keys())) keys_third = self.m._cache_key_names('str', ['another thing']) self.assertNotEqual(set(keys_first.keys()), set(keys_third.keys())) keys_fourth = self.m._cache_key_names('id', ['another thing']) self.assertNotEqual(set(keys_third.keys()), set(keys_fourth.keys())) def test_store_and_retrieve_urls(self): urls_oid = [] urls = [ "http://google.com", "http://www.google.com", "https://mail.google.com/mail/u/0/#drafts", "https://www.google.com/#hl=en&output=search&sclient=psy-ab&q=parsely&qscrl=1&oq=parsely&aq=f&aqi=g-s4&aql=&gs_l=hp.3..0i10l4.2183l11396l0l11570l18l18l0l0l0l0l172l1787l10j8l18l0.frgbld.&pbx=1&bav=on.2,or.r_gc.r_pw.r_qf.,cf.osb&fp=3a4c3f9900aaf4a9&biw=1920&bih=982", "http://174.143.148.90/", "174.143.148.90", "potato", "potato" ] for url in urls: url = unicode(url) o_id = self.m.get_id(url) self.assertEqual(url, self.m.get_string(o_id)) # Check integrity of IDs urls_oid.append((o_id, url)) for check_id, check_url in urls_oid: self.assertEqual(check_url, self.m.get_string(check_id))