def test_display_stories(self): story1 = StoryFactory(officer=self.officer, url=TEST_DOCUMENT_URL, story_type='abc') story2 = StoryFactory(officer=self.officer, url=TEST_DOCUMENT_URL, story_type='def') story_types_order = [ story2.story_type.capitalize(), story1.story_type.capitalize() ] self.setting.story_types_order = ",".join(story_types_order) self.setting.save() self.go_to_officer_detail_page(self.officer) self.until_ajax_complete() story_types = self.find_all("#story_list h3") story_types = [x.text for x in story_types] story_types.should.equal(story_types_order) self.should_see_texts([ story1.title, story1.short_description, story2.title, story2.short_description, ]) self.find('.document-url').get_attribute('href')\ .should.equal(TEST_DOCUMENT_URL) self.find('.document-thumbnail').should.be.ok
def test_distinct_query(self): story = StoryFactory(story_type='Old') StoryFactory(story_type='Old') response = self.client.get('/api/dashboard/story_types/', {'query': story.story_type[0]}) content = json.loads(response.content.decode()) data = content['data'] len(data).should.equal(1) data.should.contain(story.story_type)
def test_story_category_order(self): story_type1 = 'story_type1' story_type2 = 'story_type2' StoryFactory(officer=self.officer, story_type=story_type1) StoryFactory(officer=self.officer, story_type=story_type2) settings = self.get_admin_settings() settings.story_types_order = ','.join([story_type2, story_type1]) settings.save() self.visit_officer() story_type_titles = self.find_all('#story_list h3') story_type_titles[0].text.should.equal(story_type2.capitalize()) story_type_titles[1].text.should.equal(story_type1.capitalize())
def test_long_description_cut(self): StoryFactory( officer=self.officer, short_description="a b c" * 60) # 300 chars self.visit_officer() self.until(lambda: self.should_see_text('Read more'))
def test_delete_story(self): officer = self.officer stories = [StoryFactory(officer=officer) for x in range(2)] self.go_to_officer_profile() self.go_to_single_officer(officer) self.until(lambda: self.should_see_text(stories[1].title)) self.should_see_text(stories[0].title) self.find(".story .fa-trash").click() confirm_message = 'You are going to delete story "{title}"?'.format( title=stories[1].title) self.until(lambda: self.should_see_text(confirm_message)) self.button("OK").click() self.until_ajax_complete() self.should_see_text( 'Story "{title}" has been deleted.'.format(title=stories[1].title)) self.hide_toastr() self.until_ajax_complete() # reload story list self.until(lambda: self.should_not_see_text(stories[1].title)) self.should_see_text(stories[0].title) self.find(".check-all").click() self.button("Delete").click() self.until(lambda: self.should_see_text( "You are going to delete all stories of this officer?")) self.button("OK").click() self.until_ajax_complete() self.should_see_text("Stories have been deleted.") self.should_not_see_text(stories[0].title)
def test_suggest_existing_types(self): story = StoryFactory(story_type='Old') response = self.client.get('/api/dashboard/story_types/', {'query': story.story_type[0]}) response.status_code.should.equal(200) content = json.loads(response.content.decode()) data = content['data'] data.should.contain(story.story_type)
def test_display_delete_button(self): officer = self.officer StoryFactory(officer=officer) self.go_to_officer_profile() self.go_to_single_officer(officer) self.button("Delete").is_displayed().should.be(False) self.find("input[type='checkbox']").click() self.button("Delete").is_displayed().shouldnt.be(False)
def test_limit_results(self): limit = 10 types = ['Type %s' % i for i in range(11)] for story_type in types: StoryFactory(story_type=story_type) response = self.client.get('/api/dashboard/story_types/', {'query': 'Type'}) content = json.loads(response.content.decode()) data = content['data'] len(data).should.equal(limit)
def test_story_category_with_empty_setting(self): story_type = 'story_type' StoryFactory(officer=self.officer, story_type=story_type) settings = self.get_admin_settings() settings.story_types_order = '' settings.save() self.visit_officer() self.element_by_tagname_and_text('h3', story_type).should.be.ok
def test_fetch_stories(self): story = StoryFactory() response = self.client.get("/officer/stories/", { 'officer': story.officer.id, }) response.status_code.should.equal(200) data = json.loads(response.content.decode()) data['success'].should.be.true isinstance(data['stories'], list).should.be.true data['stories'][0]['officer']['pk'].should.equal(story.officer.id)
def test_story_type_suggest(self): story = StoryFactory(story_type='Old') officer = self.officer self.go_to_officer_profile() self.find("#search-officer input").send_keys(officer.officer_first) self.find(".officer").click() select = self.find('.Select-input > input') select.send_keys(story.story_type[0]) self.until(self.ajax_complete) self.element_by_classname_and_text('Select-option', story.story_type).should.be.ok
def test_display_stories(self): story = StoryFactory(officer=self.officer) self.visit_officer() self.until(lambda: self.should_see_text(story.story_type.capitalize())) self.should_see_text(story.title)