Exemple #1
0
 def testUsefulnessNoHitsAttribute(self):
     'Test that accessing usefulness gives correct result when hits is missing.'
     sdfile = ScanDigestFile(self.owner, url=self.url, location=self.location)
     sdfile.date = datetime.utcnow() # .now() is used in property.
     expected = 0.0
     actual = sdfile.usefulness
     self.assertEqual(expected, actual)
Exemple #2
0
 def testCreate(self):
     'Test that a ScanDigest object is created when we call create.'
     max = 25
     sdfile = ScanDigestFile(self.owner, url=self.url, location=self.location)
     sdfile.create(max)
     self.assertIsNotNone(sdfile._container)
     self.assertIsInstance(sdfile._container, ScanDigest)
     self.assertEqual(sdfile._container.maxcapacity, max)
Exemple #3
0
 def testUsefulness(self):
     'Test that accessing usefulness gives correct result.  Fails every DST change.'
     sdfile = ScanDigestFile(self.owner, url=self.url, location=self.location)
     now = datetime.now()
     utcnow = datetime.utcnow()
     seconds_diff = utcnow - now
     sdfile.hits = abs(seconds_diff.total_seconds() * 10)
     sdfile.date = utcnow
     actual = sdfile.usefulness
     expected = 10.0
     self.assertAlmostEqual(expected, actual, places=5)
Exemple #4
0
 def testCreateAddSaveLoadGet(self):
     'Test that we can create, add to, save, unload, load, and get from a ScanDigestFile.'
     max = 25
     sdfile = ScanDigestFile(self.owner, url=self.url, location=self.location,
                             siginfo=self.siginfo)
     # Create
     sdfile.create(max)
     self.assertIsNotNone(sdfile._container)
     self.assertIsInstance(sdfile._container, ScanDigest)
     self.assertEqual(sdfile._container.maxcapacity, max)
     url = 'http://www.bluecornchipfanatics.com/bestnachocheese.cgi'
     size = 3452
     uo = UrlObject(url, size, nonce=self.name, hash='ea463b2cd1')
     # Add/Get
     sdfile.add(uo)
     self.assertTrue(sdfile.get(uo))
     # Save
     sdfile.save()
     self.assertTrue(os.path.isfile(sdfile.filename))
     # Unload
     sdfile.unload()
     self.assertFalse(sdfile._container)
     # Load
     loaded_file = sdfile.load()
     self.assertTrue(sdfile._container)
     self.assertEqual(sdfile, loaded_file)
     # Get
     self.assertTrue(sdfile.get(uo))
Exemple #5
0
 def testRepr(self):
     'Test that ScanDigestFile repr makes sense.'
     sdfile = ScanDigestFile(self.owner, url=self.url, location=self.location)
     actual = sdfile.__repr__()
     expected = 'ScanDigestFile(id=None, ScanDigest, %r, %r)' % (self.owner, sdfile.filename)
     self.assertEqual(expected, actual)