def test_required_when_other_parameters_are_present(self):
     for parameters in [
         {importer_constants.KEY_MAX_SPEED: '1024'}, {importer_constants.KEY_MAX_DOWNLOADS: 2},
         {importer_constants.KEY_PROXY_PASS: '******',
          importer_constants.KEY_PROXY_USER: '******',
          importer_constants.KEY_PROXY_HOST: 'http://test.com'},
         {importer_constants.KEY_PROXY_HOST: 'http://test.com', importer_constants.KEY_PROXY_PORT: '3037'},
         {importer_constants.KEY_PROXY_HOST: 'http://test.com'},
         {importer_constants.KEY_UNITS_REMOVE_MISSING: True},
         {importer_constants.KEY_SSL_CA_CERT: 'cert'},
         {importer_constants.KEY_SSL_CLIENT_CERT: 'cert'},
         {importer_constants.KEY_SSL_CLIENT_CERT: 'cert', importer_constants.KEY_SSL_CLIENT_KEY: 'key'},
         {importer_constants.KEY_VALIDATE: True}]:
             # Each of the above configurations should cause the validator to complain about the feed_url
             # missing
             config = importer_mocks.get_basic_config(**parameters)
             status, error_message = configuration.validate(config)
             self.assertTrue(status is False)
             self.assertEqual(
                 error_message,
                 'The configuration parameter <%(feed)s> is required when any of the following other '
                 'parameters are defined: %(max_speed)s, %(num_threads)s, %(proxy_pass)s, %(proxy_port)s, '
                 '%(proxy_host)s, %(proxy_user)s, %(remove_missing_units)s, %(ssl_ca_cert)s, '
                 '%(ssl_client_cert)s, %(ssl_client_key)s, %(validate_units)s.' % {
                     'feed': importer_constants.KEY_FEED, 'max_speed': importer_constants.KEY_MAX_SPEED,
                     'num_threads': importer_constants.KEY_MAX_DOWNLOADS,
                     'proxy_pass': importer_constants.KEY_PROXY_PASS,
                     'proxy_port': importer_constants.KEY_PROXY_PORT,
                     'proxy_host': importer_constants.KEY_PROXY_HOST,
                     'proxy_user': importer_constants.KEY_PROXY_USER,
                     'remove_missing_units': importer_constants.KEY_UNITS_REMOVE_MISSING,
                     'ssl_ca_cert': importer_constants.KEY_SSL_CA_CERT,
                     'ssl_client_cert': importer_constants.KEY_SSL_CLIENT_CERT,
                     'ssl_client_key': importer_constants.KEY_SSL_CLIENT_KEY,
                     'validate_units': importer_constants.KEY_VALIDATE})
 def test_zero(self):
     config = importer_mocks.get_basic_config(**{constants.CONFIG_NUM_THREADS: 0,
                                                 constants.CONFIG_FEED_URL: 'http://test.com'})
     status, error_message = configuration.validate(config)
     self.assertTrue(status is False)
     self.assertEqual(error_message, 'The configuration parameter <num_threads> must be set to a positive '
                                     'integer, but is currently set to <0>.')
 def test_invalid_config(self):
     config = importer_mocks.get_basic_config(**{importer_constants.KEY_MAX_SPEED: -1.0,
                                                 importer_constants.KEY_FEED: 'http://test.com'})
     status, error_message = configuration.validate(config)
     self.assertTrue(status is False)
     self.assertEqual(error_message, 'The configuration parameter <max_speed> must be set to a positive '
                                     'numerical value, but is currently set to <-1.0>.')
 def test_validate(self):
     parameters = {constants.CONFIG_PROXY_PORT: 8088, constants.CONFIG_PROXY_URL: 'http://proxy.com',
                   constants.CONFIG_FEED_URL: 'http://test.com'}
     config = importer_mocks.get_basic_config(**parameters)
     status, error_message = configuration.validate(config)
     self.assertTrue(status is True)
     self.assertEqual(error_message, None)
 def test_client_cert_is_non_string(self):
     config = importer_mocks.get_basic_config(**{importer_constants.KEY_SSL_CLIENT_CERT: 8,
                                                 importer_constants.KEY_FEED: 'http://test.com'})
     status, error_message = configuration.validate(config)
     self.assertTrue(status is False)
     self.assertEqual(error_message, "The configuration parameter <ssl_client_cert> should be a string, "
                                     "but it was <type 'int'>.")
 def test_invalid_config(self):
     config = importer_mocks.get_basic_config(**{constants.CONFIG_VALIDATE_DOWNLOADS: 1,
                                                 constants.CONFIG_FEED_URL: 'http://feed.com'})
     status, error_message = configuration.validate(config)
     self.assertTrue(status is False)
     self.assertEqual(error_message, 'The configuration parameter <validate_downloads> must be set to a '
                                     'boolean value, but is currently set to <1>.')
 def test_validate(self):
     config = importer_mocks.get_basic_config(
         **{constants.CONFIG_FEED_URL: "http://test.com/feed", constants.CONFIG_MAX_SPEED: 56.6,
            constants.CONFIG_NUM_THREADS: 3})
     status, error_message = configuration.validate(config)
     self.assertTrue(status is True)
     self.assertEqual(error_message, None)
 def test_client_key_requires_client_cert(self):
     config = importer_mocks.get_basic_config(**{importer_constants.KEY_SSL_CLIENT_KEY: 'Client Key!',
                                                 importer_constants.KEY_FEED: 'http://test.com'})
     status, error_message = configuration.validate(config)
     self.assertTrue(status is False)
     self.assertEqual(error_message, 'The configuration parameter <ssl_client_key> requires the '
                                     '<ssl_client_cert> parameter to also be set.')
 def test_invalid_config(self):
     config = importer_mocks.get_basic_config(**{constants.CONFIG_REMOVE_MISSING_UNITS: 'trizue',
                                                 constants.CONFIG_FEED_URL: 'http://feed.com'})
     status, error_message = configuration.validate(config)
     self.assertTrue(status is False)
     self.assertEqual(error_message, 'The configuration parameter <remove_missing_units> must be set to a '
                                     'boolean value, but is currently set to <trizue>.')
 def test_url_is_non_string(self):
     config = importer_mocks.get_basic_config(**{constants.CONFIG_PROXY_URL: 7,
                                                 constants.CONFIG_FEED_URL: 'http://test.com'})
     status, error_message = configuration.validate(config)
     self.assertTrue(status is False)
     self.assertEqual(error_message, "The configuration parameter <proxy_url> should be a string, "
                                     "but it was <type 'int'>.")
 def test_validate(self):
     config = importer_mocks.get_basic_config(
         **{importer_constants.KEY_FEED: "http://test.com/feed", importer_constants.KEY_MAX_SPEED: 56.6,
            importer_constants.KEY_MAX_DOWNLOADS: 3})
     status, error_message = configuration.validate(config)
     self.assertTrue(status is True)
     self.assertEqual(error_message, None)
 def test_validate_str(self):
     parameters = {importer_constants.KEY_PROXY_PORT: '3128', importer_constants.KEY_PROXY_HOST: 'http://test.com',
                   importer_constants.KEY_FEED: 'http://test.com'}
     config = importer_mocks.get_basic_config(**parameters)
     status, error_message = configuration.validate(config)
     self.assertTrue(status is True)
     self.assertEqual(error_message, None)
 def test_validate(self):
     parameters = {constants.CONFIG_PROXY_PASSWORD: '******', constants.CONFIG_PROXY_USER: '******',
                   constants.CONFIG_PROXY_URL: 'http://fake.com/',
                   constants.CONFIG_FEED_URL: 'http://test.com'}
     config = importer_mocks.get_basic_config(**parameters)
     status, error_message = configuration.validate(config)
     self.assertTrue(status is True)
     self.assertEqual(error_message, None)
 def test_client_key_is_non_string(self):
     params = {constants.CONFIG_SSL_CLIENT_KEY: 9, constants.CONFIG_SSL_CLIENT_CERT: 'cert!',
               constants.CONFIG_FEED_URL: 'http://test.com'}
     config = importer_mocks.get_basic_config(**params)
     status, error_message = configuration.validate(config)
     self.assertTrue(status is False)
     self.assertEqual(error_message, "The configuration parameter <ssl_client_key> should be a string, "
                                     "but it was <type 'int'>.")
 def test_invalid_config(self):
     config = importer_mocks.get_basic_config(**{constants.CONFIG_FEED_URL: "http://test.com/feed",
                                                 constants.CONFIG_MAX_SPEED: "A Thousand",
                                                 constants.CONFIG_NUM_THREADS: 7})
     status, error_message = configuration.validate(config)
     self.assertTrue(status is False)
     self.assertEqual(error_message, 'The configuration parameter <max_speed> must be set to a positive '
                                     'numerical value, but is currently set to <A Thousand>.')
 def test_username_requires_password(self):
     parameters = {constants.CONFIG_PROXY_USER: '******', constants.CONFIG_FEED_URL: 'http://fake.com',
                   constants.CONFIG_PROXY_URL: 'http://fake.com'}
     config = importer_mocks.get_basic_config(**parameters)
     status, error_message = configuration.validate(config)
     self.assertTrue(status is False)
     self.assertEqual(error_message, 'The configuration parameter <proxy_user> requires the '
                                     '<proxy_password> parameter to also be set.')
 def test_zero(self):
     parameters = {importer_constants.KEY_PROXY_PORT: 0, importer_constants.KEY_PROXY_HOST: 'http://test.com',
                   importer_constants.KEY_FEED: 'http://test.com'}
     config = importer_mocks.get_basic_config(**parameters)
     status, error_message = configuration.validate(config)
     self.assertTrue(status is False)
     self.assertEqual(error_message, 'The configuration parameter <proxy_port> must be set to a positive '
                                     'integer, but is currently set to <0>.')
 def test_password_is_non_string(self):
     parameters = {importer_constants.KEY_PROXY_PASS: 7, importer_constants.KEY_PROXY_USER: "******",
                   importer_constants.KEY_FEED: 'http://test.com'}
     config = importer_mocks.get_basic_config(**parameters)
     status, error_message = configuration.validate(config)
     self.assertTrue(status is False)
     self.assertEqual(error_message, "The configuration parameter <proxy_password> should be a string, "
                                     "but it was <type 'int'>.")
 def test_float(self):
     parameters = {constants.CONFIG_PROXY_PORT: math.pi, constants.CONFIG_PROXY_URL: 'http://test.com',
                   constants.CONFIG_FEED_URL: 'http://test.com'}
     config = importer_mocks.get_basic_config(**parameters)
     status, error_message = configuration.validate(config)
     self.assertTrue(status is False)
     self.assertEqual(error_message, 'The configuration parameter <proxy_port> must be set to a positive '
                                     'integer, but is currently set to <%s>.'%math.pi)
 def test_validate(self):
     params = {importer_constants.KEY_PROXY_PASS: '******', importer_constants.KEY_PROXY_USER: '******',
               importer_constants.KEY_PROXY_HOST: 'http://fake.com/',
               importer_constants.KEY_FEED: 'http://test.com'}
     config = importer_mocks.get_basic_config(**params)
     status, error_message = configuration.validate(config)
     self.assertTrue(status is True)
     self.assertEqual(error_message, None)
 def test_invalid_config(self):
     config = importer_mocks.get_basic_config(**{importer_constants.KEY_VALIDATE: 1,
                                                 importer_constants.KEY_FEED: 'http://feed.com'})
     status, error_message = configuration.validate(config)
     self.assertTrue(status is False)
     expected_message = ('The configuration parameter <%(validate)s> may only be set to a '
                         'boolean value, but is currently set to <1>.')
     expected_message = expected_message % {'validate': importer_constants.KEY_VALIDATE}
     self.assertEqual(error_message, expected_message)
 def test_username_is_non_string(self):
     parameters = {constants.CONFIG_PROXY_PASSWORD: '******', constants.CONFIG_PROXY_USER: 185,
                   constants.CONFIG_PROXY_URL: 'http://test.com',
                   constants.CONFIG_FEED_URL: 'http://test2.com'}
     config = importer_mocks.get_basic_config(**parameters)
     status, error_message = configuration.validate(config)
     self.assertTrue(status is False)
     self.assertEqual(error_message, "The configuration parameter <proxy_user> should be a string, "
                                     "but it was <type 'int'>.")
 def test_zero(self):
     config = importer_mocks.get_basic_config(**{importer_constants.KEY_MAX_DOWNLOADS: 0,
                                                 importer_constants.KEY_FEED: 'http://test.com'})
     status, error_message = configuration.validate(config)
     self.assertTrue(status is False)
     expected_message = ('The configuration parameter <%(num_threads)s> must be set to a positive '
                         'integer, but is currently set to <0>.')
     expected_message = expected_message % {'num_threads': importer_constants.KEY_MAX_DOWNLOADS}
     self.assertEqual(error_message, expected_message)
 def test_invalid_config(self):
     config = importer_mocks.get_basic_config(**{importer_constants.KEY_UNITS_REMOVE_MISSING: 'trizue',
                                                 importer_constants.KEY_FEED: 'http://feed.com'})
     status, error_message = configuration.validate(config)
     self.assertTrue(status is False)
     expected_message = ('The configuration parameter <%(remove_missing)s> may only be set to a '
                         'boolean value, but is currently set to <trizue>.')
     expected_message = expected_message % {'remove_missing': importer_constants.KEY_UNITS_REMOVE_MISSING}
     self.assertEqual(error_message, expected_message)
 def test_url_is_non_string(self):
     config = importer_mocks.get_basic_config(**{importer_constants.KEY_PROXY_HOST: 7,
                                                 importer_constants.KEY_FEED: 'http://test.com'})
     status, error_message = configuration.validate(config)
     self.assertTrue(status is False)
     expected_message = ("The configuration parameter <%(proxy_host)s> should be a string, but it was "
                         "<type 'int'>.")
     expected_message = expected_message % {'proxy_host': importer_constants.KEY_PROXY_HOST}
     self.assertEqual(error_message, expected_message)
 def test_validate(self):
     params = {
         importer_constants.KEY_SSL_CA_CERT: 'CA Certificate!',
         importer_constants.KEY_SSL_CLIENT_CERT: 'Client Certificate!',
         importer_constants.KEY_SSL_CLIENT_KEY: 'Client Key!',
         importer_constants.KEY_FEED: 'http://test.com'}
     config = importer_mocks.get_basic_config(**params)
     status, error_message = configuration.validate(config)
     self.assertTrue(status is True)
     self.assertEqual(error_message, None)
 def test_username_requires_password(self):
     parameters = {importer_constants.KEY_PROXY_USER: '******', importer_constants.KEY_FEED: 'http://fake.com',
                   importer_constants.KEY_PROXY_HOST: 'http://fake.com'}
     config = importer_mocks.get_basic_config(**parameters)
     status, error_message = configuration.validate(config)
     self.assertTrue(status is False)
     expected_message = ('The configuration parameter <%(proxy_user)s> requires the '
                         '<%(proxy_pass)s> parameter to also be set.')
     expected_message = expected_message % {'proxy_user': importer_constants.KEY_PROXY_USER,
                                            'proxy_pass': importer_constants.KEY_PROXY_PASS}
     self.assertEqual(error_message, expected_message)
 def test_username_is_non_string(self):
     parameters = {importer_constants.KEY_PROXY_PASS: '******', importer_constants.KEY_PROXY_USER: 185,
                   importer_constants.KEY_PROXY_HOST: 'http://test.com',
                   importer_constants.KEY_FEED: 'http://test2.com'}
     config = importer_mocks.get_basic_config(**parameters)
     status, error_message = configuration.validate(config)
     self.assertTrue(status is False)
     expected_message = ("The configuration parameter <%(proxy_user)s> should be a string, but it was "
                         "<type 'int'>.")
     expected_message = expected_message % {'proxy_user': importer_constants.KEY_PROXY_USER}
     self.assertEqual(error_message, expected_message)
 def test_required_when_other_parameters_are_present(self):
     for parameters in [
         {constants.CONFIG_PROXY_PASSWORD: '******',
          constants.CONFIG_PROXY_USER: '******', constants.CONFIG_FEED_URL: 'http://fake.com'},
         {constants.CONFIG_PROXY_PORT: '3037', constants.CONFIG_FEED_URL: 'http://fake.com'}]:
             # Each of the above configurations should cause the validator to complain about the proxy_url
             # missing
             config = importer_mocks.get_basic_config(**parameters)
             status, error_message = configuration.validate(config)
             self.assertTrue(status is False)
             self.assertEqual(
                 error_message,
                 'The configuration parameter <proxy_url> is required when any of the following other '
                 'parameters are defined: proxy_password, proxy_port, proxy_user')
 def test_required_when_other_parameters_are_present(self):
     for parameters in [
         {importer_constants.KEY_PROXY_PASS: '******',
          importer_constants.KEY_PROXY_USER: '******', importer_constants.KEY_FEED: 'http://fake.com'},
         {importer_constants.KEY_PROXY_PORT: '3037', importer_constants.KEY_FEED: 'http://fake.com'}]:
             # Each of the above configurations should cause the validator to complain about the proxy_url
             # missing
             config = importer_mocks.get_basic_config(**parameters)
             status, error_message = configuration.validate(config)
             self.assertTrue(status is False)
             expected_message = (
                 'The configuration parameter <%(proxy_host)s> is required when any of the following '
                 'other parameters are defined: %(proxy_pass)s, %(proxy_port)s, %(proxy_user)s.')
             expected_message = expected_message % {'proxy_pass': importer_constants.KEY_PROXY_PASS,
                                                    'proxy_user': importer_constants.KEY_PROXY_USER,
                                                    'proxy_port': importer_constants.KEY_PROXY_PORT,
                                                    'proxy_host': importer_constants.KEY_PROXY_HOST}
             self.assertEqual(error_message, expected_message)