Пример #1
0
 def test_config_parsing_full(self):
     """ Read the test config and compare values. """
     test_utils.generate_test_config_file()
     result = gnippy_config.get_config(test_utils.test_config_path)
     self.assertEqual(result['Credentials']['username'], test_utils.test_username)
     self.assertEqual(result['Credentials']['password'], test_utils.test_password)
     self.assertEqual(result['PowerTrack']['url'], test_utils.test_powertrack_url)
Пример #2
0
 def test_resolve_file_arg(self):
     """ Run the "resolve" method with just a filename and check if all info is loaded. """
     test_utils.generate_test_config_file()
     conf = gnippy_config.resolve({"config_file_path": test_utils.test_config_path})
     self.assertEqual(conf['auth'][0], test_utils.test_username)
     self.assertEqual(conf['auth'][1], test_utils.test_password)
     self.assertEqual(conf['url'], test_utils.test_powertrack_url)
Пример #3
0
 def test_resolve_file_arg(self):
     """ Run the "resolve" method with just a filename and check if all info is loaded. """
     test_utils.generate_test_config_file()
     conf = gnippy_config.resolve(
         {"config_file_path": test_utils.test_config_path})
     self.assertEqual(conf['auth'][0], test_utils.test_username)
     self.assertEqual(conf['auth'][1], test_utils.test_password)
     self.assertEqual(conf['url'], test_utils.test_powertrack_url)
Пример #4
0
 def test_config_parsing_full(self):
     """ Read the test config and compare values. """
     test_utils.generate_test_config_file()
     result = gnippy_config.get_config(test_utils.test_config_path)
     self.assertEqual(result['Credentials']['username'],
                      test_utils.test_username)
     self.assertEqual(result['Credentials']['password'],
                      test_utils.test_password)
     self.assertEqual(result['PowerTrack']['url'],
                      test_utils.test_powertrack_url)
Пример #5
0
    def test_constructor_all_args(self):
        """ Initialize PowerTrackClient with all args. """
        test_utils.generate_test_config_file()
        expected_auth = ("hello", "world")
        expected_url = "http://wat.com/testing.json"
        client = PowerTrackClient(_dummy_callback, auth=expected_auth, url=expected_url, config_file_path=config_file)

        self.assertEqual(expected_auth[0], client.auth[0])
        self.assertEqual(expected_auth[1], client.auth[1])
        self.assertEqual(expected_url, client.url)
Пример #6
0
    def test_constructor_only_file(self):
        """ Initialize PowerTrackClient with only a config file path. """
        test_utils.generate_test_config_file()
        client = PowerTrackClient(_dummy_callback, config_file_path=config_file)
        expected_auth = (test_utils.test_username, test_utils.test_password)
        expected_url = test_utils.test_powertrack_url

        self.assertEqual(expected_auth[0], client.auth[0])
        self.assertEqual(expected_auth[1], client.auth[1])
        self.assertEqual(expected_url, client.url)
Пример #7
0
    def test_connected_status_after_exception_is_false(self):
        """ When an exception is thrown the client is no longer connected. """
        test_utils.generate_test_config_file()

        client = PowerTrackClient(_dummy_callback,
                                  config_file_path=config_file)
        client.connect()

        sleep(2)

        self.assertFalse(client.connected())
Пример #8
0
    def test_backfill_value_greater_than_five_raises_exception(self):
        """When passing a backfill value that isn't an integer raises an
        exception"""

        backfill_minutes = 12

        test_utils.generate_test_config_file()

        client = PowerTrackClient(_dummy_callback, config_file_path=config_file)

        self.assertRaises(AssertionError, client.connect, backfill_minutes)
Пример #9
0
    def test_constructor_only_file(self):
        """ Initialize PowerTrackClient with only a config file path. """
        test_utils.generate_test_config_file()
        client = PowerTrackClient(_dummy_callback,
                                  config_file_path=config_file)
        expected_auth = (test_utils.test_username, test_utils.test_password)
        expected_url = test_utils.test_powertrack_url

        self.assertEqual(expected_auth[0], client.auth[0])
        self.assertEqual(expected_auth[1], client.auth[1])
        self.assertEqual(expected_url, client.url)
Пример #10
0
    def test_connected_status_after_exception_is_false(self):
        """ When an exception is thrown the client is no longer connected. """
        test_utils.generate_test_config_file()

        client = PowerTrackClient(_dummy_callback,
                                  config_file_path=config_file)
        client.connect()

        sleep(2)

        self.assertFalse(client.connected())
Пример #11
0
    def test_backfill_value_greater_than_five_raises_exception(self):
        """When passing a backfill value that isn't an integer raises an
        exception"""

        backfill_minutes = 12

        test_utils.generate_test_config_file()

        client = PowerTrackClient(_dummy_callback,
                                  config_file_path=config_file)

        self.assertRaises(AssertionError, client.connect, backfill_minutes)
Пример #12
0
    def test_constructor_all_args(self):
        """ Initialize PowerTrackClient with all args. """
        test_utils.generate_test_config_file()
        expected_auth = ("hello", "world")
        expected_url = "http://wat.com/testing.json"
        client = PowerTrackClient(_dummy_callback,
                                  auth=expected_auth,
                                  url=expected_url,
                                  config_file_path=config_file)

        self.assertEqual(expected_auth[0], client.auth[0])
        self.assertEqual(expected_auth[1], client.auth[1])
        self.assertEqual(expected_url, client.url)
Пример #13
0
    def test_connected_status_true_when_running(self):
        """ Once the client connect method is called the client reports as connected. """
        test_utils.generate_test_config_file()

        client = PowerTrackClient(_dummy_callback,
                                  config_file_path=config_file)

        client.connect()

        self.assertTrue(client.connected())

        client.disconnect()

        self.assertFalse(client.connected())
Пример #14
0
    def test_connected_status_true_when_running(self):
        """ Once the client connect method is called the client reports as connected. """
        test_utils.generate_test_config_file()

        client = PowerTrackClient(_dummy_callback,
                                  config_file_path=config_file)

        client.connect()

        self.assertTrue(client.connected())

        client.disconnect()

        self.assertFalse(client.connected())
Пример #15
0
    def test_exception_with_callback(self):
        """ When exception_callback is provided, worker uses it to communicate errors. """
        test_utils.generate_test_config_file()

        exception_callback = mock.Mock()

        client = PowerTrackClient(_dummy_callback, exception_callback,
                                  config_file_path=config_file)
        client.connect()
        self.assertTrue(exception_callback.called)
        actual_exinfo = exception_callback.call_args[0][0]
        actual_ex = actual_exinfo[1]
        self.assertIsInstance(actual_ex, Exception)
        self.assertEqual(actual_ex.message, "This is a test exception")
Пример #16
0
    def test_exception_with_callback(self):
        """ When exception_callback is provided, worker uses it to communicate errors. """
        test_utils.generate_test_config_file()

        exception_callback = mock.Mock()

        client = PowerTrackClient(_dummy_callback,
                                  exception_callback,
                                  config_file_path=config_file)
        client.connect()
        self.assertTrue(exception_callback.called)
        actual_exinfo = exception_callback.call_args[0][0]
        actual_ex = actual_exinfo[1]
        self.assertIsInstance(actual_ex, Exception)
        self.assertEqual(actual_ex.message, "This is a test exception")
Пример #17
0
    def test_backfill_value_appended_to_url(self, mocked_requests_get):
        """When passing a backfill value it is appended to the url call to
        GNIP"""

        backfill_minutes = 3

        expected_powertrack_url = "{0}?backfillMinutes={1}".format(
            test_utils.test_powertrack_url, backfill_minutes)

        test_utils.generate_test_config_file()

        client = PowerTrackClient(_dummy_callback, config_file_path=config_file)

        client.connect(backfill_minutes=backfill_minutes)
        client.disconnect()

        mocked_requests_get.assert_called_with(
            expected_powertrack_url,
            auth=(test_utils.test_username, test_utils.test_password),
            stream=True
        )
Пример #18
0
    def test_backfill_value_appended_to_url(self, mocked_requests_get):
        """When passing a backfill value it is appended to the url call to
        GNIP"""

        backfill_minutes = 3

        expected_powertrack_url = "{0}?backfillMinutes={1}".format(
            test_utils.test_powertrack_url, backfill_minutes)

        test_utils.generate_test_config_file()

        client = PowerTrackClient(_dummy_callback,
                                  config_file_path=config_file)

        client.connect(backfill_minutes=backfill_minutes)
        client.disconnect()

        mocked_requests_get.assert_called_with(expected_powertrack_url,
                                               auth=(test_utils.test_username,
                                                     test_utils.test_password),
                                               stream=True)
Пример #19
0
 def setUp(self):
     test_utils.generate_test_config_file()
Пример #20
0
 def setUp(self):
     test_utils.generate_test_config_file()