def test_schema_validation(self): provider = ProviderFactory() provider.credentials_schema = { "$schema": False, } assert_that(provider.validate(), contains_string("schema")) provider.credentials_schema = { "$schema": "A Schema", } assert_that(provider.validate(), none())
def test_requires_common_provider(self): provider_1 = ProviderFactory() provider_2 = ProviderFactory() collector_type = CollectorTypeFactory(provider=provider_1) data_source = DataSourceFactory(provider=provider_2) collector = CollectorFactory(type=collector_type, data_source=data_source) assert_that(collector.validate(), contains_string('provider')) data_source.provider = provider_1 assert_that(collector.validate(), none())
def test_can_list_providers_with_collector_permission(self): provider = ProviderFactory() response = self.client.get('/provider', HTTP_AUTHORIZATION='Bearer correct-token') assert_that(response.status_code, equal_to(200))
def test_get(self): provider = ProviderFactory( credentials_schema={ "$schema": "http://json-schema.org/schema#", "type": "object", "properties": { "password": { "type": "string" }, }, "required": ["password"], "additionalProperties": False, }) response = self.client.get( '/provider/{}'.format(provider.name), HTTP_AUTHORIZATION='Bearer development-oauth-access-token', content_type='application/json') assert_that(response.status_code, equal_to(200)) resp_json = json.loads(response.content) assert_that(resp_json['id'], equal_to(str(provider.id))) assert_that(resp_json['slug'], equal_to(provider.slug)) assert_that(resp_json['name'], equal_to(provider.name)) assert_that(resp_json['credentials_schema'], equal_to(provider.credentials_schema))
def test_list(self): provider_1 = ProviderFactory() provider_2 = ProviderFactory() response = self.client.get( '/provider', HTTP_AUTHORIZATION='Bearer development-oauth-access-token', content_type='application/json') assert_that(response.status_code, equal_to(200)) resp_json = json.loads(response.content) assert_that(resp_json, match_equality(has_entries({"slug": provider_1.slug}))) assert_that(resp_json, match_equality(has_entries({"slug": provider_2.slug})))
def test_schema_validation(self): provider = ProviderFactory() provider.credentials_schema = { "$schema": False, } assert_that(provider.validate(), contains_string("schema")) provider.credentials_schema = { "$schema": "A Schema", } assert_that(provider.validate(), none())
def test_credentials_are_validated_against_provider(self): provider = ProviderFactory( credentials_schema={ "$schema": "http://json-schema.org/schema#", "type": "object", "properties": { "password": { "type": "string" }, }, "required": ["password"], "additionalProperties": False, }) credentials = '{"name": "something"}' data_source = DataSourceFactory(provider=provider, credentials=credentials) assert_that(data_source.credentials, credentials) assert_that(data_source.validate(), not_none()) data_source.credentials = '{"password": "******"}' assert_that(data_source.validate(), none())
def test_get_from_unauthorised_client_fails(self): provider = ProviderFactory() resp = self.client.get('/provider/{}'.format(provider.name)) assert_that(resp.status_code, equal_to(403))
def setUpClass(cls): cls.provider = ProviderFactory() cls.data_source = DataSourceFactory(provider=cls.provider) cls.collector_type = CollectorTypeFactory(provider=cls.provider) cls.data_set = DataSetFactory()
def setUpClass(cls): cls.provider = ProviderFactory()