def test_categories_replacement_logic(self): category = self.allegation_category.category other_category = AllegationCategoryFactory() sub_category = AllegationCategoryFactory(category=category) OfficerAllegationFactory(cat=other_category) OfficerAllegationFactory(cat=sub_category) self.filter_complaint_type() self.link(category).click() self.until_ajax_complete() self.element_by_classname_and_text('filter-name', category).should.be.ok self.link(sub_category.allegation_name).click() self.until_ajax_complete() self.element_by_classname_and_text( 'filter-name', sub_category.allegation_name).should.be.ok self.element_by_classname_and_text('filter-name', category).should.be.false self.link(other_category.category).click() self.until_ajax_complete() self.element_by_classname_and_text( 'filter-name', other_category.category).should.be.ok self.element_by_classname_and_text( 'filter-name', sub_category.allegation_name).should.be.false
def test_suggest_allegation_category_on_duty(self): AllegationCategoryFactory(on_duty=True) AllegationCategoryFactory(on_duty=False) ret1 = SuggestAllegationCategoryOnDuty.query('On D') ret1['Category On Duty'][0]['tag_value']['value'].should.be.equal(True) ret2 = SuggestAllegationCategoryOnDuty.query('Off D') ret2['Category On Duty'][0]['tag_value']['value'].should.be.equal(False)
def test_lookup_by_multiple_categories_officerallegation(self): allegation = AllegationFactory() cat1 = AllegationCategoryFactory() cat2 = AllegationCategoryFactory() OfficerAllegationFactory(allegation=allegation, cat=cat1) OfficerAllegationFactory(allegation=allegation, cat=cat2) response = self.client.get( '/lookup/{query}'.format(query=allegation.crid)) response.status_code.should.equals(HTTP_301_MOVED_PERMANENTLY) response.url.should.contain('/s/{query}'.format(query=allegation.crid))
def setUp(self): self.category = AllegationCategoryFactory() self.allegation = AllegationFactory() DocumentFactory(documentcloud_id=None, requested=False, allegation=self.allegation) OfficerAllegationFactory(cat=self.category, allegation=self.allegation)
def test_detect_suggest_type_main_complaint_category(self): AllegationCategoryFactory(category='Bonding category') rebuild_index() data = self.get_suggestion('Bonding') data.should.contain('Category')
def test_circle_color_of_involved_officers(self): crid = '1234' category = AllegationCategoryFactory() allegation = AllegationFactory(crid=crid) allegations_count_color_map = { 'circle-0': 21, 'circle-1': 11, 'circle-2': 4, 'circle-3': 2, 'circle-4': 1 } officers = {} for circle_class, allegations_count in \ allegations_count_color_map.items(): officer = OfficerFactory(allegations_count=allegations_count) officers[circle_class] = officer OfficerAllegationFactory(allegation=allegation, officer=officer, cat=category) self.visit_complaint_page(allegation.crid, category.id) self.until(lambda: self.should_not_see_text(allegation.crid)) for circle_class, allegations_count in \ allegations_count_color_map.items(): selector = '.officer-card.officer-{id} .{circle_class}'.format( id=officers[circle_class].id, circle_class=circle_class ) self.find_all(selector).should.have.length_of(1)
def setUp(self): super(OutcomeAnalyticsTestCase, self).setUp() self.allegation_category = AllegationCategoryFactory() for filter_type in FILTERS: for final_finding in FILTERS[filter_type]: OfficerAllegationFactory(final_finding=final_finding, cat=self.allegation_category)
def test_redirect_allegation_crid_only_session(self): allegation = AllegationFactory() category1 = AllegationCategoryFactory() category2 = AllegationCategoryFactory() OfficerAllegationFactory(allegation=allegation, cat=category1) OfficerAllegationFactory(allegation=allegation, cat=category2) filters = { 'allegation__crid': [{ 'value': allegation.crid, 'category': 'allegation__crid' }] } urls = self.redirect_allegation_id_only_session(filters) allegation_redirect_url = '/s/{crid}'.format(crid=allegation.crid) urls.should.be.equal([allegation_redirect_url])
def test_suggest_allegation_category(self): allegation_category = AllegationCategoryFactory(category='Execessive Force') self.rebuild_index() # TODO: Not sure why exce not working here SuggestAllegationCategoryCategory.query('for')['Category'][0]['suggest_value']\ .should.be.equal(allegation_category.category) SuggestAllegationCategoryCategory.query('not in suggest')['Category'].should.be.equal([])
def test_allegation_with_bad_category(self): cat = AllegationCategoryFactory() officer_allegation = OfficerAllegationFactory(cat=cat) self.visit_complaint_page(officer_allegation.allegation.crid, 0) self.until(lambda: self.find('.message-title')) self.should_see_text('Invalid page!') self.should_see_text('The complaint with this category is not recorded in our database. Please use search box ' 'for new search session.')
def test_allegation_category_on_duty(self): expected_allegations = [ OfficerAllegationFactory(cat=AllegationCategoryFactory( on_duty=True))] OfficerAllegationFactory() query_string = 'cat__on_duty=true' expected_ids = [allegation.id for allegation in expected_allegations] self.check_built_query(query_string, expected_ids)
def test_redirect_mobile_complaint_page_to_data_tool(self): category = AllegationCategoryFactory() officer_allegation = OfficerAllegationFactory(cat=category) crid = officer_allegation.allegation.crid cat_id = category.id self.visit_complaint_page(crid, cat_id) self.assert_current_url_is_data_tool_page() self.assert_have_filter_tags('Allegation ID', crid) self.assert_have_filter_tags('Allegation Type', category.category)
def test_get_summary(self): AllegationCategoryFactory() response = self.client.get('/api/officer-allegations/summary/') data = self.json(response) data.should.contain("summary") isinstance(data['summary'], list).should.be.true data['summary'].should.have.length_of(1) data['summary'][0]['name'].should.equal( self.officer_allegation.cat.category)
def test_click_on_category_only_show_allegation_belong_to_it(self): other_category = AllegationCategoryFactory() OfficerAllegationFactory(cat=other_category) self.filter_complaint_type() self.check_number_officer(2) self.until(lambda: self.link(self.allegation_category.category). is_displayed()) self.link(self.allegation_category.category).click() self.check_number_officer(1)
def test_lookup_by_allegation_crid_with_one_officerallegation(self): allegation = AllegationFactory(crid='12345') category = AllegationCategoryFactory(pk=123456, category='category name') OfficerAllegationFactory(allegation=allegation, cat=category) expected_url = '/complaint/12345/category-name/x8G40LjV' response = self.client.get( '/lookup/{query}'.format(query=allegation.crid)) response.status_code.should.equals(HTTP_301_MOVED_PERMANENTLY) response.url.should.contain(expected_url)
def test_toggle_complaint_page(self): category = AllegationCategoryFactory() allegation = AllegationFactory() OfficerAllegationFactory(cat=category, allegation=allegation) self.visit_complaint_page(allegation.crid, category.id) self.until(lambda: self.find('.number-of-allegations-section')).click() self.until(lambda: self.find('.toggle-page.content').text.should.contain(category.category)) self.find_all('.officer-allegation-detail').should.have.length_of(0) self.find('.toggle-container').click() self.element_exist('.officer-allegation-detail.pad')
def test_complaint_page_with_category(self): crid = '12345' category_id = 123456 category_name = 'category name' expected_url = '/complaint/12345/category-name/x8G40LjV' allegation = AllegationFactory(crid=crid) category = AllegationCategoryFactory(pk=category_id, category=category_name) officer_allegation = OfficerAllegationFactory(allegation=allegation, cat=category) MobileUrlBuilder().complaint_page(officer_allegation).should.be.equal( expected_url)
def setUp(self): super(AllegationFilterTestCase, self).setUp() self.allegation_category = AllegationCategoryFactory() for _filter in FILTERS: for final_finding in FILTERS[_filter]: # Make sure it doesn't break the disciplined test OfficerAllegationFactory(final_finding=final_finding, cat=self.allegation_category, final_outcome_class='disciplined') rebuild_index() self.visit_home() self.hide_chat_box()
def setUp(self): officer = OfficerFactory(id=10, officer_first='first', officer_last='last') self.officer_url = '/officer/first-last/10' self.officer_suggestion = self.build_officer_suggestion(officer) allegation = AllegationFactory(crid='12345') category = AllegationCategoryFactory(pk=123456, category='category name') OfficerAllegationFactory(allegation=allegation, cat=category) self.allegation_url = '/complaint/12345/category-name/x8G40LjV' self.allegation_suggestion = self.build_allegation_suggestion( allegation)
def test_suggest_allegation_category_cat(self): allegation_category = AllegationCategoryFactory( allegation_name='Twisted Extremities (Wrist/Arm/Leg)', cat_id='S123' ) self.rebuild_index() ret1 = SuggestAllegationCategoryCat.query('123') ret2 = SuggestAllegationCategoryCat.query('some thing wrong') ret1['Category ID'][0]['suggest_value'].should.be.equal(allegation_category.cat_id) ret1['Allegation type'][0]['suggest_value'].should.be.equal('Twisted Extremities (Wrist/Arm/Leg)') ret2['Category ID'].should.be.equal([]) ret2['Allegation type'].should.be.equal([])
def test_should_redirect_to_data_tool_page(self): previous_session_count = Session.objects.count() category = AllegationCategoryFactory() officer_allegation = OfficerAllegationFactory(cat=category) crid = officer_allegation.allegation.crid cat_hash = MobileUrlHashUtil().encode(category.id) response = self.client.get(reverse('allegation:complaint-page', kwargs={'crid': crid, 'category_slug': 'slug', 'cat_hash': cat_hash})) response.status_code.should.be.equal(HTTP_301_MOVED_PERMANENTLY) response.url.should.contain('/data') Session.objects.count().should.be(previous_session_count + 1) last_session = Session.objects.last() last_session.query['filters'].should.contain('cat') last_session.query['filters'].should.contain('allegation__crid')
def test_allegation_with_full_information(self): view_document_text = 'View' officer_gender = 'X' officer_gender_display = 'X' complaint_witness_gender = 'F' complaint_witness_race = 'Black' complaint_witness_age = 40 complaint_witness_text = 'Female, Black, Age 40' address1 = 4748 address2 = 'N Kimball Ave' addresss = '{add1} {add2}'.format(add1=address1, add2=address2) category = AllegationCategoryFactory() officer = OfficerFactory(gender=officer_gender) current_rank = 'SERGEANT OF POLICE' investigator = InvestigatorFactory(current_rank=current_rank) allegation = AllegationFactory( investigator=investigator, add1=address1, add2=address2, city='Chicago, IL', location='15') DocumentFactory(documentcloud_id=123, allegation=allegation) OfficerAllegationFactory(cat=category, officer=officer, allegation=allegation) ComplainingWitnessFactory( crid=allegation.crid, gender=complaint_witness_gender, allegation=allegation, race=complaint_witness_race, age=complaint_witness_age) self.visit_complaint_page(allegation.crid, category.id) self.until(lambda: self.find('.crid-number')) self.until(lambda: self.find('.allegation-category').text.should.be.equal(category.category)) self.find('.allegation-name').text.should.be.equal(category.allegation_name) self.should_see_text(officer.display_name, '.against-section') self.should_see_text(officer_gender_display, '.against-section') self.should_see_text(complaint_witness_text, '.complaining-witness-list') self.should_see_text(investigator.name, '.investigator .name') self.should_see_text(investigator.current_rank, '.investigator .rank') self.should_see_text(allegation.beat.name, '.location-detail') self.should_see_text(view_document_text, '.document-card') location_detail = self.find('.location-detail').text location_detail.should.contain(addresss) location_detail.should.contain(allegation.city) location_detail.should.contain(allegation.location)
def test_browse_session_admin(self): self.login_user() self.visit("/admin/models/") link = self.link("Sessions") link.should.be.ok session = SessionFactory() link.click() self.should_see_texts([ session.hash_id, "Fresh", session.query['title'] ]) shared_session = SessionFactory(share_from=session) self.browser.refresh() self.should_see_texts([ shared_session.hash_id, "Shared", shared_session.query['title'] ]) category = AllegationCategoryFactory() SessionFactory(query={ 'filters': { 'cat__category': { 'value': [category.category] } } }) self.browser.refresh() self.should_see_texts([ 'Chicago Police Database', category.category, ]) self.find("#searchbar").send_keys("{query}\n".format(query=session.query['title'])) self.should_see_text(session.query['title']) self.should_not_see_text(shared_session.query['title']) self.fill_in("#searchbar", "{query}\n".format(query=session.hash_id)) self.should_see_text(session.query['title']) self.should_not_see_text(shared_session.query['title'])
def test_redirect_allegation_crid_only_session_has_only_one_officer_allegation_with_category( self): crid = '12345' category_id = 123456 category_name = 'category name' expected_url = '/complaint/12345/category-name/x8G40LjV' allegation = AllegationFactory(crid=crid) category = AllegationCategoryFactory(pk=category_id, category=category_name) OfficerAllegationFactory(allegation=allegation, cat=category) filters = { 'allegation__crid': [{ 'value': allegation.crid, 'category': 'allegation__crid' }] } urls = self.redirect_allegation_id_only_session(filters) urls.should.be.equal([expected_url])
def test_all_subcategories_should_be_selected(self): category = self.allegation_category.category allegation_category = AllegationCategoryFactory(category=category) OfficerAllegationFactory(cat=allegation_category) # First, we click a category, we should see the arrow beside the category self.filter_complaint_type() with self.browser_no_wait(): self.element_exist('.row .arrow-container').should.equal(False) self.until( lambda: self.link(self.allegation_category.category).click()) # TODO: We should have another test to check which main category this arrow belong to? self.element_exist('.row .arrow-container').should.equal(True) # And it should have a an arrow on the category self.until( lambda: self.number_of_active_subcategories().should.equal(2)) self.until(lambda: self.should_see_text(self.allegation_category. allegation_name)) self.link(self.allegation_category.allegation_name).click() self.until( lambda: self.number_of_active_subcategories().should.equal(1))
class DataToolCategoriesTabTestCase(BaseLiveTestCase): def setUp(self): self.allegation_category = AllegationCategoryFactory() self.officer_allegation = OfficerAllegationFactory( cat=self.allegation_category, final_finding='NS') def tearDown(self): super(DataToolCategoriesTabTestCase, self).tearDown() self.allegation_category.delete() if self.officer_allegation.officer: self.officer_allegation.officer.delete() else: self.officer_allegation.delete() # Helper methods def filter_complaint_type(self): self.visit_home() self.link("Categories").click() self.until_ajax_complete() def check_number_officer(self, num): self.until(lambda: self.number_of_officers().should.equal(num)) def number_of_active_subcategories(self): active_subcategories = self.find_all( '.child-rows .category-name.active') return len(active_subcategories) def number_of_officers(self): officers = self.find_all('.officer') return len(officers) # Tests def test_click_on_category_only_show_allegation_belong_to_it(self): other_category = AllegationCategoryFactory() OfficerAllegationFactory(cat=other_category) self.filter_complaint_type() self.check_number_officer(2) self.until( lambda: self.link(self.allegation_category.category).is_displayed()) self.link(self.allegation_category.category).click() self.check_number_officer(1) def test_click_on_officer_will_show_compliant(self): self.filter_complaint_type() self.check_number_officer(1) self.browser.refresh() self.find('.checkmark').click() self.until(lambda: self.element_exist('.complaint-list')) self.find('.complaint-row > .row').click() self.element_exist('.complaint_detail').should.equal(True) def test_all_subcategories_should_be_selected(self): category = self.allegation_category.category allegation_category = AllegationCategoryFactory(category=category) OfficerAllegationFactory(cat=allegation_category) # First, we click a category, we should see the arrow beside the category self.filter_complaint_type() with self.browser_no_wait(): self.element_exist('.row .arrow-container').should.equal(False) self.until( lambda: self.link(self.allegation_category.category).click()) # TODO: We should have another test to check which main category this arrow belong to? self.element_exist('.row .arrow-container').should.equal(True) # And it should have a an arrow on the category self.until( lambda: self.number_of_active_subcategories().should.equal(2)) self.until( lambda: self.should_see_text(self.allegation_category.allegation_name)) self.link(self.allegation_category.allegation_name).click() self.until( lambda: self.number_of_active_subcategories().should.equal(1)) def test_categories_replacement_logic(self): category = self.allegation_category.category other_category = AllegationCategoryFactory() sub_category = AllegationCategoryFactory(category=category) OfficerAllegationFactory(cat=other_category) OfficerAllegationFactory(cat=sub_category) self.filter_complaint_type() self.link(category).click() self.until_ajax_complete() self.element_by_classname_and_text('filter-name', category).should.be.ok self.link(sub_category.allegation_name).click() self.until_ajax_complete() self.element_by_classname_and_text('filter-name', sub_category.allegation_name).should.be.ok self.element_by_classname_and_text('filter-name', category).should.be.false self.link(other_category.category).click() self.until_ajax_complete() self.element_by_classname_and_text('filter-name', other_category.category).should.be.ok self.element_by_classname_and_text('filter-name', sub_category.allegation_name).should.be.false
class DataToolCategoriesTabTestCase(BaseLiveTestCase): def setUp(self): self.allegation_category = AllegationCategoryFactory() self.officer_allegation = OfficerAllegationFactory( cat=self.allegation_category, final_finding='NS') def tearDown(self): super(DataToolCategoriesTabTestCase, self).tearDown() self.allegation_category.delete() if self.officer_allegation.officer: self.officer_allegation.officer.delete() else: self.officer_allegation.delete() # Helper methods def filter_complaint_type(self): self.visit_home() self.link("Categories").click() self.until_ajax_complete() def check_number_officer(self, num): self.until(lambda: self.number_of_officers().should.equal(num)) def number_of_active_subcategories(self): active_subcategories = self.find_all( '.child-rows .category-name.active') return len(active_subcategories) def number_of_officers(self): officers = self.find_all('.officer') return len(officers) # Tests def test_click_on_category_only_show_allegation_belong_to_it(self): other_category = AllegationCategoryFactory() OfficerAllegationFactory(cat=other_category) self.filter_complaint_type() self.check_number_officer(2) self.until(lambda: self.link(self.allegation_category.category). is_displayed()) self.link(self.allegation_category.category).click() self.check_number_officer(1) def test_click_on_officer_will_show_compliant(self): self.filter_complaint_type() self.check_number_officer(1) self.browser.refresh() self.find('.checkmark').click() self.until(lambda: self.element_exist('.complaint-list')) self.find('.complaint-row > .row').click() self.element_exist('.complaint_detail').should.equal(True) def test_all_subcategories_should_be_selected(self): category = self.allegation_category.category allegation_category = AllegationCategoryFactory(category=category) OfficerAllegationFactory(cat=allegation_category) # First, we click a category, we should see the arrow beside the category self.filter_complaint_type() with self.browser_no_wait(): self.element_exist('.row .arrow-container').should.equal(False) self.until( lambda: self.link(self.allegation_category.category).click()) # TODO: We should have another test to check which main category this arrow belong to? self.element_exist('.row .arrow-container').should.equal(True) # And it should have a an arrow on the category self.until( lambda: self.number_of_active_subcategories().should.equal(2)) self.until(lambda: self.should_see_text(self.allegation_category. allegation_name)) self.link(self.allegation_category.allegation_name).click() self.until( lambda: self.number_of_active_subcategories().should.equal(1)) def test_categories_replacement_logic(self): category = self.allegation_category.category other_category = AllegationCategoryFactory() sub_category = AllegationCategoryFactory(category=category) OfficerAllegationFactory(cat=other_category) OfficerAllegationFactory(cat=sub_category) self.filter_complaint_type() self.link(category).click() self.until_ajax_complete() self.element_by_classname_and_text('filter-name', category).should.be.ok self.link(sub_category.allegation_name).click() self.until_ajax_complete() self.element_by_classname_and_text( 'filter-name', sub_category.allegation_name).should.be.ok self.element_by_classname_and_text('filter-name', category).should.be.false self.link(other_category.category).click() self.until_ajax_complete() self.element_by_classname_and_text( 'filter-name', other_category.category).should.be.ok self.element_by_classname_and_text( 'filter-name', sub_category.allegation_name).should.be.false
class HomePageTestCase(AutocompleteTestHelperMixin, BaseLiveTestCase): def setUp(self): self.allegation_category = AllegationCategoryFactory() self.officer_allegation = OfficerAllegationFactory( cat=self.allegation_category, final_finding='NS') def tearDown(self): super(HomePageTestCase, self).tearDown() self.allegation_category.delete() if self.officer_allegation.officer: self.officer_allegation.officer.delete() else: self.officer_allegation.delete() def test_start_new_session_on_click_logo(self): Session.objects.all().count().should.equal(0) self.visit_home(fresh=True) self.link("Categories").click() self.find(".category-name-wrapper a").click() self.until_ajax_complete() Session.objects.all().count().should.equal(1) url = self.browser.current_url self.find("#logo_link img").click() self.until(lambda: self.browser.current_url != url) Session.objects.all().count().should.equal(2) session = Session.objects.all()[1] self.browser.current_url.should.contain(session.hash_id) def test_see_tabs(self): self.visit_home() links = self.find_all('.chart-row .nav a') link_texts = [x.text for x in links] link_texts.should.contain('Outcomes') link_texts.should.contain('Categories') link_texts.should.contain('Complainants') link_texts.should.contain('Accused') def test_close_disclaimer(self): self.visit_home() self.link('About the data').click() self.until(lambda: self.button('I UNDERSTAND').click()) self.until(lambda: self.should_not_see_text('I UNDERSTAND')) def test_see_session_query_on_reload(self): self.visit_home() officer = self.officer_allegation.officer rebuild_index() self.until( lambda: self.fill_in('.ui-autocomplete-input', officer.officer_first)) self.until_ajax_complete() self.until(lambda: self.find(".autocomplete-officer").is_displayed()) self.find(".autocomplete-officer").click() self.should_see_text(officer.officer_first) self.should_see_text(officer.officer_last) self.browser.refresh() self.until(self.ajax_complete) self.until(lambda: self.should_see_text(officer.officer_first)) self.should_see_text(officer.officer_last) def test_complaint_detail_without_investigator(self): self.officer_allegation.investigator = None self.officer_allegation.save() self.visit_home() self.link('Categories').click() self.find('.category-name').click() self.find('.complaint-row .cursor').click() officers_divs = self.find_all('.officers > div') len(officers_divs).should.equal(1) officers_divs[0].has_class('col-md-10') def click_sunburst_legend(self, text): self.element_by_tagname_and_text('td', text).click() self.sleep(0.75) self.until( lambda: self.element_by_classname_and_text('filter-name', text) .should.be.ok) def test_sunburst(self): us = 'Unsustained' ns = 'Not Sustained' self.visit_home() self.click_active_tab("Outcomes") with self.browser_no_wait(): self.element_by_classname_and_text('filter-name', us)\ .shouldnt.be.ok self.element_by_classname_and_text('filter-name', ns)\ .shouldnt.be.ok self.click_sunburst_legend(us) with self.browser_no_wait(): self.element_by_classname_and_text('filter-name', ns)\ .shouldnt.be.ok sunburst_legend_root_text = self.find('#sunburst-legend .root').text url = self.browser.current_url with self.open_new_browser(): self.visit(url) self.until_ajax_complete() self.sleep(0.75) # sunburst zoom time with self.browser_no_wait(): # same state with above self.find('#sunburst-legend .root')\ .text.should.equal(sunburst_legend_root_text) self.click_sunburst_legend(ns) with self.browser_no_wait(): self.element_by_classname_and_text( 'filter-name', us).shouldnt.be.ok self.click_sunburst_legend(us) with self.browser_no_wait(): self.element_by_classname_and_text( 'filter-name', ns).shouldnt.be.ok self.find(".tag .remove").click() with self.browser_no_wait(): self.element_by_tagname_and_text('td', ns).shouldnt.be.ok def test_sunburst_remove_tag(self): us = 'Unsustained' ns = 'Not Sustained' self.officer_allegation = OfficerAllegationFactory( cat=self.allegation_category, final_outcome='300') self.visit_home() self.click_active_tab("Outcomes") self.until(lambda: self.should_see_text('Officers (2)')) self.click_sunburst_legend(us) self.click_sunburst_legend(ns) self.until(lambda: self.element_by_classname_and_text('filter-name', ns)) self.find(".tag .remove").click() self.until(lambda: self.element_by_classname_and_text('filter-name', us)) self.should_see_text('Officers (1)') def test_replace_old_filter_in_same_category(self): officer_allegation = OfficerAllegationFactory() rebuild_index() self.visit_home() self.search_officer(officer_allegation.officer) self.should_see_text(officer_allegation.officer.display_name) self.search_officer(self.officer_allegation.officer) self.should_see_text(self.officer_allegation.officer.display_name) self.should_not_see_text(officer_allegation.officer.display_name) @retry_random_fail def test_pin_tag(self): officer_allegation = OfficerAllegationFactory() another = OfficerAllegationFactory() rebuild_index() self.visit_home() self.search_officer(officer_allegation.officer) self.should_see_text(officer_allegation.officer.display_name) self.find('.tag > .pin').click() self.until( lambda: self.find('.tag').get_attribute('class').should.contain('pinned')) self.search_officer(self.officer_allegation.officer) self.should_see_text(self.officer_allegation.officer.display_name) self.should_see_text(officer_allegation.officer.display_name) self.search_officer(another.officer) self.should_see_text(another.officer.display_name) self.should_see_text(officer_allegation.officer.display_name) self.should_not_see_text(self.officer_allegation.officer.display_name) def test_unpin_tag(self): officer_allegation = OfficerAllegationFactory() another = OfficerAllegationFactory() rebuild_index() self.visit_home() self.search_officer(officer_allegation.officer) self.should_see_text(officer_allegation.officer.display_name) self.find('.tag > .pin').click() self.search_officer(self.officer_allegation.officer) self.should_see_text(self.officer_allegation.officer.display_name) self.should_see_text(officer_allegation.officer.display_name) element = self.find('.pinned') element.find('.pin').click() self.until( lambda: element.get_attribute('class').shouldnt.contain('pinned')) self.search_officer(another.officer) self.should_see_text(another.officer.display_name) self.should_not_see_text(officer_allegation.officer.display_name) self.should_not_see_text(self.officer_allegation.officer.display_name) def test_default_site_title_from_settings(self): setting = self.get_admin_settings() setting.default_site_title = 'New title' setting.save() self.visit_home(fresh=True) self.browser.title.should.equal(setting.default_site_title) def test_share_button(self): self.visit_home(fresh=True) self.find('.share-button button').click() self.find('.share-bar').is_displayed() self.find('.share-bar-content-wrapper input').get_attribute('value').should_not.equal(self.browser.current_url) self.find('.share-button button').click() with self.browser_no_wait(): self.element_exist('.share-bar').should.be.false def test_no_disclaimer_when_search_engine(self): profile = webdriver.FirefoxProfile() profile.set_preference( "general.useragent.override", "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)" ) browser = WebDriver(profile) browser.implicitly_wait(10) browser.set_window_size(width=1200, height=1200) old_browser = self.browser self.set_browser(browser) try: self.visit_home() self.find('#disclaimer').get_attribute('class').should.contain('fade') finally: browser.close() self.set_browser(old_browser) self.set_default_window_size() self.try_to_revive_browser() def create_glossary_page(self, rows): HomePage.get_tree().all().delete() root = HomePage.add_root(instance=HomePageFactory.build( title='Root', slug='root')) glossary_page = root.add_child( instance=GlossaryPageFactory.build( title='Glossary', glossary_table_rows=rows, slug='glossary', subtitle='sub-title')) Site.objects.create( is_default_site=True, root_page=root, hostname='localhost') return glossary_page def visit_glossary_page(self): nav_link = [el for el in self.find_all('.nav-link') if el.text == 'Glossary'] nav_link[0].find('a').click() def glossary_rows_content(self): return [ [el.find('.%s' % cls_name).text for cls_name in ['term', 'definition', 'category']] for el in self.find_all('table.glossary-table tr')] def test_glossary_page(self): rows = [ GlossaryTableRowFactory.build(sort_order=3), GlossaryTableRowFactory.build(sort_order=1), GlossaryTableRowFactory.build(sort_order=2) ] glossary_page = self.create_glossary_page(rows) self.visit_home(fresh=True) self.visit_glossary_page() self.find('.glossary-page .glossary-title').text.should.equal(glossary_page.title) self.find('.glossary-page .glossary-subtitle').text.should.equal(glossary_page.subtitle) self.glossary_rows_content().should.equal([ [rows[1].term, rows[1].definition, rows[1].category_text], [rows[2].term, rows[2].definition, rows[2].category_text], [rows[0].term, rows[0].definition, rows[0].category_text] ]) def test_share_bar_facebook_share(self): title = 'Donald Duck' self.visit_home() self.find('.share-button button').click() self.until_ajax_complete() self.fill_in('.site-title-input', title) shared_hash_id = re.findall( r'data/([^/]+)', self.find('.share-bar-content-wrapper input').get_attribute('value'))[0] self.find('.share-bar-facebook-link').click() self.until_ajax_complete() with switch_to_popup(self.browser): ('https://www.facebook.com' in self.browser.current_url).should.be.true self.find('.share-button button').click() session_id = Session.id_from_hash(shared_hash_id)[0] session = Session.objects.get(id=session_id) session.title.should.be.equal(title) def test_responsive_layout(self): profile = webdriver.FirefoxProfile() profile.set_preference( "general.useragent.override", "Mozilla/5.0 (iPad; CPU OS 5_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko ) Version/5.1 Mobile/9B176 Safari/7534.48.3" # noqa ) driver = webdriver.Firefox(profile) old_browser = self.browser self.set_browser(driver) try: self.browser.set_window_size(width=1040, height=1200) # 1024 + 16px for scroll bar, apparently? self.visit_home() self.find('.chart-row .nav-tabs li:first-child').text.should.contain('Outcomes') self.find('#sunburst-chart svg').get_attribute('width').should.be.greater_than('249') self.browser.set_window_size(width=1023, height=1200) self.visit_home() self.find('.chart-row .nav-tabs li:first-child').text.should.contain('Map') finally: driver.close() self.set_browser(old_browser) self.browser.set_window_size(width=1200, height=1000) def test_hamburger_menu(self): self.visit_home() try: self.browser.set_window_size(800, 1000) self.is_element_displayed('.landing-nav .nav-tabs').should.be.true self.is_element_displayed('.landing-nav .tablist').should.be.false self.find('.landing-nav .nav-tabs .fa-bars').click() self.find('.landing-nav .nav-tabs-sidebar').get_attribute('class').shouldnt.contain('hidden') self.find('.landing-nav .nav-tabs-sidebar .fa-times').click() self.find('.landing-nav .nav-tabs-sidebar').get_attribute('class').should.contain('hidden') self.find('.landing-nav .nav-tabs .fa-bars').click() self.find('#landing-page > div.landing-page.fixed-nav > nav > div > div.nav-tabs.pull-right > div > ul > li:nth-child(3) > a').click() # noqa self.until_ajax_complete() self.find('.landing-nav .nav-tabs-sidebar').get_attribute('class').should.contain('hidden') finally: self.set_default_window_size() self.try_to_revive_browser() def test_overlay_hamburger_menu(self): self.visit_home() try: self.browser.set_window_size(800, 1000) self.find('.landing-nav .nav-tabs .fa-bars').click() self.find('#overlay').get_attribute('class').should.contain('active') self.find('.landing-nav .nav-tabs-sidebar .fa-times').click() self.find('#overlay').get_attribute('class').shouldnt.contain('active') self.find('.landing-nav .nav-tabs .fa-bars').click() self.find('#landing-page > div.landing-page.fixed-nav > nav > div > div.nav-tabs.pull-right > div > ul > li:nth-child(3) > a').click() # noqa self.until_ajax_complete() self.find('#overlay').get_attribute('class').shouldnt.contain('active') self.find('.landing-nav .nav-tabs .fa-bars').click() self.find('#overlay').get_attribute('class').should.contain('active') finally: self.set_default_window_size() self.try_to_revive_browser()
class HomePageTestCase(AutocompleteTestHelperMixin, BaseLiveTestCase): def setUp(self): self.allegation_category = AllegationCategoryFactory() self.officer_allegation = OfficerAllegationFactory( cat=self.allegation_category, final_finding='NS') def tearDown(self): super(HomePageTestCase, self).tearDown() self.allegation_category.delete() if self.officer_allegation.officer: self.officer_allegation.officer.delete() else: self.officer_allegation.delete() def test_start_new_session_on_click_logo(self): Session.objects.all().count().should.equal(0) self.visit_home(fresh=True) self.link("Categories").click() self.find(".category-name-wrapper a").click() self.until_ajax_complete() Session.objects.all().count().should.equal(1) url = self.browser.current_url self.find("#logo_link img").click() self.until(lambda: self.browser.current_url != url) Session.objects.all().count().should.equal(2) session = Session.objects.all()[1] self.browser.current_url.should.contain(session.hash_id) def test_see_tabs(self): self.visit_home() links = self.find_all('.chart-row .nav a') link_texts = [x.text for x in links] link_texts.should.contain('Outcomes') link_texts.should.contain('Categories') link_texts.should.contain('Complainants') link_texts.should.contain('Accused') def test_close_disclaimer(self): self.visit_home() self.link('About the data').click() self.until(lambda: self.button('I UNDERSTAND').click()) self.until(lambda: self.should_not_see_text('I UNDERSTAND')) def test_see_session_query_on_reload(self): self.visit_home() officer = self.officer_allegation.officer rebuild_index() self.until(lambda: self.fill_in('.ui-autocomplete-input', officer. officer_first)) self.until_ajax_complete() self.until(lambda: self.find(".autocomplete-officer").is_displayed()) self.find(".autocomplete-officer").click() self.should_see_text(officer.officer_first) self.should_see_text(officer.officer_last) self.browser.refresh() self.until(self.ajax_complete) self.until(lambda: self.should_see_text(officer.officer_first)) self.should_see_text(officer.officer_last) def test_complaint_detail_without_investigator(self): self.officer_allegation.investigator = None self.officer_allegation.save() self.visit_home() self.link('Categories').click() self.find('.category-name').click() self.find('.complaint-row .cursor').click() officers_divs = self.find_all('.officers > div') len(officers_divs).should.equal(1) officers_divs[0].has_class('col-md-10') def click_sunburst_legend(self, text): self.element_by_tagname_and_text('td', text).click() self.sleep(0.75) self.until(lambda: self.element_by_classname_and_text( 'filter-name', text).should.be.ok) def test_sunburst(self): us = 'Unsustained' ns = 'Not Sustained' self.visit_home() self.click_active_tab("Outcomes") with self.browser_no_wait(): self.element_by_classname_and_text('filter-name', us)\ .shouldnt.be.ok self.element_by_classname_and_text('filter-name', ns)\ .shouldnt.be.ok self.click_sunburst_legend(us) with self.browser_no_wait(): self.element_by_classname_and_text('filter-name', ns)\ .shouldnt.be.ok sunburst_legend_root_text = self.find('#sunburst-legend .root').text url = self.browser.current_url with self.open_new_browser(): self.visit(url) self.until_ajax_complete() self.sleep(0.75) # sunburst zoom time with self.browser_no_wait(): # same state with above self.find('#sunburst-legend .root')\ .text.should.equal(sunburst_legend_root_text) self.click_sunburst_legend(ns) with self.browser_no_wait(): self.element_by_classname_and_text('filter-name', us).shouldnt.be.ok self.click_sunburst_legend(us) with self.browser_no_wait(): self.element_by_classname_and_text('filter-name', ns).shouldnt.be.ok self.find(".tag .remove").click() with self.browser_no_wait(): self.element_by_tagname_and_text('td', ns).shouldnt.be.ok def test_sunburst_remove_tag(self): us = 'Unsustained' ns = 'Not Sustained' self.officer_allegation = OfficerAllegationFactory( cat=self.allegation_category, final_outcome='300') self.visit_home() self.click_active_tab("Outcomes") self.until(lambda: self.should_see_text('Officers (2)')) self.click_sunburst_legend(us) self.click_sunburst_legend(ns) self.until( lambda: self.element_by_classname_and_text('filter-name', ns)) self.find(".tag .remove").click() self.until( lambda: self.element_by_classname_and_text('filter-name', us)) self.should_see_text('Officers (1)') def test_replace_old_filter_in_same_category(self): officer_allegation = OfficerAllegationFactory() rebuild_index() self.visit_home() self.search_officer(officer_allegation.officer) self.should_see_text(officer_allegation.officer.display_name) self.search_officer(self.officer_allegation.officer) self.should_see_text(self.officer_allegation.officer.display_name) self.should_not_see_text(officer_allegation.officer.display_name) @retry_random_fail def test_pin_tag(self): officer_allegation = OfficerAllegationFactory() another = OfficerAllegationFactory() rebuild_index() self.visit_home() self.search_officer(officer_allegation.officer) self.should_see_text(officer_allegation.officer.display_name) self.find('.tag > .pin').click() self.until(lambda: self.find('.tag').get_attribute('class').should. contain('pinned')) self.search_officer(self.officer_allegation.officer) self.should_see_text(self.officer_allegation.officer.display_name) self.should_see_text(officer_allegation.officer.display_name) self.search_officer(another.officer) self.should_see_text(another.officer.display_name) self.should_see_text(officer_allegation.officer.display_name) self.should_not_see_text(self.officer_allegation.officer.display_name) def test_unpin_tag(self): officer_allegation = OfficerAllegationFactory() another = OfficerAllegationFactory() rebuild_index() self.visit_home() self.search_officer(officer_allegation.officer) self.should_see_text(officer_allegation.officer.display_name) self.find('.tag > .pin').click() self.search_officer(self.officer_allegation.officer) self.should_see_text(self.officer_allegation.officer.display_name) self.should_see_text(officer_allegation.officer.display_name) element = self.find('.pinned') element.find('.pin').click() self.until( lambda: element.get_attribute('class').shouldnt.contain('pinned')) self.search_officer(another.officer) self.should_see_text(another.officer.display_name) self.should_not_see_text(officer_allegation.officer.display_name) self.should_not_see_text(self.officer_allegation.officer.display_name) def test_default_site_title_from_settings(self): setting = self.get_admin_settings() setting.default_site_title = 'New title' setting.save() self.visit_home(fresh=True) self.browser.title.should.equal(setting.default_site_title) def test_share_button(self): self.visit_home(fresh=True) self.find('.share-button button').click() self.find('.share-bar').is_displayed() self.find('.share-bar-content-wrapper input').get_attribute( 'value').should_not.equal(self.browser.current_url) self.find('.share-button button').click() with self.browser_no_wait(): self.element_exist('.share-bar').should.be.false def test_no_disclaimer_when_search_engine(self): profile = webdriver.FirefoxProfile() profile.set_preference( "general.useragent.override", "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)" ) browser = WebDriver(profile) browser.implicitly_wait(10) browser.set_window_size(width=1200, height=1200) old_browser = self.browser self.set_browser(browser) try: self.visit_home() self.find('#disclaimer').get_attribute('class').should.contain( 'fade') finally: browser.close() self.set_browser(old_browser) self.set_default_window_size() self.try_to_revive_browser() def create_glossary_page(self, rows): HomePage.get_tree().all().delete() root = HomePage.add_root( instance=HomePageFactory.build(title='Root', slug='root')) glossary_page = root.add_child( instance=GlossaryPageFactory.build(title='Glossary', glossary_table_rows=rows, slug='glossary', subtitle='sub-title')) Site.objects.create(is_default_site=True, root_page=root, hostname='localhost') return glossary_page def visit_glossary_page(self): nav_link = [ el for el in self.find_all('.nav-link') if el.text == 'Glossary' ] nav_link[0].find('a').click() def glossary_rows_content(self): return [[ el.find('.%s' % cls_name).text for cls_name in ['term', 'definition', 'category'] ] for el in self.find_all('table.glossary-table tr')] def test_glossary_page(self): rows = [ GlossaryTableRowFactory.build(sort_order=3), GlossaryTableRowFactory.build(sort_order=1), GlossaryTableRowFactory.build(sort_order=2) ] glossary_page = self.create_glossary_page(rows) self.visit_home(fresh=True) self.visit_glossary_page() self.find('.glossary-page .glossary-title').text.should.equal( glossary_page.title) self.find('.glossary-page .glossary-subtitle').text.should.equal( glossary_page.subtitle) self.glossary_rows_content().should.equal( [[rows[1].term, rows[1].definition, rows[1].category_text], [rows[2].term, rows[2].definition, rows[2].category_text], [rows[0].term, rows[0].definition, rows[0].category_text]]) def test_share_bar_facebook_share(self): title = 'Donald Duck' self.visit_home() self.find('.share-button button').click() self.until_ajax_complete() self.fill_in('.site-title-input', title) shared_hash_id = re.findall( r'data/([^/]+)', self.find('.share-bar-content-wrapper input').get_attribute( 'value'))[0] self.find('.share-bar-facebook-link').click() self.until_ajax_complete() with switch_to_popup(self.browser): ('https://www.facebook.com' in self.browser.current_url).should.be.true self.find('.share-button button').click() session_id = Session.id_from_hash(shared_hash_id)[0] session = Session.objects.get(id=session_id) session.title.should.be.equal(title) def test_responsive_layout(self): profile = webdriver.FirefoxProfile() profile.set_preference( "general.useragent.override", "Mozilla/5.0 (iPad; CPU OS 5_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko ) Version/5.1 Mobile/9B176 Safari/7534.48.3" # noqa ) driver = webdriver.Firefox(profile) old_browser = self.browser self.set_browser(driver) try: self.browser.set_window_size( width=1040, height=1200) # 1024 + 16px for scroll bar, apparently? self.visit_home() self.find('.chart-row .nav-tabs li:first-child' ).text.should.contain('Outcomes') self.find('#sunburst-chart svg').get_attribute( 'width').should.be.greater_than('249') self.browser.set_window_size(width=1023, height=1200) self.visit_home() self.find('.chart-row .nav-tabs li:first-child' ).text.should.contain('Map') finally: driver.close() self.set_browser(old_browser) self.browser.set_window_size(width=1200, height=1000) def test_hamburger_menu(self): self.visit_home() try: self.browser.set_window_size(800, 1000) self.is_element_displayed('.landing-nav .nav-tabs').should.be.true self.is_element_displayed('.landing-nav .tablist').should.be.false self.find('.landing-nav .nav-tabs .fa-bars').click() self.find('.landing-nav .nav-tabs-sidebar').get_attribute( 'class').shouldnt.contain('hidden') self.find('.landing-nav .nav-tabs-sidebar .fa-times').click() self.find('.landing-nav .nav-tabs-sidebar').get_attribute( 'class').should.contain('hidden') self.find('.landing-nav .nav-tabs .fa-bars').click() self.find( '#landing-page > div.landing-page.fixed-nav > nav > div > div.nav-tabs.pull-right > div > ul > li:nth-child(3) > a' ).click() # noqa self.until_ajax_complete() self.find('.landing-nav .nav-tabs-sidebar').get_attribute( 'class').should.contain('hidden') finally: self.set_default_window_size() self.try_to_revive_browser() def test_overlay_hamburger_menu(self): self.visit_home() try: self.browser.set_window_size(800, 1000) self.find('.landing-nav .nav-tabs .fa-bars').click() self.find('#overlay').get_attribute('class').should.contain( 'active') self.find('.landing-nav .nav-tabs-sidebar .fa-times').click() self.find('#overlay').get_attribute('class').shouldnt.contain( 'active') self.find('.landing-nav .nav-tabs .fa-bars').click() self.find( '#landing-page > div.landing-page.fixed-nav > nav > div > div.nav-tabs.pull-right > div > ul > li:nth-child(3) > a' ).click() # noqa self.until_ajax_complete() self.find('#overlay').get_attribute('class').shouldnt.contain( 'active') self.find('.landing-nav .nav-tabs .fa-bars').click() self.find('#overlay').get_attribute('class').should.contain( 'active') finally: self.set_default_window_size() self.try_to_revive_browser()
def setUp(self): self.allegation_category = AllegationCategoryFactory() self.officer_allegation = OfficerAllegationFactory( cat=self.allegation_category, final_finding='NS')
def setUp(self): self.officer = OfficerFactory() self.allegation = AllegationFactory() self.cat = AllegationCategoryFactory() self.officer_allegation = OfficerAllegationFactory( officer=self.officer, allegation=self.allegation, cat=self.cat)