Ejemplo n.º 1
0
    def test_minimal_bandwidth_file(self):
        """
    Basic sanity check that we can parse a bandwidth file with minimal
    attributes.
    """

        desc = BandwidthFile.create()

        self.assertEqual('1410723598', str(desc))

        self.assertEqual(datetime.datetime(2014, 9, 14, 19, 39, 58),
                         desc.timestamp)
        self.assertEqual('1.0.0', desc.version)

        self.assertEqual(None, desc.software)
        self.assertEqual(None, desc.software_version)

        self.assertEqual(None, desc.earliest_bandwidth)
        self.assertEqual(None, desc.latest_bandwidth)
        self.assertEqual(None, desc.created_at)
        self.assertEqual(None, desc.generated_at)

        self.assertEqual(None, desc.consensus_size)
        self.assertEqual(None, desc.eligible_count)
        self.assertEqual(None, desc.eligible_percent)
        self.assertEqual(None, desc.min_count)
        self.assertEqual(None, desc.min_percent)

        self.assertEqual({}, desc.header)
Ejemplo n.º 2
0
  def test_new_header_attribute(self):
    """
    Include an unrecognized header field.
    """

    desc = BandwidthFile.create(collections.OrderedDict([('version', '1.1.0'), ('new_header', 'neat stuff')]))
    self.assertEqual(EXPECTED_NEW_HEADER_CONTENT, str(desc))
    self.assertEqual('1.1.0', desc.version)
    self.assertEqual({'version': '1.1.0', 'new_header': 'neat stuff'}, desc.header)
Ejemplo n.º 3
0
    def test_bandwidth_stats(self, stdout_mock, get_bandwidth_file_mock):
        get_bandwidth_file_mock().run.return_value = [
            BandwidthFile.create({
                'content': [
                    'bw=1 bw_mean=807445 bw_median=911047 consensus_bandwidth=1190000 node_id=$FDCF49562E65B1CC219410009BD48A9EED387C77',
                    'bw=1 bw_mean=631049 bw_median=622052 consensus_bandwidth=55000 node_id=$BD4172533C3F7271ABCCD9F057E06FD91547C42B',
                ],
            })
        ]

        import bandwidth_stats
        self.assertEqual(EXPECTED_BANDWIDTH_STATS, stdout_mock.getvalue())
Ejemplo n.º 4
0
 def test_from_str(self):
     sig = BandwidthFile.create()
     self.assertEqual(sig, BandwidthFile.from_str(str(sig)))