def test_sss_source_re_should_not_include_service_not_published(self): fixtures.create_content(self.portal, serveis.servei_domain_none) fixtures.create_content(self.portal, serveis.servei_domain_1) commit() calculator = SessionsSourceServei(self.portal) source_re = calculator._build_filters() self.assertEqual('ga:source=~^$', source_re)
def test_sss_source_re_should_be_empty_if_all_services_not_published_or_urls_empty_or_none( self): fixtures.create_and_publish_content(self.portal, serveis.servei_domain_empty) fixtures.create_and_publish_content(self.portal, serveis.servei_domain_none) fixtures.create_content(self.portal, serveis.servei_domain_1) commit() calculator = SessionsSourceServei(self.portal) source_re = calculator._build_filters() self.assertEqual('ga:source=~^$', source_re)
def test_sss_source_re_should_be_empty_if_all_services_not_published_or_urls_empty_or_none(self): fixtures.create_and_publish_content( self.portal, serveis.servei_domain_empty) fixtures.create_and_publish_content( self.portal, serveis.servei_domain_none) fixtures.create_content( self.portal, serveis.servei_domain_1) commit() calculator = SessionsSourceServei(self.portal) source_re = calculator._build_filters() self.assertEqual('ga:source=~^$', source_re)
def test_indicators_data_should_show_modified_only_if_not_online_category(self): servei = fixtures.create_content( self.portal, fixtures.servei_with_service_id) commit() view = api.content.get_view( 'retrieve_indicadors', servei, self.layer['request']) with patch('genweb.serveistic.data_access.indicadors.' 'IndicadorsDataReporter.' 'list_by_service_id_and_indicators_order', side_effect=(fixtures_retrieve.indicadors,)): query_string = "?count_indicator=5" self.browser.open(view.url() + query_string) self.assertAppearInOrder([ "Indicador 1", "v1.1", "Categoria 1.1", "v1.2", "Categoria 1.2", "3/2/2015", "Dia", "Indicador 2", "v2.1", "Categoria 2.1", "5/2/2015", "Mes", "v2.2", "Categoria 2.2", "v2.3", "Categoria 2.3", ], self.browser.contents) self.assertNotIn("2/2/2015", self.browser.contents) self.assertNotIn("6/2/2015", self.browser.contents) self.assertNotIn("7/2/2015", self.browser.contents)
def test_sss_source_re_should_only_include_services_if_published_and_with_urls( self): fixtures.create_and_publish_content(self.portal, serveis.servei_domain_empty) fixtures.create_and_publish_content(self.portal, serveis.servei_domain_none) fixtures.create_and_publish_content(self.portal, serveis.servei_domain_1) fixtures.create_content(self.portal, serveis.servei_domain_2) fixtures.create_and_publish_content(self.portal, serveis.servei_domain_3) commit() calculator = SessionsSourceServei(self.portal) source_re = calculator._build_filters() self.assertEqual( 'ga:source=~^domain1\\.com$,ga:source=~^domain3\\.com$', source_re)
def test_sss_source_re_should_only_include_services_if_published_and_with_urls(self): fixtures.create_and_publish_content( self.portal, serveis.servei_domain_empty) fixtures.create_and_publish_content( self.portal, serveis.servei_domain_none) fixtures.create_and_publish_content( self.portal, serveis.servei_domain_1) fixtures.create_content( self.portal, serveis.servei_domain_2) fixtures.create_and_publish_content( self.portal, serveis.servei_domain_3) commit() calculator = SessionsSourceServei(self.portal) source_re = calculator._build_filters() self.assertEqual( 'ga:source=~^domain1\\.com$,ga:source=~^domain3\\.com$', source_re)
def test_allindicators_text_should_not_appear_when_no_service_id(self): servei = fixtures.create_content( self.portal, fixtures.servei_without_service_id) commit() view = api.content.get_view( 'retrieve_indicadors', servei, self.layer['request']) self.browser.open(view.url()) self.assertNotIn( "Tots els indicadors", self.browser.contents)
def test_noindicators_text_should_appear_when_no_service_id(self): servei = fixtures.create_content( self.portal, fixtures.servei_without_service_id) commit() view = api.content.get_view( 'retrieve_indicadors', servei, self.layer['request']) self.browser.open(view.url()) self.assertIn( "No hi ha cap indicador enregistrat relacionat amb aquest servei", self.browser.contents)
def test_allindicators_text_should_not_appear_when_count_not_specified(self): servei = fixtures.create_content( self.portal, fixtures.servei_with_service_id) commit() view = api.content.get_view( 'retrieve_indicadors', servei, self.layer['request']) with patch('genweb.serveistic.data_access.indicadors.' 'IndicadorsDataReporter.list_by_service_id_and_indicators_order', side_effect=(fixtures_retrieve.indicadors,)): self.browser.open(view.url()) self.assertNotIn( "Tots els indicadors", self.browser.contents)
def test_indicators_order_should_not_be_applied_when_order_not_defined(self): servei = fixtures.create_content( self.portal, fixtures.servei_with_service_id) commit() view = api.content.get_view( 'retrieve_indicadors', servei, self.layer['request']) with patch('genweb.serveistic.data_access.indicadors.' 'IndicadorsDataReporter.' 'list_by_service_id', side_effect=(fixtures_retrieve.indicadors,)) as list_by_service_id: query_string = "?apply_order=yes&count_indicator=5" self.browser.open(view.url() + query_string) self.assertTrue(list_by_service_id.called)
def test_noindicators_text_should_appear_when_indicadors_none(self): servei = fixtures.create_content( self.portal, fixtures.servei_with_service_id) commit() view = api.content.get_view( 'retrieve_indicadors', servei, self.layer['request']) with patch('genweb.serveistic.data_access.indicadors.' 'IndicadorsDataReporter.' 'list_by_service_id_and_indicators_order', side_effect=(None,)): query_string = "?count_indicator=5" self.browser.open(view.url() + query_string) self.assertIn( "No hi ha cap indicador enregistrat relacionat amb " "aquest servei", self.browser.contents)
def test_indicators_data_should_show_unknown_frequency_if_no_frequency(self): servei = fixtures.create_content( self.portal, fixtures.servei_with_service_id) commit() view = api.content.get_view( 'retrieve_indicadors', servei, self.layer['request']) with patch('genweb.serveistic.utilities.IndicadorsClient.' 'list_indicators', side_effect=(fixtures_retrieve.indicators_dto,)): with patch('genweb.serveistic.utilities.IndicadorsClient.' 'list_categories', side_effect=(fixtures_retrieve.categories_dto,)): query_string = "?count_indicator=5" self.browser.open(view.url() + query_string) self.assertAppearInOrder([ "Indicador 1", "v1.1", "Categoria 1.1", "02/02/2015", "category_freq_unknown", ], self.browser.contents)
def test_retrieve_from_ws(self): servei = fixtures.create_content( self.portal, fixtures.servei_with_product_id) fixtures.create_content( servei['problemes'], fixtures.problema_1) fixtures.create_content( servei['problemes'], fixtures.problema_2) commit() view = api.content.get_view( 'retrieve_problemes', servei, self.layer['request']) # problems not empty, count is present problems = [ Mock( date_creation="25/02/2016", topic="The topic 1", url="problem-1"), Mock( date_creation="26/02/2016", topic="The topic 2", url="problem-2"), ] with patch('genweb.serveistic.data_access.problemes.ProblemesDataReporter.list_by_product_id', side_effect=(problems,)): query_string = "?count=5" self.browser.open(view.url() + query_string) self.assertAppearInOrder([ "25/02/2016", "The topic", "26/02/2016", "The topic 2", ], self.browser.contents) self.assertIn( "Tots els problemes", self.browser.contents) self.assertNotIn( "No hi ha cap problema enregistrat relacionat amb aquest " "servei", self.browser.contents) # problems not empty, count not present problems = [ Mock( date_creation="25/02/2016", topic="The topic 1", url="problem-1"), Mock( date_creation="26/02/2016", topic="The topic 2", url="problem-2"), ] with patch('genweb.serveistic.data_access.problemes.ProblemesDataReporter.list_by_product_id', side_effect=(problems,)): self.browser.open(view.url()) self.assertAppearInOrder([ "25/02/2016", "The topic", "26/02/2016", "The topic 2", ], self.browser.contents) self.assertNotIn( "Tots els problemes", self.browser.contents) self.assertNotIn( "No hi ha cap problema enregistrat relacionat amb aquest " "servei", self.browser.contents) # problems is empty with patch('genweb.serveistic.data_access.problemes.ProblemesDataReporter.list_by_product_id', side_effect=([],)): self.browser.open(view.url()) self.assertIn( "No hi ha cap problema enregistrat relacionat amb aquest " "servei", self.browser.contents) self.assertNotIn( "Tots els problemes", self.browser.contents) # problems is None with patch('genweb.serveistic.data_access.problemes.ProblemesDataReporter.list_by_product_id', side_effect=(None,)): self.browser.open(view.url()) self.assertIn( "No hi ha cap problema enregistrat relacionat amb aquest " "servei", self.browser.contents) self.assertNotIn( "Tots els problemes", self.browser.contents)
def setUpPloneSite(self, portal): super(GenwebServeisticLayerWithData, self).setUpPloneSite(portal) fixtures.create_content(portal, fixtures.servei_mylist) commit()