def test_does_not_return_less_than_2_chars_query(self): SuggestionLogFactory(search_query='long_long_query') SuggestionLogFactory(search_query='12') response, data = self.call_query_data_api() len(data['data']).should.equal(1)
def test_filter_fail_attemps(self): log = SuggestionLogFactory(num_suggestions=0) log1 = SuggestionLogFactory(num_suggestions=1) self.go_to_search_result() self.element_by_tagname_and_text('li', "Fail attempts").click() self.until(lambda: self.should_see_text(log.search_query)) self.should_not_see_text(log1.search_query)
def test_api_call_with_num_suggestions_filter(self): SuggestionLogFactory(num_suggestions=0) SuggestionLogFactory(num_suggestions=1) response, data = self.call_query_data_api({'fail': 1}) len(data['data']).should.equal(1) data['data'][0]['num_suggestions'].should.equal(0)
def test_search_by_query_call(self): SuggestionLogFactory(search_query='query') SuggestionLogFactory(search_query='other') q = 'qu' response, data = self.call_query_data_api({'q': q}) len(data['data']).should.equal(1) data['data'][0]['search_query'].should.contain(q)
def test_suggestion_admin(self): self.login_user() log = SuggestionLogFactory() self.visit("/admin/models/") self.link("Suggestion logs").click() self.should_see_text(log.search_query)
def test_filter_alias(self): log = SuggestionLogFactory(num_suggestions=0) alias = AliasFactory() self.go_to_search_result() self.element_by_tagname_and_text('li', "Alias").click() self.until(lambda: self.should_see_text(alias.alias)) self.should_not_see_text(log.search_query)
def test_get_search_traffic(self): suggestion_log = SuggestionLogFactory() response, data = self.call_search_traffic_api() response.status_code.should.equal(status.HTTP_200_OK) set(data.keys()).should.equal({'day', 'week', 'month'}) for _, item in data.items(): item.should.contain(suggestion_log.search_query)
def test_get_aliases_should_return_all_aliases(self): alias = 'alias' AliasFactory(alias=alias) SuggestionLogFactory(search_query=alias, num_suggestions=1) response, data = self.get_aliases() len(data['data']).should.equal(1)
def test_add_alias_from_query(self): SuggestionLogFactory() self.go_to_search_result() row = self.find(".query") row.find(".add-alias").click() self.until(lambda: self.find(".modal").is_displayed()) self.find("input[name='alias']").get_attribute("value").should.equal( row.find("td").text)
def test_get_details_with_session(self): session = SessionFactory() SuggestionLogFactory(session_id=session.hash_id) FilterLogFactory(session_id=session.hash_id) response, data = self.get_sessions() response.status_code.should.equal(200) len(data['results']).should.be(1) len(data['results'][0]['suggestion_logs']).should.be(1) len(data['results'][0]['filter_logs']).should.be(1)
def test_success_call_with_pagination(self): SuggestionLog.objects.all().delete() self.logs = [SuggestionLogFactory() for i in range(16)] response, data = self.call_query_data_api() data.should.contain('data') isinstance(data['data'], list).should.be.true len(data['data']).should.equal(15) response, data = self.call_query_data_api({'page': 1}) len(data['data']).should.equal(1)
def test_see_history_of_session(self): category = 'category' session = SessionFactory() suggestion = SuggestionLogFactory(session_id=session.hash_id) FilterLogFactory(session_id=session.hash_id, tag_name='cat__category=category') self.go_to_sessions() self.find('tr.session-row').click() self.should_see_text(suggestion.search_query) self.should_see_text(category)
def test_see_search_result_tab(self): log = SuggestionLogFactory() self.should_see_text('Search Results') self.go_to_search_result() self.button('Add Alias').should.be.ok self.find("#queries").should.be.ok results = self.find_all("#queries .query") len(results).shouldnt.equal(0) self.should_see_text(log.search_query) self.should_see_text(log.num_suggestions) self.should_see_text(1)
def test_sort_order(self): SuggestionLogFactory.create_batch(search_query='query1', size=2) SuggestionLogFactory.create_batch(search_query='query2', size=4) SuggestionLogFactory.create_batch(search_query='query3', size=3) response, data = self.call_query_data_api({'order_by': '-num_usage'}) data = data['data'] data[0]['search_query'].should.equal('query2') data[1]['search_query'].should.equal('query3') data[2]['search_query'].should.equal('query1')
def test_get_search_traffic_with_bad_characters(self): SuggestionLogFactory(search_query="bad'searchquery") response, data = self.call_search_traffic_api() response.status_code.should.equal(status.HTTP_200_OK)