def test_populate_vocabularies(self): cmd = VocabulariesPopulateCommand() cmd.run(self.filename) service = get_resource_service('vocabularies') for item in self.json_data: data = service.find_one(_id=item['_id'], req=None) self.assertEqual(data['_id'], item['_id']) self.assertListEqual(data['items'], item['items'])
def setup_ntb_vocabulary(context): with context.app.app_context(): # prepopulate vocabularies voc_file = os.path.join( os.path.abspath(os.path.dirname(os.path.dirname(ntb.__file__))), 'data', 'vocabularies.json') VocabulariesPopulateCommand().run(voc_file)
def test_check_similar(self): f = get_resource_service('filter_conditions') filter_condition1 = { 'field': 'urgency', 'operator': 'in', 'value': '2' } filter_condition2 = { 'field': 'urgency', 'operator': 'in', 'value': '3' } filter_condition3 = { 'field': 'urgency', 'operator': 'in', 'value': '1' } filter_condition4 = { 'field': 'urgency', 'operator': 'in', 'value': '5' } filter_condition5 = { 'field': 'urgency', 'operator': 'nin', 'value': '5' } filter_condition6 = { 'field': 'headline', 'operator': 'like', 'value': 'tor' } with self.app.app_context(): cmd = VocabulariesPopulateCommand() filename = os.path.join( os.path.abspath( os.path.dirname( "apps/prepopulate/data_init/vocabularies.json")), "vocabularies.json") cmd.run(filename) self.assertTrue(len(f.check_similar(filter_condition1)) == 2) self.assertTrue(len(f.check_similar(filter_condition2)) == 1) self.assertTrue(len(f.check_similar(filter_condition3)) == 0) self.assertTrue(len(f.check_similar(filter_condition4)) == 3) self.assertTrue(len(f.check_similar(filter_condition5)) == 1) self.assertTrue(len(f.check_similar(filter_condition6)) == 1)
def test_check_similar(self): f = get_resource_service('filter_conditions') filter_condition1 = {'field': 'urgency', 'operator': 'in', 'value': '2'} filter_condition2 = {'field': 'urgency', 'operator': 'in', 'value': '3'} filter_condition3 = {'field': 'urgency', 'operator': 'in', 'value': '1'} filter_condition4 = {'field': 'urgency', 'operator': 'in', 'value': '5'} filter_condition5 = {'field': 'urgency', 'operator': 'nin', 'value': '5'} filter_condition6 = {'field': 'headline', 'operator': 'like', 'value': 'tor'} with self.app.app_context(): cmd = VocabulariesPopulateCommand() filename = os.path.join(os.path.abspath( os.path.dirname("apps/prepopulate/data_init/vocabularies.json")), "vocabularies.json") cmd.run(filename) self.assertTrue(len(f.check_similar(filter_condition1)) == 2) self.assertTrue(len(f.check_similar(filter_condition2)) == 1) self.assertTrue(len(f.check_similar(filter_condition3)) == 0) self.assertTrue(len(f.check_similar(filter_condition4)) == 3) self.assertTrue(len(f.check_similar(filter_condition5)) == 1) self.assertTrue(len(f.check_similar(filter_condition6)) == 1)
def test_get_subscribers_by_filter_condition(self): filter_condition1 = {'field': 'urgency', 'operator': 'in', 'value': '2'} filter_condition2 = {'field': 'urgency', 'operator': 'in', 'value': '1'} filter_condition3 = {'field': 'headline', 'operator': 'like', 'value': 'tor'} filter_condition4 = {'field': 'urgency', 'operator': 'nin', 'value': '3'} with self.app.app_context(): cmd = VocabulariesPopulateCommand() filename = os.path.join(os.path.abspath( os.path.dirname("apps/prepopulate/data_init/vocabularies.json")), "vocabularies.json") cmd.run(filename) r1 = self.s._get_subscribers_by_filter_condition(filter_condition1) r2 = self.s._get_subscribers_by_filter_condition(filter_condition2) r3 = self.s._get_subscribers_by_filter_condition(filter_condition3) r4 = self.s._get_subscribers_by_filter_condition(filter_condition4) self.assertTrue(len(r1[0]['selected_subscribers']) == 1) self.assertTrue(len(r2[0]['selected_subscribers']) == 0) self.assertTrue(len(r3[0]['selected_subscribers']) == 2) self.assertTrue(len(r4[0]['selected_subscribers']) == 1)
def setup_before_scenario(context, scenario, config, app_factory): if scenario.status != 'skipped' and 'notesting' in scenario.tags: config['SUPERDESK_TESTING'] = False # use liveblog auth for tests config['CORE_APPS'] = [app for app in CORE_APPS if app != 'apps.auth.db'] config['CORE_APPS'].append('liveblog.auth') # TODO: Temp fix for DATE_FORMAT. This will be removed when superdesk will allow to specify custom test settings. config['DATE_FORMAT'] = DATE_FORMAT tests.setup(context, config, app_factory, bool(config)) context.headers = [ ('Content-Type', 'application/json'), ('Origin', 'localhost') ] if 'amazons3' in scenario.tags and not context.app.config.get('AMAZON_CONTAINER_NAME', None): scenario.mark_skipped() if 'alchemy' in scenario.tags and not context.app.config.get('KEYWORDS_KEY_API'): scenario.mark_skipped() if 'clean_snapshots' in scenario.tags: tests.use_snapshot.cache.clear() setup_search_provider(context.app) if scenario.status != 'skipped' and 'auth' in scenario.tags: setup_auth_user(context) if scenario.status != 'skipped' and 'consumer_auth' in scenario.tags: setup_auth_consumer(context, test_consumer) if scenario.status != 'skipped' and 'provider' in scenario.tags: setup_providers(context) if scenario.status != 'skipped' and 'vocabulary' in scenario.tags: with context.app.app_context(): cmd = VocabulariesPopulateCommand() filename = os.path.join(os.path.abspath(os.path.dirname("features/steps/fixtures/")), "vocabularies.json") cmd.run(filename) if scenario.status != 'skipped' and 'content_type' in scenario.tags: with context.app.app_context(): cmd = VocabulariesPopulateCommand() filename = os.path.join(os.path.abspath(os.path.dirname("features/steps/fixtures/")), "content_types.json") cmd.run(filename) if scenario.status != 'skipped' and 'notification' in scenario.tags: tests.setup_notification(context)
def setup_before_scenario(context, scenario, config, app_factory): if scenario.status != 'skipped' and 'notesting' in scenario.tags: config['SUPERDESK_TESTING'] = False tests.setup(context, config, app_factory, bool(config)) context.headers = [('Content-Type', 'application/json'), ('Origin', 'localhost')] if 'dbauth' in scenario.tags and LDAP_SERVER: scenario.mark_skipped() if 'ldapauth' in scenario.tags and not LDAP_SERVER: scenario.mark_skipped() if 'alchemy' in scenario.tags and not context.app.config.get( 'KEYWORDS_KEY_API'): scenario.mark_skipped() if 'clean_snapshots' in scenario.tags: tests.use_snapshot.cache.clear() setup_search_provider(context.app) if scenario.status != 'skipped' and 'auth' in scenario.tags: setup_auth_user(context) if scenario.status != 'skipped' and 'provider' in scenario.tags: setup_providers(context) if scenario.status != 'skipped' and 'vocabulary' in scenario.tags: with context.app.app_context(): cmd = VocabulariesPopulateCommand() filename = os.path.join( os.path.abspath(os.path.dirname("features/steps/fixtures/")), "vocabularies.json") cmd.run(filename) if scenario.status != 'skipped' and 'content_type' in scenario.tags: with context.app.app_context(): cmd = VocabulariesPopulateCommand() filename = os.path.join( os.path.abspath(os.path.dirname("features/steps/fixtures/")), "content_types.json") cmd.run(filename) if scenario.status != 'skipped' and 'notification' in scenario.tags: tests.setup_notification(context)
def test_get_subscribers_by_filter_condition(self): filter_condition1 = { 'field': 'urgency', 'operator': 'in', 'value': '2' } filter_condition2 = { 'field': 'urgency', 'operator': 'in', 'value': '1' } filter_condition3 = { 'field': 'headline', 'operator': 'like', 'value': 'tor' } filter_condition4 = { 'field': 'urgency', 'operator': 'nin', 'value': '3' } with self.app.app_context(): cmd = VocabulariesPopulateCommand() filename = os.path.join( os.path.abspath( os.path.dirname( "apps/prepopulate/data_init/vocabularies.json")), "vocabularies.json") cmd.run(filename) r1 = self.s._get_subscribers_by_filter_condition(filter_condition1) r2 = self.s._get_subscribers_by_filter_condition(filter_condition2) r3 = self.s._get_subscribers_by_filter_condition(filter_condition3) r4 = self.s._get_subscribers_by_filter_condition(filter_condition4) self.assertTrue(len(r1[0]['selected_subscribers']) == 1) self.assertTrue(len(r2[0]['selected_subscribers']) == 0) self.assertTrue(len(r3[0]['selected_subscribers']) == 2) self.assertTrue(len(r4[0]['selected_subscribers']) == 1)
def setUp(self): super().setUp() # we need to prepopulate vocabularies to get qcodes voc_file = os.path.join( os.path.abspath(os.path.dirname(os.path.dirname(ntb.__file__))), 'data', 'vocabularies.json') VocabulariesPopulateCommand().run(voc_file) # settings are needed in order to get into account NITF_MAPPING for key in dir(settings): if key.isupper(): setattr(config, key, getattr(settings, key)) self._run_parse()
def setUp(self): super().setUp() # we need to prepopulate vocabularies to get qcodes voc_file = os.path.join(os.path.abspath(os.path.dirname(os.path.dirname(ntb.__file__))), 'data', 'vocabularies.json') VocabulariesPopulateCommand().run(voc_file) # settings are needed in order to get into account NITF_MAPPING for key in dir(settings): if key.isupper(): setattr(config, key, getattr(settings, key)) dirname = os.path.dirname(os.path.realpath(__file__)) fixture = os.path.normpath(os.path.join(dirname, '../fixtures', self.filename)) provider = {'name': 'Test'} with open(fixture, 'rb') as f: self.xml = f.read() self.xml_root = etree.fromstring(self.xml) self.item = self.parser.parse(self.xml_root, provider)
def setUp(self): super().setUp() with self.app.app_context(): # prepopulate vocabularies voc_file = os.path.join( os.path.abspath(os.path.dirname(os.path.dirname( ntb.__file__))), 'data', 'vocabularies.json') VocabulariesPopulateCommand().run(voc_file) # by default events resource is not available init_events_app(self.app) # NTBEventsApiFeedingService does 4 request during 1 update, # to mock returning of different results (requests.get) self._side_effect is used self.feeds = [] for i in range(4): dirname = os.path.dirname(os.path.realpath(__file__)) fixture = os.path.normpath( os.path.join(dirname, '../fixtures', 'ntb_events_api', '{}.xml'.format(i))) with open(fixture, 'rb') as f: self.feeds.append(f.read())
def setup_before_scenario(context, scenario, config, app_factory): if scenario.status != 'skipped' and 'notesting' in scenario.tags: config['SUPERDESK_TESTING'] = False tests.setup(context, config, app_factory, bool(config)) context.headers = [ ('Content-Type', 'application/json'), ('Origin', 'localhost') ] if 'dbauth' in scenario.tags and LDAP_SERVER: scenario.mark_skipped() if 'ldapauth' in scenario.tags and not LDAP_SERVER: scenario.mark_skipped() if 'alchemy' in scenario.tags and not context.app.config.get('KEYWORDS_KEY_API'): scenario.mark_skipped() if 'clean_snapshots' in scenario.tags: tests.use_snapshot.cache.clear() setup_search_provider(context.app) if scenario.status != 'skipped' and 'auth' in scenario.tags: setup_auth_user(context) if scenario.status != 'skipped' and 'provider' in scenario.tags: setup_providers(context) if scenario.status != 'skipped' and 'vocabulary' in scenario.tags: with context.app.app_context(): cmd = VocabulariesPopulateCommand() filename = os.path.join(os.path.abspath(os.path.dirname("features/steps/fixtures/")), "vocabularies.json") cmd.run(filename) if scenario.status != 'skipped' and 'content_type' in scenario.tags: with context.app.app_context(): cmd = VocabulariesPopulateCommand() filename = os.path.join(os.path.abspath(os.path.dirname("features/steps/fixtures/")), "content_types.json") cmd.run(filename) if scenario.status != 'skipped' and 'notification' in scenario.tags: tests.setup_notification(context)