Ejemplo n.º 1
0
    def test_get_overview_stats(self, mock_urlopen):
        """
        Asserts that overview returns proper stats.

        Args:
        :param mock_urlopen: A patched urllib object
        """
        mock_response = MockURLResponse(self.test_overview_stats)
        mock_urlopen.return_value = mock_response
        stats = self.stats.get_overview_stats()
        self.assertTrue(stats)
Ejemplo n.º 2
0
    def test_vhots(self, mock_urlopen):
        """
        Asserts that get_vhosts returns all vhosts data.

        Args:
        :param mock_urlopen: A patched urllib object
        """
        mock_response = MockURLResponse(json.dumps(self.test_vhosts))
        mock_urlopen.return_value = mock_response
        vhosts = self.stats.get_vhosts()
        self.assertEqual(len(vhosts), len(self.test_vhosts))
Ejemplo n.º 3
0
    def test_get_info_url_bad_json(self, mock_urlopen):
        """
        Asserts that get_info returns None on bad json.

        Args:
        :param mock_urlopen: A patched urllib object
        """
        url = "http://test"
        mock_response = MockURLResponse('{"test":test}')
        mock_urlopen.return_value = mock_response
        result = self.stats.get_info(url)
        self.assertIsNone(result)
Ejemplo n.º 4
0
    def test_get_queue_stats(self, mock_urlopen):
        """
        Asserts that queue returns proper stats.

        Args:
        :param mock_urlopen: A patched urllib object
        """
        self.test_stats['name'] = 'test_queue'
        mock_response = MockURLResponse(self.test_stats)
        mock_urlopen.return_value = mock_response
        stats = self.stats.get_queue_stats('test_queue')
        self.assertTrue(stats)
Ejemplo n.º 5
0
    def test_vhots_names(self, mock_urlopen):
        """
        Asserts that get_vhosts returns all vhosts data.

        Args:
        :param mock_urlopen: A patched urllib object
        """
        mock_response = MockURLResponse(json.dumps(self.test_vhosts))
        mock_urlopen.return_value = mock_response
        vhost_names = self.stats.get_vhost_names()
        self.assertIn('%2F', vhost_names)
        self.assertIn('test_vhosta', vhost_names)
        self.assertIn('test_vhostb', vhost_names)
Ejemplo n.º 6
0
    def test_get_info(self, mock_urlopen):
        """
        Asserts that get_info returns the proper data from url.

        Args:
        :param mock_urlopen: A patched urllib object
        """
        url = "http://test"
        test_value = ['test', 'json']
        mock_response = MockURLResponse(json.dumps(test_value))
        mock_urlopen.return_value = mock_response
        result = self.stats.get_info(url)
        self.assertIsNotNone(result)
        self.assertEqual(test_value, result)
Ejemplo n.º 7
0
    def test_get_all_exchange_stats(self, mock_urlopen):
        """
        Asserts that exchange returns proper stats.

        Args:
        :param mock_urlopen: A patched urllib object
        """
        self.stats.get_exchanges = Mock()
        self.stats.get_exchanges.return_value = [
            dict(name='e1'), dict(name='e2'),
            dict(name='e3')
        ]
        self.test_stats['name'] = 'test_exchange'
        mock_response = MockURLResponse(self.test_stats)
        mock_urlopen.return_value = mock_response
        stats = self.stats.get_exchange_stats()
        self.assertTrue(stats)