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