From 48b5160155bcef790b14a0c839ded36d98dd2052 Mon Sep 17 00:00:00 2001 From: Dan Ford Date: Mon, 10 Nov 2014 13:52:13 -0500 Subject: [PATCH 01/17] add test ES setup/teardown --- tests/__init__.py | 62 +++++++ tests/fixtures/newsroom.json | 320 +++++++++++++++++++++++++++++++++++ 2 files changed, 382 insertions(+) create mode 100644 tests/fixtures/newsroom.json diff --git a/tests/__init__.py b/tests/__init__.py index e69de29bb2d..15f98ec67b3 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -0,0 +1,62 @@ +import os +import json + +from elasticsearch import Elasticsearch + +from sheer.wsgi import app_with_config + +index_name = "cfgov_test" +root = os.getcwd() + +def setup_package(): + es = Elasticsearch() + if es.indices.exists(index_name): + es.indices.delete(index_name) + es.indices.create(index=index_name) + + newsroom_mapping = { "properties" : + { + "title" : {"type" : "string", "store" : "yes"}, + "text" : {"type" : "string", "store" : "yes"}, + "date" : {"type" : "date", "store": "yes"}, + "category" : {"type":"string", "index": "not_analyzed"}, + "author" : {"type":"string", "index":"not_analyzed"}, + "tags" : {"type":"string", "store": "yes", "index":"not_analyzed"}, + "excerpt" : {"type":"string", "store": "yes"}, + "custom_fields": { + "properties": { + "display_in_newsroom": {"type":"string", "index":"not_analyzed"} + } + } + } + } + + # Create the mappings + es.indices.put_mapping(index=index_name, + doc_type="newsroom", + body={"newsroom": newsroom_mapping}) + + newsroom_json = open(os.path.join(root, 'fixtures/newsroom.json')) + newsroom = json.load(newsroom_json) + + # Index the documents + for document in newsroom: + es.create(index=index_name, + doc_type="newsroom", + id=document['_id'], + body=document) + + # Setup server + config = {'debug': False, + 'index': index_name, + 'elasticsearch': [{'host': 'localhost', 'port': 9200}], + 'location': root} + print "Starting server" + application = app_with_config(config) + application.run(host='0.0.0.0', port=7000, threaded=True) + + + +def teardown_package(): + es = Elasticsearch() + es.indices.delete(index_name) \ No newline at end of file diff --git a/tests/fixtures/newsroom.json b/tests/fixtures/newsroom.json new file mode 100644 index 00000000000..7c65311aef7 --- /dev/null +++ b/tests/fixtures/newsroom.json @@ -0,0 +1,320 @@ +[ + { + "attachments": [], + "excerpt": "This is just an excerpt of the content", + "taxonomy_cfpb_newsroom_tag_taxonomy": [ + { + "post_count": 88, + "description": "", + "title": "Credit cards", + "id": 19, + "slug": "credit-cards" + }, + { + "post_count": 26, + "description": "", + "title": "Foreclosure", + "id": 441, + "slug": "foreclosure" + }, + { + "post_count": 188, + "description": "", + "title": "Mortgages", + "id": 23, + "slug": "mortgages" + } + ], + "taxonomy_cfpb_newsroom_cat_taxonomy": [ + { + "description": "", + "parent": 0, + "title": "Op-Ed", + "post_count": 17, + "slug": "op-ed", + "id": 443 + } + ], + "taxonomy_author": [ + { + "post_count": 30, + "description": "", + "title": "Batman", + "id": 779, + "slug": "batman" + } + ], + "id": 45929, + "custom_fields": {}, + "category": [ + "Op-Ed" + ], + "author": [ + "Batman" + ], + "content": "Some test content", + "comment_count": 0, + "categories": [], + "type": "cfpb_newsroom", + "status": "publish", + "parent": 0, + "tags": [ + "Credit cards", + "Foreclosure", + "Mortgages" + ], + "taxonomy_fj_tag": [ + { + "post_count": 112, + "description": "", + "title": "Credit cards", + "id": 19, + "slug": "credit-cards" + }, + { + "post_count": 29, + "description": "", + "title": "Foreclosure", + "id": 441, + "slug": "foreclosure" + }, + { + "post_count": 255, + "description": "", + "title": "Mortgages", + "id": 23, + "slug": "mortgages" + } + ], + "date": "2010-09-17T04:41:50Z", + "slug": "fighting-to-protect-testers", + "comment_status": "closed", + "title_plain": "Fighting to Protect Testers", + "title": "Fighting to Protect Testers", + "modified": "2010-09-17 04:41:50", + "dek": "Test dek", + "_id": "fighting-to-protect-testers", + "order": 0 + }, + { + "attachments": [], + "excerpt": "Test excerpt for this post", + "taxonomy_cfpb_newsroom_tag_taxonomy": [ + { + "post_count": 97, + "description": "", + "title": "Banking", + "id": 435, + "slug": "banking-2" + } + ], + "taxonomy_cfpb_newsroom_cat_taxonomy": [ + { + "description": "", + "parent": 0, + "title": "Op-Ed", + "post_count": 17, + "slug": "op-ed", + "id": 443 + } + ], + "taxonomy_author": [ + { + "post_count": 30, + "description": "", + "title": "Batman", + "id": 779, + "slug": "batman" + } + ], + "id": 45893, + "custom_fields": {}, + "category": [ + "Op-Ed" + ], + "author": [ + "Batman" + ], + "content": "Here is a bunch of content", + "comment_count": 0, + "categories": [], + "type": "cfpb_newsroom", + "status": "publish", + "parent": 0, + "tags": [ + "Banking" + ], + "taxonomy_fj_tag": [ + { + "post_count": 98, + "description": "", + "title": "Banking", + "id": 435, + "slug": "banking-2" + } + ], + "date": "2010-11-10T12:00:52Z", + "slug": "ttttttest", + "comment_status": "closed", + "title_plain": "Ttttttest", + "title": "Ttttttest", + "modified": "2010-11-10 12:00:52", + "dek": "The dek goes here", + "_id": "ttttttest", + "order": 0 + }, + { + "attachments": [], + "excerpt": "Excerpts are shorter versions of the real thing", + "taxonomy_cfpb_newsroom_tag_taxonomy": [ + { + "post_count": 32, + "description": "", + "title": "Personnel", + "id": 433, + "slug": "personnel" + }, + { + "post_count": 28, + "description": "", + "title": "Servicemembers", + "id": 32, + "slug": "servicemembers" + } + ], + "taxonomy_cfpb_newsroom_cat_taxonomy": [ + { + "description": "", + "parent": 0, + "title": "Press Release", + "post_count": 245, + "slug": "pressrelease", + "id": 425 + } + ], + "taxonomy_author": [], + "id": 45927, + "custom_fields": {}, + "category": [ + "Press Release" + ], + "author": [], + "content": "Some content would be cool to go here", + "comment_count": 0, + "categories": [], + "type": "cfpb_newsroom", + "status": "publish", + "parent": 0, + "tags": [ + "Personnel", + "Servicemembers" + ], + "taxonomy_fj_tag": [ + { + "post_count": 32, + "description": "", + "title": "Personnel", + "id": 433, + "slug": "personnel" + }, + { + "post_count": 69, + "description": "", + "title": "Servicemembers", + "id": 32, + "slug": "servicemembers" + } + ], + "date": "2011-01-06T04:51:16Z", + "slug": "this-is-for-testing-purposes", + "comment_status": "closed", + "title_plain": "This is for testing purposes", + "title": "This is for testing purposes", + "modified": "2011-01-06 04:51:16", + "dek": "Some sort of dek info", + "_id": "this-is-for-testing-purposes", + "order": 0 + }, + { + "attachments": [], + "excerpt": "Excerpt Excerpt Excerpt", + "taxonomy_cfpb_newsroom_tag_taxonomy": [ + { + "post_count": 88, + "description": "", + "title": "Credit cards", + "id": 19, + "slug": "credit-cards" + }, + { + "post_count": 32, + "description": "", + "title": "Personnel", + "id": 433, + "slug": "personnel" + } + ], + "taxonomy_cfpb_newsroom_cat_taxonomy": [ + { + "description": "", + "parent": 0, + "title": "Op-Ed", + "post_count": 17, + "slug": "op-ed", + "id": 443 + } + ], + "taxonomy_author": [ + { + "post_count": 30, + "description": "", + "title": "Batman", + "id": 779, + "slug": "batman" + } + ], + "id": 45923, + "custom_fields": {}, + "category": [ + "Op-Ed" + ], + "author": [ + "Batman" + ], + "content": "More blog content", + "comment_count": 0, + "categories": [], + "type": "cfpb_newsroom", + "status": "publish", + "parent": 0, + "tags": [ + "Credit cards", + "Personnel" + ], + "taxonomy_fj_tag": [ + { + "post_count": 112, + "description": "", + "title": "Credit cards", + "id": 19, + "slug": "credit-cards" + }, + { + "post_count": 32, + "description": "", + "title": "Personnel", + "id": 433, + "slug": "personnel" + } + ], + "date": "2011-01-06T20:50:14Z", + "slug": "just-more-testing", + "comment_status": "closed", + "title_plain": "Blah blah blah", + "title": "Blah blah blah", + "modified": "2011-01-06 20:50:14", + "dek": "Dek info here", + "_id": "just-more-testing", + "order": 0 + } +] \ No newline at end of file From b51c904121c09b99bb815cbb62165a2cc2e4213e Mon Sep 17 00:00:00 2001 From: Dan Ford Date: Mon, 10 Nov 2014 14:44:44 -0500 Subject: [PATCH 02/17] added Flask-Testing, different way to initialize app --- tests/__init__.py | 13 +------------ tests/requirements.txt | 1 + tests/test.py | 18 ++++++++++++++++-- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/tests/__init__.py b/tests/__init__.py index 15f98ec67b3..29754f37867 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -3,11 +3,10 @@ from elasticsearch import Elasticsearch -from sheer.wsgi import app_with_config - index_name = "cfgov_test" root = os.getcwd() + def setup_package(): es = Elasticsearch() if es.indices.exists(index_name): @@ -46,16 +45,6 @@ def setup_package(): id=document['_id'], body=document) - # Setup server - config = {'debug': False, - 'index': index_name, - 'elasticsearch': [{'host': 'localhost', 'port': 9200}], - 'location': root} - print "Starting server" - application = app_with_config(config) - application.run(host='0.0.0.0', port=7000, threaded=True) - - def teardown_package(): es = Elasticsearch() diff --git a/tests/requirements.txt b/tests/requirements.txt index 12895de2dab..92ff560aafe 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -2,3 +2,4 @@ nose==1.3.4 selenium==2.44.0 selenose==1.3 wsgiref==0.1.2 +Flask-Testing==0.4.2 diff --git a/tests/test.py b/tests/test.py index 72067118147..00bf7f08f0b 100644 --- a/tests/test.py +++ b/tests/test.py @@ -1,15 +1,29 @@ import nose +import os from nose.plugins.attrib import attr from selenose.cases import SeleniumTestCase - +from flask.ext.testing import LiveServerTestCase from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as ec from .test_helpers import * -class NewsroomTestCase(SeleniumTestCase): +from sheer.wsgi import app_with_config + +class NewsroomTestCase(SeleniumTestCase, LiveServerTestCase): + + def create_app(self): + # Setup server + config = {'debug': False, + 'index': 'cfgov_test', + 'elasticsearch': [{'host': 'localhost', 'port': 9200}], + 'location': os.getcwd()} + application = app_with_config(config) + application.config['LIVESERVER_PORT'] = 7000 + return application + def setUp(self): self.driver.get('http://refresh.demo.cfpb.gov/newsroom/') # self.filter_dropdown_button = self.driver.find_element_by_xpath('//button[contains(text(), "Filter posts")]') From bd8d88f5dca9786ceb4f8e1dd64202b8a7ff59b2 Mon Sep 17 00:00:00 2001 From: Dan Ford Date: Wed, 12 Nov 2014 10:16:48 -0500 Subject: [PATCH 03/17] added view, switched away from Selenose --- tests/__init__.py | 17 ++- tests/fixtures/views.json | 247 ++++++++++++++++++++++++++++++++++++++ tests/test.py | 103 +++++++++------- 3 files changed, 323 insertions(+), 44 deletions(-) create mode 100644 tests/fixtures/views.json diff --git a/tests/__init__.py b/tests/__init__.py index 29754f37867..70ea45b08e1 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -2,6 +2,7 @@ import json from elasticsearch import Elasticsearch +from elasticsearch.client import IndicesClient index_name = "cfgov_test" root = os.getcwd() @@ -38,6 +39,9 @@ def setup_package(): newsroom_json = open(os.path.join(root, 'fixtures/newsroom.json')) newsroom = json.load(newsroom_json) + view_json = open(os.path.join(root, 'fixtures/views.json')) + view = json.load(view_json) + # Index the documents for document in newsroom: es.create(index=index_name, @@ -45,7 +49,16 @@ def setup_package(): id=document['_id'], body=document) + for document in view: + es.create(index=index_name, + doc_type="views", + id=document['_id'], + body=document) + + print "outer mapping here", IndicesClient(es).get_mapping(index='cfgov_test') + def teardown_package(): - es = Elasticsearch() - es.indices.delete(index_name) \ No newline at end of file + pass + # es = Elasticsearch() + # es.indices.delete(index_name) \ No newline at end of file diff --git a/tests/fixtures/views.json b/tests/fixtures/views.json new file mode 100644 index 00000000000..36c28f75bf6 --- /dev/null +++ b/tests/fixtures/views.json @@ -0,0 +1,247 @@ +[ + { + "attachments": [], + "excerpt": "", + "id": 62519, + "custom_fields": { + "related_hero": [ + "" + ] + }, + "related_links": [], + "author": { + "first_name": "Mike", + "last_name": "m", + "name": "Mike", + "url": "", + "slug": "mm", + "nickname": "mm", + "id": 233, + "description": "" + }, + "comments": [], + "content": "", + "comment_count": 0, + "categories": [], + "type": "view", + "status": "publish", + "parent": 0, + "tags": [], + "date": "2014-08-25 17:47:01", + "slug": "contact-us", + "comment_status": "closed", + "title_plain": "contact us", + "title": "contact us", + "modified": "2014-08-25 17:47:13", + "dek": "", + "_id": "contact-us", + "order": 0 + }, + { + "attachments": [], + "popular_posts": [ + "spring-2014-rulemaking-agenda", + "our-board-and-council-meetings-are-changing", + "save-the-date-join-us-for-a-consumer-advisory-board-meeting-in-reno-nevada", + "summer-jobs-are-a-perfect-time-to-build-financial-skills-for-young-people", + "truth-in-lending-rule-now-available-in-easier-to-navigate-format" + ], + "excerpt": "", + "id": 62331, + "custom_fields": { + "related_hero": [ + "" + ], + "related_link_2": [ + "http://www.consumerfinance.gov/askcfpb/", + "Ask CFPB" + ], + "related_link_1": [ + "http://www.consumerfinance.gov/knowbeforeyouowe/", + "Know Before You Owe" + ], + "popular_posts": [ + "spring-2014-rulemaking-agenda", + "our-board-and-council-meetings-are-changing", + "save-the-date-join-us-for-a-consumer-advisory-board-meeting-in-reno-nevada", + "summer-jobs-are-a-perfect-time-to-build-financial-skills-for-young-people", + "truth-in-lending-rule-now-available-in-easier-to-navigate-format" + ], + "related_link_0": [ + "http://www.consumerfinance.gov/newsroom/prepared-remarks-of-cfpb-director-richard-cordray-at-the-consumer-response-field-hearing/", + "Prepared Remarks of CFPB Director Richard Cordray at the Consumer Response Field Hearing" + ] + }, + "related_links": [ + [ + "http://www.consumerfinance.gov/newsroom/prepared-remarks-of-cfpb-director-richard-cordray-at-the-consumer-response-field-hearing/", + "Prepared Remarks of CFPB Director Richard Cordray at the Consumer Response Field Hearing" + ], + [ + "http://www.consumerfinance.gov/knowbeforeyouowe/", + "Know Before You Owe" + ], + [ + "http://www.consumerfinance.gov/askcfpb/", + "Ask CFPB" + ] + ], + "author": { + "first_name": "Dan", + "last_name": "f", + "name": "Dan", + "url": "", + "slug": "df", + "nickname": "df", + "id": 329, + "description": "" + }, + "comments": [], + "content": "", + "comment_count": 0, + "categories": [], + "type": "view", + "status": "publish", + "parent": 0, + "tags": [], + "date": "2014-07-14 15:23:03", + "slug": "newsroom", + "comment_status": "closed", + "title_plain": "newsroom", + "title": "newsroom", + "modified": "2014-08-26 16:14:09", + "dek": "", + "_id": "newsroom", + "order": 0 + }, + { + "attachments": [], + "excerpt": "", + "id": 62031, + "custom_fields": { + "related_link_4": [ + "http://www.consumerfinance.gov/blog/truth-in-lending-rule-now-available-in-easier-to-navigate-format", + "Truth in Lending rule now available in easier-to-navigate format" + ], + "related_link_3": [ + "http://www.consumerfinance.gov/blog/save-the-date-join-us-for-a-consumer-advisory-board-meeting-in-reno-nevada", + "Save the date: Join us for a Consumer Advisory Board meeting in Reno, Nevada" + ], + "related_link_2": [ + "http://www.consumerfinance.gov/blog/our-board-and-council-meetings-are-changing", + "Our Board and Council meetings are changing" + ], + "related_link_1": [ + "http://www.consumerfinance.gov/blog/summer-jobs-are-a-perfect-time-to-build-financial-skills-for-young-people", + "Summer jobs are a perfect time to build financial skills for young people" + ], + "related_link_0": [ + "http://www.consumerfinance.gov/blog/spring-2014-rulemaking-agenda", + "Spring 2014 rulemaking agenda" + ], + "related_hero": [ + "two-years-of-standing-up-for-consumers" + ], + "related_post": [ + "Johnson & Johnson", + "Johnson & Johnson" + ] + }, + "related_links": [ + [ + "http://www.consumerfinance.gov/blog/spring-2014-rulemaking-agenda", + "Spring 2014 rulemaking agenda" + ], + [ + "http://www.consumerfinance.gov/blog/summer-jobs-are-a-perfect-time-to-build-financial-skills-for-young-people", + "Summer jobs are a perfect time to build financial skills for young people" + ], + [ + "http://www.consumerfinance.gov/blog/our-board-and-council-meetings-are-changing", + "Our Board and Council meetings are changing" + ], + [ + "http://www.consumerfinance.gov/blog/save-the-date-join-us-for-a-consumer-advisory-board-meeting-in-reno-nevada", + "Save the date: Join us for a Consumer Advisory Board meeting in Reno, Nevada" + ], + [ + "http://www.consumerfinance.gov/blog/truth-in-lending-rule-now-available-in-easier-to-navigate-format", + "Truth in Lending rule now available in easier-to-navigate format" + ] + ], + "author": { + "first_name": "Ross", + "last_name": "K", + "name": "k", + "url": "", + "slug": "k", + "nickname": "k", + "id": 59, + "description": "" + }, + "comments": [], + "content": "", + "comment_count": 0, + "categories": [], + "type": "view", + "status": "publish", + "hero": { + "attachments": [], + "excerpt": "", + "id": 63077, + "custom_fields": { + "mobile_image": [ + "/static/img/hero-small.png" + ], + "desktop_image": [ + "/static/img/hero-large.png" + ], + "background_color": [ + "rgb(51,126,125)" + ], + "related_post": [ + "two-years-of-standing-up-for-consumers", + "Announcements & updates" + ] + }, + "author": { + "first_name": "Scott", + "last_name": "C", + "name": "sc", + "url": "", + "slug": "sc", + "nickname": "sc", + "id": 211, + "description": "" + }, + "comments": [], + "content": "", + "comment_count": 0, + "categories": [], + "related_post": "two-years-of-standing-up-for-consumers", + "type": "cfpb_hero", + "status": "publish", + "parent": 0, + "tags": [], + "date": "2014-10-28 09:28:10", + "slug": "two-years-of-standing-up-for-consumers", + "comment_status": "closed", + "title_plain": "Two years of standing up for consumers", + "title": "Two years of standing up for consumers", + "modified": "2014-10-28 09:44:19", + "dek": "", + "order": 0 + }, + "parent": 0, + "tags": [], + "date": "2014-06-02 20:40:46", + "slug": "blog", + "comment_status": "closed", + "title_plain": "blog", + "title": "blog", + "modified": "2014-10-29 12:24:47", + "dek": "", + "_id": "blog", + "order": 0 + } +] \ No newline at end of file diff --git a/tests/test.py b/tests/test.py index 00bf7f08f0b..24817a5d144 100644 --- a/tests/test.py +++ b/tests/test.py @@ -1,8 +1,15 @@ import nose import os from nose.plugins.attrib import attr +from flask import Flask from selenose.cases import SeleniumTestCase + +from selenium import webdriver +from elasticsearch import Elasticsearch +from elasticsearch.client import IndicesClient + + from flask.ext.testing import LiveServerTestCase from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait @@ -12,20 +19,29 @@ from sheer.wsgi import app_with_config -class NewsroomTestCase(SeleniumTestCase, LiveServerTestCase): +class NewsroomTestCase(LiveServerTestCase): def create_app(self): # Setup server - config = {'debug': False, + config = {'debug': True, 'index': 'cfgov_test', 'elasticsearch': [{'host': 'localhost', 'port': 9200}], - 'location': os.getcwd()} + 'location': os.path.join(os.getcwd(), '..')} application = app_with_config(config) + # app = Flask(__name__) + # app.config['debug'] = True + # app.config['index'] = 'cfgov_test' + # app.config['elasticsearch'] = [{'host': 'localhost', 'port': 9200}] + # app.config['location'] = os.getcwd() + application.config['TESTING'] = True application.config['LIVESERVER_PORT'] = 7000 return application def setUp(self): - self.driver.get('http://refresh.demo.cfpb.gov/newsroom/') + es = Elasticsearch() + print "inner mapping here", IndicesClient(es).get_mapping(index='cfgov_test') + self.driver = webdriver.Chrome() + self.driver.get('http://localhost:7000/newsroom/') # self.filter_dropdown_button = self.driver.find_element_by_xpath('//button[contains(text(), "Filter posts")]') click_filter_posts(self) @@ -33,45 +49,48 @@ def test_filter_display_button(self): filter_options = self.driver.find_element_by_class_name('padded-container') assert filter_options.is_displayed() - @attr('checkbox') - def test_filter_checkboxes(self): - categoryList = ["Op-Ed", "Press Release", "Speech", "Testimony", "Blog"] - for cat in categoryList: - # use this after view changes value of checkbox input to 'Blog' - # checkbox = self.driver.find_element_by_xpath('//label/input[@value=\"'+ cat +'\"]/..') - checkbox = self.driver.find_element_by_xpath('//label/span[contains(text(), \"'+ cat +'\")]/..') - checkbox.click() - assert "is-checked" in checkbox.get_attribute('class') - checkbox.click() - assert "is-checkedFocus" in checkbox.get_attribute('class') + # @attr('checkbox') + # def test_filter_checkboxes(self): + # categoryList = ["Op-Ed", "Press Release", "Speech", "Testimony", "Blog"] + # for cat in categoryList: + # # use this after view changes value of checkbox input to 'Blog' + # # checkbox = self.driver.find_element_by_xpath('//label/input[@value=\"'+ cat +'\"]/..') + # checkbox = self.driver.find_element_by_xpath('//label/span[contains(text(), \"'+ cat +'\")]/..') + # checkbox.click() + # assert "is-checked" in checkbox.get_attribute('class') + # checkbox.click() + # assert "is-checkedFocus" in checkbox.get_attribute('class') + + # @attr('search') + # @attr('category') + # def test_filter_category_search(self): + # categoryList = ["Op-Ed", "Press Release", "Speech", "Testimony"] # No Blog posts yet so add in when data is there + # for cat in categoryList: + # click_filter_posts(self) + # # checkbox = self.driver.find_element_by_xpath('//label/span[contains(text(), \"'+ cat +'\")]/..') + # checkbox = WebDriverWait(self.driver, 10).until( + # ec.visibility_of_element_located((By.XPATH, '//label/span[contains(text(), \"'+ cat +'\")]/..')) + # ) + # checkbox.click() + # filter_results_button = WebDriverWait(self.driver, 10).until( + # ec.visibility_of_element_located((By.XPATH, '//input[@value="Apply filters"]')) + # ) + # filter_results_button.click() + # cat = coerce_category_for_dom(cat) + # cat_type_elem = WebDriverWait(self.driver, 10).until( + # ec.visibility_of_element_located((By.XPATH, '//a[@href="?filter_category='+ cat +'"]')) + # ) + # assert cat_type_elem + # click_filter_posts(self) + # cat = coerce_category_for_dom(cat) + # # checkbox = self.driver.find_element_by_xpath('//label/span[contains(text(), \"'+ cat +'\")]/..') + # checkbox = WebDriverWait(self.driver, 10).until( + # ec.visibility_of_element_located((By.XPATH, '//label/span[contains(text(), \"'+ cat +'\")]/..')) + # ) + # checkbox.click() - @attr('search') - @attr('category') - def test_filter_category_search(self): - categoryList = ["Op-Ed", "Press Release", "Speech", "Testimony"] # No Blog posts yet so add in when data is there - for cat in categoryList: - click_filter_posts(self) - # checkbox = self.driver.find_element_by_xpath('//label/span[contains(text(), \"'+ cat +'\")]/..') - checkbox = WebDriverWait(self.driver, 10).until( - ec.visibility_of_element_located((By.XPATH, '//label/span[contains(text(), \"'+ cat +'\")]/..')) - ) - checkbox.click() - filter_results_button = WebDriverWait(self.driver, 10).until( - ec.visibility_of_element_located((By.XPATH, '//input[@value="Apply filters"]')) - ) - filter_results_button.click() - cat = coerce_category_for_dom(cat) - cat_type_elem = WebDriverWait(self.driver, 10).until( - ec.visibility_of_element_located((By.XPATH, '//a[@href="?filter_category='+ cat +'"]')) - ) - assert cat_type_elem - click_filter_posts(self) - cat = coerce_category_for_dom(cat) - # checkbox = self.driver.find_element_by_xpath('//label/span[contains(text(), \"'+ cat +'\")]/..') - checkbox = WebDriverWait(self.driver, 10).until( - ec.visibility_of_element_located((By.XPATH, '//label/span[contains(text(), \"'+ cat +'\")]/..')) - ) - checkbox.click() + def tearDown(self): + self.driver.close() if __name__ == '__main__': nose.main() From 08fa7bd3a95948d1be735d1de1ab2c4aa19957c1 Mon Sep 17 00:00:00 2001 From: Dan Ford Date: Wed, 12 Nov 2014 11:23:10 -0500 Subject: [PATCH 04/17] added logging --- tests/__init__.py | 7 +++++++ tests/test.py | 5 ----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/__init__.py b/tests/__init__.py index 70ea45b08e1..b21c4187e8c 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,5 +1,6 @@ import os import json +import logging from elasticsearch import Elasticsearch from elasticsearch.client import IndicesClient @@ -9,6 +10,12 @@ def setup_package(): + logging.basicConfig() + logger = logging.getLogger("") + logger.setLevel(logging.DEBUG) + tracer = logging.getLogger('elasticsearch.trace') + tracer.setLevel(logging.DEBUG) + tracer.addHandler(logging.FileHandler('elasticsearch-py.txt')) es = Elasticsearch() if es.indices.exists(index_name): es.indices.delete(index_name) diff --git a/tests/test.py b/tests/test.py index 24817a5d144..cf7c79aab88 100644 --- a/tests/test.py +++ b/tests/test.py @@ -28,11 +28,6 @@ def create_app(self): 'elasticsearch': [{'host': 'localhost', 'port': 9200}], 'location': os.path.join(os.getcwd(), '..')} application = app_with_config(config) - # app = Flask(__name__) - # app.config['debug'] = True - # app.config['index'] = 'cfgov_test' - # app.config['elasticsearch'] = [{'host': 'localhost', 'port': 9200}] - # app.config['location'] = os.getcwd() application.config['TESTING'] = True application.config['LIVESERVER_PORT'] = 7000 return application From 9a71c3ebc28d55035b2518fb30e30a95746b4a9d Mon Sep 17 00:00:00 2001 From: Dan Ford Date: Fri, 14 Nov 2014 16:49:04 -0500 Subject: [PATCH 05/17] added watchroom fixture --- tests/__init__.py | 25 +++++++---- tests/fixtures/watchroom.json | 54 +++++++++++++++++++++++ tests/test.py | 83 +++++++++++++++++------------------ 3 files changed, 112 insertions(+), 50 deletions(-) create mode 100644 tests/fixtures/watchroom.json diff --git a/tests/__init__.py b/tests/__init__.py index b21c4187e8c..09ca09f83e6 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,6 +1,7 @@ import os import json import logging +import dateutil.parser from elasticsearch import Elasticsearch from elasticsearch.client import IndicesClient @@ -21,7 +22,7 @@ def setup_package(): es.indices.delete(index_name) es.indices.create(index=index_name) - newsroom_mapping = { "properties" : + posts_mapping = { "properties" : { "title" : {"type" : "string", "store" : "yes"}, "text" : {"type" : "string", "store" : "yes"}, @@ -41,14 +42,18 @@ def setup_package(): # Create the mappings es.indices.put_mapping(index=index_name, doc_type="newsroom", - body={"newsroom": newsroom_mapping}) + body={"newsroom": posts_mapping, + "watchroom": posts_mapping}) - newsroom_json = open(os.path.join(root, 'fixtures/newsroom.json')) + newsroom_json = open(os.path.join(root, 'tests/fixtures/newsroom.json')) newsroom = json.load(newsroom_json) - view_json = open(os.path.join(root, 'fixtures/views.json')) + view_json = open(os.path.join(root, 'tests/fixtures/views.json')) view = json.load(view_json) + watchroom_json = open(os.path.join(root, 'tests/fixtures/watchroom.json')) + watchroom = json.load(watchroom_json) + # Index the documents for document in newsroom: es.create(index=index_name, @@ -62,10 +67,14 @@ def setup_package(): id=document['_id'], body=document) - print "outer mapping here", IndicesClient(es).get_mapping(index='cfgov_test') + for document in watchroom: + es.create(index=index_name, + doc_type="newsroom", + id=document['_id'], + body=document) + def teardown_package(): - pass - # es = Elasticsearch() - # es.indices.delete(index_name) \ No newline at end of file + es = Elasticsearch() + es.indices.delete(index_name) \ No newline at end of file diff --git a/tests/fixtures/watchroom.json b/tests/fixtures/watchroom.json new file mode 100644 index 00000000000..140ffd31474 --- /dev/null +++ b/tests/fixtures/watchroom.json @@ -0,0 +1,54 @@ +[ +{ + "attachments": [], + "links": [ + [ + "http://www.google.com", + "Google" + ], + [ + "http://www.yahoo.com", + "Yahoo" + ], + [ + "http://www.facebook.com", + "Facebook" + ] + ], + "excerpt": "

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat […]

\n", + "id": 62449, + "custom_fields": { + "watchroom_data_2": [ + "http://www.facebook.com", + "Facebook" + ], + "watchroom_data_0": [ + "http://www.google.com", + "Google" + ], + "watchroom_data_1": [ + "http://www.yahoo.com", + "Yahoo" + ] + }, + "author": [ + "Mike" + ], + "content": "

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

\n", + "comment_count": 0, + "categories": [], + "type": "watchroom", + "status": "publish", + "parent": 0, + "tags": [], + "date": "2014-07-28T16:19:46Z", + "slug": "who-watches-the-watchroom", + "comment_status": "closed", + "title_plain": "Who watches the watchroom", + "title": "Who watches the watchroom", + "modified": "2014-08-13 13:36:30", + "dek": "", + "_id": "who-watches-the-watchroom", + "order": 0 +} +] \ No newline at end of file diff --git a/tests/test.py b/tests/test.py index cf7c79aab88..45c13baf3ca 100644 --- a/tests/test.py +++ b/tests/test.py @@ -26,7 +26,7 @@ def create_app(self): config = {'debug': True, 'index': 'cfgov_test', 'elasticsearch': [{'host': 'localhost', 'port': 9200}], - 'location': os.path.join(os.getcwd(), '..')} + 'location': os.getcwd()} application = app_with_config(config) application.config['TESTING'] = True application.config['LIVESERVER_PORT'] = 7000 @@ -34,55 +34,54 @@ def create_app(self): def setUp(self): es = Elasticsearch() - print "inner mapping here", IndicesClient(es).get_mapping(index='cfgov_test') self.driver = webdriver.Chrome() self.driver.get('http://localhost:7000/newsroom/') - # self.filter_dropdown_button = self.driver.find_element_by_xpath('//button[contains(text(), "Filter posts")]') + self.filter_dropdown_button = self.driver.find_element_by_xpath('//button[contains(text(), "Filter posts")]') click_filter_posts(self) def test_filter_display_button(self): filter_options = self.driver.find_element_by_class_name('padded-container') - assert filter_options.is_displayed() - # @attr('checkbox') - # def test_filter_checkboxes(self): - # categoryList = ["Op-Ed", "Press Release", "Speech", "Testimony", "Blog"] - # for cat in categoryList: - # # use this after view changes value of checkbox input to 'Blog' - # # checkbox = self.driver.find_element_by_xpath('//label/input[@value=\"'+ cat +'\"]/..') - # checkbox = self.driver.find_element_by_xpath('//label/span[contains(text(), \"'+ cat +'\")]/..') - # checkbox.click() - # assert "is-checked" in checkbox.get_attribute('class') - # checkbox.click() - # assert "is-checkedFocus" in checkbox.get_attribute('class') - # @attr('search') - # @attr('category') - # def test_filter_category_search(self): - # categoryList = ["Op-Ed", "Press Release", "Speech", "Testimony"] # No Blog posts yet so add in when data is there - # for cat in categoryList: - # click_filter_posts(self) - # # checkbox = self.driver.find_element_by_xpath('//label/span[contains(text(), \"'+ cat +'\")]/..') - # checkbox = WebDriverWait(self.driver, 10).until( - # ec.visibility_of_element_located((By.XPATH, '//label/span[contains(text(), \"'+ cat +'\")]/..')) - # ) - # checkbox.click() - # filter_results_button = WebDriverWait(self.driver, 10).until( - # ec.visibility_of_element_located((By.XPATH, '//input[@value="Apply filters"]')) - # ) - # filter_results_button.click() - # cat = coerce_category_for_dom(cat) - # cat_type_elem = WebDriverWait(self.driver, 10).until( - # ec.visibility_of_element_located((By.XPATH, '//a[@href="?filter_category='+ cat +'"]')) - # ) - # assert cat_type_elem - # click_filter_posts(self) - # cat = coerce_category_for_dom(cat) - # # checkbox = self.driver.find_element_by_xpath('//label/span[contains(text(), \"'+ cat +'\")]/..') - # checkbox = WebDriverWait(self.driver, 10).until( - # ec.visibility_of_element_located((By.XPATH, '//label/span[contains(text(), \"'+ cat +'\")]/..')) - # ) - # checkbox.click() + @attr('checkbox') + def test_filter_checkboxes(self): + categoryList = ["Op-Ed", "Press Release", "Speech", "Testimony", "Blog"] + for cat in categoryList: + # use this after view changes value of checkbox input to 'Blog' + # checkbox = self.driver.find_element_by_xpath('//label/input[@value=\"'+ cat +'\"]/..') + checkbox = self.driver.find_element_by_xpath('//label/span[contains(text(), \"'+ cat +'\")]/..') + checkbox.click() + assert "is-checked" in checkbox.get_attribute('class') + checkbox.click() + assert "is-checkedFocus" in checkbox.get_attribute('class') + + @attr('search') + @attr('category') + def test_filter_category_search(self): + categoryList = ["Op-Ed", "Press Release", "Speech", "Testimony"] # No Blog posts yet so add in when data is there + for cat in categoryList: + click_filter_posts(self) + # checkbox = self.driver.find_element_by_xpath('//label/span[contains(text(), \"'+ cat +'\")]/..') + checkbox = WebDriverWait(self.driver, 10).until( + ec.visibility_of_element_located((By.XPATH, '//label/span[contains(text(), \"'+ cat +'\")]/..')) + ) + checkbox.click() + filter_results_button = WebDriverWait(self.driver, 10).until( + ec.visibility_of_element_located((By.XPATH, '//input[@value="Apply filters"]')) + ) + filter_results_button.click() + cat = coerce_category_for_dom(cat) + cat_type_elem = WebDriverWait(self.driver, 10).until( + ec.visibility_of_element_located((By.XPATH, '//a[@href="?filter_category='+ cat +'"]')) + ) + assert cat_type_elem + click_filter_posts(self) + cat = coerce_category_for_dom(cat) + # checkbox = self.driver.find_element_by_xpath('//label/span[contains(text(), \"'+ cat +'\")]/..') + checkbox = WebDriverWait(self.driver, 10).until( + ec.visibility_of_element_located((By.XPATH, '//label/span[contains(text(), \"'+ cat +'\")]/..')) + ) + checkbox.click() def tearDown(self): self.driver.close() From 02cccc389d2398e9a7499ca917fe43424ab2e304 Mon Sep 17 00:00:00 2001 From: Dan Ford Date: Mon, 17 Nov 2014 14:13:32 -0500 Subject: [PATCH 06/17] refactored the mapping creation and document indexing --- tests/__init__.py | 81 ++++++++++++------------------------------- tests/test.py | 31 +++++++++-------- tests/test_helpers.py | 9 ----- 3 files changed, 40 insertions(+), 81 deletions(-) diff --git a/tests/__init__.py b/tests/__init__.py index 09ca09f83e6..a49f0c49303 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,80 +1,45 @@ import os import json -import logging -import dateutil.parser from elasticsearch import Elasticsearch -from elasticsearch.client import IndicesClient index_name = "cfgov_test" root = os.getcwd() - def setup_package(): - logging.basicConfig() - logger = logging.getLogger("") - logger.setLevel(logging.DEBUG) - tracer = logging.getLogger('elasticsearch.trace') - tracer.setLevel(logging.DEBUG) - tracer.addHandler(logging.FileHandler('elasticsearch-py.txt')) es = Elasticsearch() if es.indices.exists(index_name): es.indices.delete(index_name) es.indices.create(index=index_name) - posts_mapping = { "properties" : - { - "title" : {"type" : "string", "store" : "yes"}, - "text" : {"type" : "string", "store" : "yes"}, - "date" : {"type" : "date", "store": "yes"}, - "category" : {"type":"string", "index": "not_analyzed"}, - "author" : {"type":"string", "index":"not_analyzed"}, - "tags" : {"type":"string", "store": "yes", "index":"not_analyzed"}, - "excerpt" : {"type":"string", "store": "yes"}, - "custom_fields": { - "properties": { - "display_in_newsroom": {"type":"string", "index":"not_analyzed"} - } - } - } - } - # Create the mappings - es.indices.put_mapping(index=index_name, - doc_type="newsroom", - body={"newsroom": posts_mapping, - "watchroom": posts_mapping}) + create_mapping('newsroom', '_settings/posts_mappings.json') + create_mapping('watchroom', '_settings/posts_mappings.json') - newsroom_json = open(os.path.join(root, 'tests/fixtures/newsroom.json')) - newsroom = json.load(newsroom_json) - - view_json = open(os.path.join(root, 'tests/fixtures/views.json')) - view = json.load(view_json) + # Index the documents + index_documents('newsroom', 'tests/fixtures/newsroom.json') + index_documents('views', 'tests/fixtures/views.json') + index_documents('watchroom', 'tests/fixtures/watchroom.json') - watchroom_json = open(os.path.join(root, 'tests/fixtures/watchroom.json')) - watchroom = json.load(watchroom_json) +def teardown_package(): + es = Elasticsearch() + es.indices.delete(index_name) - # Index the documents - for document in newsroom: - es.create(index=index_name, - doc_type="newsroom", - id=document['_id'], - body=document) +def create_mapping(doc_type, mapping_json_path): + es = Elasticsearch() + mapping_json = open(os.path.join(root, mapping_json_path)) + mapping = json.load(mapping_json) + es.indices.put_mapping(index=index_name, + doc_type=doc_type, + body={doc_type: mapping}) - for document in view: - es.create(index=index_name, - doc_type="views", - id=document['_id'], - body=document) +def index_documents(doc_type, json_path): + es = Elasticsearch() + json_file = open(os.path.join(root, json_path)) + documents = json.load(json_file) - for document in watchroom: + for document in documents: es.create(index=index_name, - doc_type="newsroom", + doc_type=doc_type, id=document['_id'], - body=document) - - - -def teardown_package(): - es = Elasticsearch() - es.indices.delete(index_name) \ No newline at end of file + body=document) \ No newline at end of file diff --git a/tests/test.py b/tests/test.py index 45c13baf3ca..23952e8ba21 100644 --- a/tests/test.py +++ b/tests/test.py @@ -23,33 +23,36 @@ class NewsroomTestCase(LiveServerTestCase): def create_app(self): # Setup server - config = {'debug': True, + config = {'debug': False, 'index': 'cfgov_test', 'elasticsearch': [{'host': 'localhost', 'port': 9200}], 'location': os.getcwd()} application = app_with_config(config) - application.config['TESTING'] = True - application.config['LIVESERVER_PORT'] = 7000 + application.config['LIVESERVER_PORT'] = 31337 return application def setUp(self): - es = Elasticsearch() self.driver = webdriver.Chrome() - self.driver.get('http://localhost:7000/newsroom/') + self.driver.set_window_size(1400, 850) + self.driver.get('http://localhost:31337/newsroom/') self.filter_dropdown_button = self.driver.find_element_by_xpath('//button[contains(text(), "Filter posts")]') click_filter_posts(self) def test_filter_display_button(self): - filter_options = self.driver.find_element_by_class_name('padded-container') + filter_posts_display_button = self.driver.find_element_by_xpath( + '//button[contains(text(), "Filter posts")]' + ) + assert filter_posts_display_button.is_displayed() @attr('checkbox') def test_filter_checkboxes(self): - categoryList = ["Op-Ed", "Press Release", "Speech", "Testimony", "Blog"] - for cat in categoryList: + category_list = ["Op-Ed", "Press Release"] + for cat in category_list: + print cat # use this after view changes value of checkbox input to 'Blog' # checkbox = self.driver.find_element_by_xpath('//label/input[@value=\"'+ cat +'\"]/..') - checkbox = self.driver.find_element_by_xpath('//label/span[contains(text(), \"'+ cat +'\")]/..') + checkbox = self.driver.find_element_by_xpath('//label/span[contains(text(), "{0}")]/..'.format(cat)) checkbox.click() assert "is-checked" in checkbox.get_attribute('class') checkbox.click() @@ -58,12 +61,12 @@ def test_filter_checkboxes(self): @attr('search') @attr('category') def test_filter_category_search(self): - categoryList = ["Op-Ed", "Press Release", "Speech", "Testimony"] # No Blog posts yet so add in when data is there - for cat in categoryList: + category_list = ["Op-Ed", "Press Release"] + for cat in category_list: click_filter_posts(self) # checkbox = self.driver.find_element_by_xpath('//label/span[contains(text(), \"'+ cat +'\")]/..') checkbox = WebDriverWait(self.driver, 10).until( - ec.visibility_of_element_located((By.XPATH, '//label/span[contains(text(), \"'+ cat +'\")]/..')) + ec.visibility_of_element_located((By.XPATH, '//label/span[contains(text(), "{0}")]/..'.format(cat))) ) checkbox.click() filter_results_button = WebDriverWait(self.driver, 10).until( @@ -72,14 +75,14 @@ def test_filter_category_search(self): filter_results_button.click() cat = coerce_category_for_dom(cat) cat_type_elem = WebDriverWait(self.driver, 10).until( - ec.visibility_of_element_located((By.XPATH, '//a[@href="?filter_category='+ cat +'"]')) + ec.visibility_of_element_located((By.XPATH, '//a[@href="?filter_category={0}"]'.format(cat))) ) assert cat_type_elem click_filter_posts(self) cat = coerce_category_for_dom(cat) # checkbox = self.driver.find_element_by_xpath('//label/span[contains(text(), \"'+ cat +'\")]/..') checkbox = WebDriverWait(self.driver, 10).until( - ec.visibility_of_element_located((By.XPATH, '//label/span[contains(text(), \"'+ cat +'\")]/..')) + ec.visibility_of_element_located((By.XPATH, '//label/span[contains(text(), "{0}")]/..'.format(cat))) ) checkbox.click() diff --git a/tests/test_helpers.py b/tests/test_helpers.py index 898e2e9bcae..dce5e0b313a 100644 --- a/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -1,12 +1,3 @@ -# import nose - -# from selenose.cases import SeleniumTestCase -# from nose.plugins.attrib import attr -# from selenium.webdriver.common.by import By -# from selenium.webdriver.support.ui import WebDriverWait -# from selenium.webdriver.support import expected_conditions as ec - - def click_filter_posts(test): test.filter_dropdown_button = test.driver.find_element_by_xpath('//button[contains(text(), "Filter posts")]') if test.filter_dropdown_button.get_attribute('aria-pressed') == 'false': From 611af4b7788d6b5725139395ecf978aa3f69600d Mon Sep 17 00:00:00 2001 From: Dan Ford Date: Tue, 18 Nov 2014 10:49:45 -0500 Subject: [PATCH 07/17] merging in more tests' --- tests/setup.cfg | 7 --- tests/test.py | 135 ++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 124 insertions(+), 18 deletions(-) delete mode 100644 tests/setup.cfg diff --git a/tests/setup.cfg b/tests/setup.cfg deleted file mode 100644 index 402c5270ea5..00000000000 --- a/tests/setup.cfg +++ /dev/null @@ -1,7 +0,0 @@ -[nosetests] -with-selenium-driver = true -selenium-driver = chrome - -[selenium-driver:chrome] -webdriver = chrome - diff --git a/tests/test.py b/tests/test.py index 23952e8ba21..16e0f858f17 100644 --- a/tests/test.py +++ b/tests/test.py @@ -3,8 +3,6 @@ from nose.plugins.attrib import attr from flask import Flask -from selenose.cases import SeleniumTestCase - from selenium import webdriver from elasticsearch import Elasticsearch from elasticsearch.client import IndicesClient @@ -12,8 +10,9 @@ from flask.ext.testing import LiveServerTestCase from selenium.webdriver.common.by import By +from selenium.webdriver.common.keys import Keys from selenium.webdriver.support.ui import WebDriverWait -from selenium.webdriver.support import expected_conditions as ec +from selenium.webdriver.support import expected_conditions as EC from .test_helpers import * @@ -49,10 +48,8 @@ def test_filter_display_button(self): def test_filter_checkboxes(self): category_list = ["Op-Ed", "Press Release"] for cat in category_list: - print cat - # use this after view changes value of checkbox input to 'Blog' - # checkbox = self.driver.find_element_by_xpath('//label/input[@value=\"'+ cat +'\"]/..') - checkbox = self.driver.find_element_by_xpath('//label/span[contains(text(), "{0}")]/..'.format(cat)) + checkbox = self.driver.find_element_by_xpath( + '//label/span[contains(text(), "{0}")]/..'.format(cat)) checkbox.click() assert "is-checked" in checkbox.get_attribute('class') checkbox.click() @@ -66,26 +63,142 @@ def test_filter_category_search(self): click_filter_posts(self) # checkbox = self.driver.find_element_by_xpath('//label/span[contains(text(), \"'+ cat +'\")]/..') checkbox = WebDriverWait(self.driver, 10).until( - ec.visibility_of_element_located((By.XPATH, '//label/span[contains(text(), "{0}")]/..'.format(cat))) + EC.visibility_of_element_located(( + By.XPATH, '//label/span[contains(text(), "{0}")]/..'.format(cat))) ) checkbox.click() filter_results_button = WebDriverWait(self.driver, 10).until( - ec.visibility_of_element_located((By.XPATH, '//input[@value="Apply filters"]')) + EC.visibility_of_element_located(( + By.XPATH, '//input[@value="Apply filters"]')) ) filter_results_button.click() cat = coerce_category_for_dom(cat) cat_type_elem = WebDriverWait(self.driver, 10).until( - ec.visibility_of_element_located((By.XPATH, '//a[@href="?filter_category={0}"]'.format(cat))) + EC.visibility_of_element_located(( + By.XPATH, '//a[@href="?filter_category={0}"]'.format(cat))) ) assert cat_type_elem click_filter_posts(self) cat = coerce_category_for_dom(cat) # checkbox = self.driver.find_element_by_xpath('//label/span[contains(text(), \"'+ cat +'\")]/..') checkbox = WebDriverWait(self.driver, 10).until( - ec.visibility_of_element_located((By.XPATH, '//label/span[contains(text(), "{0}")]/..'.format(cat))) + EC.visibility_of_element_located(( + By.XPATH, '//label/span[contains(text(), "{0}")]/..'.format(cat))) ) checkbox.click() + # @attr('search') + # @attr('topics') + # def test_filter_topic_search(self): + # click_filter_posts_dropdown(self) + # # topic_input = self.driver.find_element_by_xpath('//input[@value="Search for topics"]') + # topic_input = WebDriverWait(self.driver, 10).until( + # EC.visibility_of_element_located(( + # By.XPATH, '//input[@value="Search for topics"]' + # )) + # ) + # topic_input.click() + # topic_input.send_keys("ban") + # topic_choice_results = self.driver.find_element_by_xpath( + # '//div[@id="filter_tags_chosen"]/div/ul[@class="chosen-results"]' + # ) + # assert topic_choice_results.is_displayed() + # # choice = self.driver.find_element_by_xpath('//div[@id="filter_tags_chosen"]/div[@class="chosen-drop"]/ul[@class="chosen-results"]/li/em[contains(text(),"Ban")]/..') + # choice = WebDriverWait(self.driver, 10).until( + # EC.visibility_of_element_located(( + # By.XPATH, + # '//div[@id="filter_tags_chosen"]/div/ul[@class="chosen-results"]/li/em[contains(text(),"Ban")]/..' + # )) + # ) + # choice.click() + # topic_elem = self.driver.find_element_by_xpath( + # '//div[@id="filter_tags_chosen"]/ul/li/span[contains(text(), "Banking")]' + # ) + # assert topic_elem + + # @attr('search') + # @attr('authors') + # def test_filter_author_search(self): + # author_input = WebDriverWait(self.driver, 10).until( + # EC.visibility_of_element_located(( + # By.XPATH, '//input[@value="Search for authors"]' + # )) + # ) + # author_input.click() + # author_input.send_keys("dan") + # author_choice_results = self.driver.find_element_by_xpath( + # '//div[@id="filter_author_chosen"]/div/ul[@class="chosen-results"]' + # ) + # assert author_choice_results.is_displayed() + # choice = WebDriverWait(self.driver, 10).until( + # EC.visibility_of_element_located(( + # By.XPATH, + # '//div[@id="filter_author_chosen"]/div/ul[@class="chosen-results"]/li/em[contains(text(),"Dan")]/..' + # )) + # ) + # choice.click() + # author_elem = self.driver.find_element_by_xpath( + # '//div[@id="filter_author_chosen"]/ul/li/span[contains(text(), "Dan Sokolov")]' + # ) + # assert author_elem + # filter_results_button = WebDriverWait(self.driver, 10).until( + # EC.visibility_of_element_located(( + # By.XPATH, '//input[@value="Apply filters"]' + # )) + # ) + # filter_results_button.click() + # author = WebDriverWait(self.driver, 10).until( + # EC.visibility_of_element_located(( + # By.XPATH, '//p[@class="summary_byline"][contains(text(), "Dan")]' + # )) + # ) + # assert author + + # @attr('search') + # @attr('date') + # def test_filter_date_search(self): + # # scroll(self.driver) + # WebDriverWait(self.driver, 10).until( + # EC.visibility_of_element_located(( + # By.XPATH, + # '//div[@id="filter_range_date_gte-replacement"]/div[1]' + # )) + # ) + + # # click 'from month' + # self.driver.find_element_by_xpath( + # '//select[@id="filter_from_month"]/option[@value="01"]' + # ).click() + # # click 'from year' + # self.driver.find_element_by_xpath( + # '//select[@id="filter_from_year"]/option[@value="2013"]' + # ).click() + + # # click 'to month' + # self.driver.find_element_by_xpath( + # '//select[@id="filter_to_month"]/option[@value="02"]' + # ).click() + # # click 'to year' + # self.driver.find_element_by_xpath( + # '//select[@id="filter_to_year"]/option[@value="2013"]' + # ).click() + + # # Search + # WebDriverWait(self.driver, 10).until( + # EC.visibility_of_element_located(( + # By.XPATH, '//input[@value="Apply filters"]' + # )) + # ).click() + + # filtered_article_date = WebDriverWait(self.driver, 10).until( + # EC.visibility_of_element_located(( + # By.XPATH, + # '//div[@id="pagination_content"]/article[1]/div[1]/span[1]' + # )) + # ) + # filtered = 'jan' in filtered_article_date.text.lower() or 'feb' in filtered_article_date.text.lower() + # assert filtered + def tearDown(self): self.driver.close() From a71989d4f75d3106e18652368dd9a5066c0f5a04 Mon Sep 17 00:00:00 2001 From: Dan Ford Date: Thu, 20 Nov 2014 13:48:22 -0500 Subject: [PATCH 08/17] removed some unnecessary reqs --- tests/requirements.txt | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/requirements.txt b/tests/requirements.txt index 92ff560aafe..02a764060a8 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -1,5 +1,2 @@ -nose==1.3.4 selenium==2.44.0 -selenose==1.3 -wsgiref==0.1.2 Flask-Testing==0.4.2 From b30a269f10022f7c8e87061047cb8e67561b1bf6 Mon Sep 17 00:00:00 2001 From: Dan Ford Date: Thu, 20 Nov 2014 13:58:10 -0500 Subject: [PATCH 09/17] added sheer as a requirement --- tests/requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/requirements.txt b/tests/requirements.txt index 02a764060a8..f9f5f972418 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -1,2 +1,3 @@ selenium==2.44.0 Flask-Testing==0.4.2 +-e git+https://github.com/cfpb/sheer.git#egg=sheer From 8cf2cc7ddc44e182080bfce3f499217c4cb177b5 Mon Sep 17 00:00:00 2001 From: Dan Ford Date: Thu, 20 Nov 2014 16:02:41 -0500 Subject: [PATCH 10/17] updated README --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 246a08b15c7..7e2ec65d666 100755 --- a/README.md +++ b/README.md @@ -59,6 +59,12 @@ Since cfgov-refresh is based off of cf-demo we encourage you to start with the [cf-demo docs](http://cfpb.github.io/capital-framework/cf-demo/). _More specific cfgov-refresh docs are coming soon._ +### Tests + +To run browser tests, you'll need to perform the following steps: +1. Download the latest [Chromedriver](http://chromedriver.storage.googleapis.com/index.html) binary and put it somehwere on your path (e.g. /path/to/your/venv/bin) +2. `pip install -r tests/requirements.txt` +3. `nosetests -x -v` ## How this repo is versioned From a7d982a0d423fb755e0664271829b6475a0d2f57 Mon Sep 17 00:00:00 2001 From: Dan Ford Date: Fri, 21 Nov 2014 10:57:58 -0500 Subject: [PATCH 11/17] fixed up some tests, moved to _tests/ --- {tests => _tests}/__init__.py | 6 +- {tests => _tests}/fixtures/newsroom.json | 0 {tests => _tests}/fixtures/views.json | 0 {tests => _tests}/fixtures/watchroom.json | 0 {tests => _tests}/requirements.txt | 0 _tests/test.py | 201 +++++++++++++++++++++ {tests => _tests}/test_helpers.py | 0 tests/test.py | 206 ---------------------- 8 files changed, 204 insertions(+), 209 deletions(-) rename {tests => _tests}/__init__.py (86%) rename {tests => _tests}/fixtures/newsroom.json (100%) rename {tests => _tests}/fixtures/views.json (100%) rename {tests => _tests}/fixtures/watchroom.json (100%) rename {tests => _tests}/requirements.txt (100%) create mode 100644 _tests/test.py rename {tests => _tests}/test_helpers.py (100%) delete mode 100644 tests/test.py diff --git a/tests/__init__.py b/_tests/__init__.py similarity index 86% rename from tests/__init__.py rename to _tests/__init__.py index a49f0c49303..f7f3d743eab 100644 --- a/tests/__init__.py +++ b/_tests/__init__.py @@ -17,9 +17,9 @@ def setup_package(): create_mapping('watchroom', '_settings/posts_mappings.json') # Index the documents - index_documents('newsroom', 'tests/fixtures/newsroom.json') - index_documents('views', 'tests/fixtures/views.json') - index_documents('watchroom', 'tests/fixtures/watchroom.json') + index_documents('newsroom', '_tests/fixtures/newsroom.json') + index_documents('views', '_tests/fixtures/views.json') + index_documents('watchroom', '_tests/fixtures/watchroom.json') def teardown_package(): es = Elasticsearch() diff --git a/tests/fixtures/newsroom.json b/_tests/fixtures/newsroom.json similarity index 100% rename from tests/fixtures/newsroom.json rename to _tests/fixtures/newsroom.json diff --git a/tests/fixtures/views.json b/_tests/fixtures/views.json similarity index 100% rename from tests/fixtures/views.json rename to _tests/fixtures/views.json diff --git a/tests/fixtures/watchroom.json b/_tests/fixtures/watchroom.json similarity index 100% rename from tests/fixtures/watchroom.json rename to _tests/fixtures/watchroom.json diff --git a/tests/requirements.txt b/_tests/requirements.txt similarity index 100% rename from tests/requirements.txt rename to _tests/requirements.txt diff --git a/_tests/test.py b/_tests/test.py new file mode 100644 index 00000000000..f34d00c8013 --- /dev/null +++ b/_tests/test.py @@ -0,0 +1,201 @@ +import nose +import os +from nose.plugins.attrib import attr +from flask import Flask + +from selenium import webdriver +from elasticsearch import Elasticsearch +from elasticsearch.client import IndicesClient + + +from flask.ext.testing import LiveServerTestCase +from selenium.webdriver.common.by import By +from selenium.webdriver.common.keys import Keys +from selenium.webdriver.support.ui import WebDriverWait +from selenium.webdriver.support import expected_conditions as EC + +from .test_helpers import * + +from sheer.wsgi import app_with_config + +class NewsroomTestCase(LiveServerTestCase): + + def create_app(self): + # Setup server + config = {'debug': False, + 'index': 'cfgov_test', + 'elasticsearch': [{'host': 'localhost', 'port': 9200}], + 'location': os.getcwd()} + application = app_with_config(config) + application.config['LIVESERVER_PORT'] = 31337 + return application + + def setUp(self): + self.driver = webdriver.Chrome() + self.driver.set_window_size(1400, 850) + self.driver.get('http://localhost:31337/newsroom/') + self.filter_dropdown_button = self.driver.find_element_by_xpath('//button[contains(text(), "Filter posts")]') + click_filter_posts(self) + + def test_filter_display_button(self): + filter_posts_display_button = self.driver.find_element_by_xpath( + '//button[contains(text(), "Filter posts")]' + ) + assert filter_posts_display_button.is_displayed() + + + @attr('checkbox') + def test_filter_checkboxes(self): + category_list = ["Op-Ed", "Press Release"] + for cat in category_list: + checkbox = self.driver.find_element_by_xpath( + '//label/span[contains(text(), "{0}")]/..'.format(cat)) + checkbox.click() + assert "is-checked" in checkbox.get_attribute('class') + checkbox.click() + assert "is-checkedFocus" in checkbox.get_attribute('class') + + @attr('search') + @attr('category') + def test_filter_category_search(self): + category_list = ["Op-Ed", "Press Release"] + for cat in category_list: + click_filter_posts(self) + checkbox = WebDriverWait(self.driver, 10).until( + EC.visibility_of_element_located(( + By.XPATH, '//label/span[contains(text(), "{0}")]/..'.format(cat))) + ) + checkbox.click() + filter_results_button = WebDriverWait(self.driver, 10).until( + EC.visibility_of_element_located(( + By.XPATH, '//input[@value="Apply filters"]')) + ) + filter_results_button.click() + cat = coerce_category_for_dom(cat) + cat_type_elem = WebDriverWait(self.driver, 10).until( + EC.visibility_of_element_located(( + By.XPATH, '//a[@href="?filter_category={0}"]'.format(cat))) + ) + assert cat_type_elem + click_filter_posts(self) + cat = coerce_category_for_dom(cat) + checkbox = WebDriverWait(self.driver, 10).until( + EC.visibility_of_element_located(( + By.XPATH, '//label/span[contains(text(), "{0}")]/..'.format(cat))) + ) + checkbox.click() + + @attr('search') + @attr('topics') + def test_filter_topic_search(self): + topic_input = WebDriverWait(self.driver, 10).until( + EC.visibility_of_element_located(( + By.XPATH, '//input[@value="Search for topics"]' + )) + ) + topic_input.click() + topic_input.send_keys("for") + topic_choice_results = self.driver.find_element_by_xpath( + '//div[@id="filter_tags_chosen"]/div/ul[@class="chosen-results"]' + ) + assert topic_choice_results.is_displayed() + choice = WebDriverWait(self.driver, 10).until( + EC.visibility_of_element_located(( + By.XPATH, + '//div[@id="filter_tags_chosen"]/div/ul[@class="chosen-results"]/li/em[contains(text(),"For")]/..' + )) + ) + choice.click() + topic_elem = self.driver.find_element_by_xpath( + '//div[@id="filter_tags_chosen"]/ul/li/span[contains(text(), "Foreclosure")]' + ) + assert topic_elem + + @attr('search') + @attr('authors') + def test_filter_author_search(self): + author_input = WebDriverWait(self.driver, 10).until( + EC.visibility_of_element_located(( + By.XPATH, '//input[@value="Search for authors"]' + )) + ) + author_input.click() + author_input.send_keys("bat") + author_choice_results = self.driver.find_element_by_xpath( + '//div[@id="filter_author_chosen"]/div/ul[@class="chosen-results"]' + ) + assert author_choice_results.is_displayed() + choice = WebDriverWait(self.driver, 10).until( + EC.visibility_of_element_located(( + By.XPATH, + '//div[@id="filter_author_chosen"]/div/ul[@class="chosen-results"]/li/em[contains(text(),"Bat")]/..' + )) + ) + choice.click() + author_elem = self.driver.find_element_by_xpath( + '//div[@id="filter_author_chosen"]/ul/li/span[contains(text(), "Batman")]' + ) + assert author_elem + filter_results_button = WebDriverWait(self.driver, 10).until( + EC.visibility_of_element_located(( + By.XPATH, '//input[@value="Apply filters"]' + )) + ) + filter_results_button.click() + author = WebDriverWait(self.driver, 10).until( + EC.visibility_of_element_located(( + By.XPATH, '//p[@class="summary_byline"][contains(text(), "Bat")]' + )) + ) + assert author + + @attr('search') + @attr('date') + def test_filter_date_search(self): + # scroll(self.driver) + WebDriverWait(self.driver, 10).until( + EC.visibility_of_element_located(( + By.XPATH, + '//div[@id="filter_range_date_gte-replacement"]/div[1]' + )) + ) + + # click 'from month' + self.driver.find_element_by_xpath( + '//select[@id="filter_from_month"]/option[@value="01"]' + ).click() + # click 'from year' + self.driver.find_element_by_xpath( + '//select[@id="filter_from_year"]/option[@value="2013"]' + ).click() + + # click 'to month' + self.driver.find_element_by_xpath( + '//select[@id="filter_to_month"]/option[@value="02"]' + ).click() + # click 'to year' + self.driver.find_element_by_xpath( + '//select[@id="filter_to_year"]/option[@value="2013"]' + ).click() + + # Search + WebDriverWait(self.driver, 10).until( + EC.visibility_of_element_located(( + By.XPATH, '//input[@value="Apply filters"]' + )) + ).click() + + filtered_article_date = WebDriverWait(self.driver, 10).until( + EC.visibility_of_element_located(( + By.XPATH, + '//div[@id="pagination_content"]/article[1]/div[1]/span[1]' + )) + ) + filtered = 'jan' in filtered_article_date.text.lower() or 'feb' in filtered_article_date.text.lower() + assert filtered + + def tearDown(self): + self.driver.close() + +if __name__ == '__main__': + nose.main() diff --git a/tests/test_helpers.py b/_tests/test_helpers.py similarity index 100% rename from tests/test_helpers.py rename to _tests/test_helpers.py diff --git a/tests/test.py b/tests/test.py deleted file mode 100644 index 16e0f858f17..00000000000 --- a/tests/test.py +++ /dev/null @@ -1,206 +0,0 @@ -import nose -import os -from nose.plugins.attrib import attr -from flask import Flask - -from selenium import webdriver -from elasticsearch import Elasticsearch -from elasticsearch.client import IndicesClient - - -from flask.ext.testing import LiveServerTestCase -from selenium.webdriver.common.by import By -from selenium.webdriver.common.keys import Keys -from selenium.webdriver.support.ui import WebDriverWait -from selenium.webdriver.support import expected_conditions as EC - -from .test_helpers import * - -from sheer.wsgi import app_with_config - -class NewsroomTestCase(LiveServerTestCase): - - def create_app(self): - # Setup server - config = {'debug': False, - 'index': 'cfgov_test', - 'elasticsearch': [{'host': 'localhost', 'port': 9200}], - 'location': os.getcwd()} - application = app_with_config(config) - application.config['LIVESERVER_PORT'] = 31337 - return application - - def setUp(self): - self.driver = webdriver.Chrome() - self.driver.set_window_size(1400, 850) - self.driver.get('http://localhost:31337/newsroom/') - self.filter_dropdown_button = self.driver.find_element_by_xpath('//button[contains(text(), "Filter posts")]') - click_filter_posts(self) - - def test_filter_display_button(self): - filter_posts_display_button = self.driver.find_element_by_xpath( - '//button[contains(text(), "Filter posts")]' - ) - assert filter_posts_display_button.is_displayed() - - - @attr('checkbox') - def test_filter_checkboxes(self): - category_list = ["Op-Ed", "Press Release"] - for cat in category_list: - checkbox = self.driver.find_element_by_xpath( - '//label/span[contains(text(), "{0}")]/..'.format(cat)) - checkbox.click() - assert "is-checked" in checkbox.get_attribute('class') - checkbox.click() - assert "is-checkedFocus" in checkbox.get_attribute('class') - - @attr('search') - @attr('category') - def test_filter_category_search(self): - category_list = ["Op-Ed", "Press Release"] - for cat in category_list: - click_filter_posts(self) - # checkbox = self.driver.find_element_by_xpath('//label/span[contains(text(), \"'+ cat +'\")]/..') - checkbox = WebDriverWait(self.driver, 10).until( - EC.visibility_of_element_located(( - By.XPATH, '//label/span[contains(text(), "{0}")]/..'.format(cat))) - ) - checkbox.click() - filter_results_button = WebDriverWait(self.driver, 10).until( - EC.visibility_of_element_located(( - By.XPATH, '//input[@value="Apply filters"]')) - ) - filter_results_button.click() - cat = coerce_category_for_dom(cat) - cat_type_elem = WebDriverWait(self.driver, 10).until( - EC.visibility_of_element_located(( - By.XPATH, '//a[@href="?filter_category={0}"]'.format(cat))) - ) - assert cat_type_elem - click_filter_posts(self) - cat = coerce_category_for_dom(cat) - # checkbox = self.driver.find_element_by_xpath('//label/span[contains(text(), \"'+ cat +'\")]/..') - checkbox = WebDriverWait(self.driver, 10).until( - EC.visibility_of_element_located(( - By.XPATH, '//label/span[contains(text(), "{0}")]/..'.format(cat))) - ) - checkbox.click() - - # @attr('search') - # @attr('topics') - # def test_filter_topic_search(self): - # click_filter_posts_dropdown(self) - # # topic_input = self.driver.find_element_by_xpath('//input[@value="Search for topics"]') - # topic_input = WebDriverWait(self.driver, 10).until( - # EC.visibility_of_element_located(( - # By.XPATH, '//input[@value="Search for topics"]' - # )) - # ) - # topic_input.click() - # topic_input.send_keys("ban") - # topic_choice_results = self.driver.find_element_by_xpath( - # '//div[@id="filter_tags_chosen"]/div/ul[@class="chosen-results"]' - # ) - # assert topic_choice_results.is_displayed() - # # choice = self.driver.find_element_by_xpath('//div[@id="filter_tags_chosen"]/div[@class="chosen-drop"]/ul[@class="chosen-results"]/li/em[contains(text(),"Ban")]/..') - # choice = WebDriverWait(self.driver, 10).until( - # EC.visibility_of_element_located(( - # By.XPATH, - # '//div[@id="filter_tags_chosen"]/div/ul[@class="chosen-results"]/li/em[contains(text(),"Ban")]/..' - # )) - # ) - # choice.click() - # topic_elem = self.driver.find_element_by_xpath( - # '//div[@id="filter_tags_chosen"]/ul/li/span[contains(text(), "Banking")]' - # ) - # assert topic_elem - - # @attr('search') - # @attr('authors') - # def test_filter_author_search(self): - # author_input = WebDriverWait(self.driver, 10).until( - # EC.visibility_of_element_located(( - # By.XPATH, '//input[@value="Search for authors"]' - # )) - # ) - # author_input.click() - # author_input.send_keys("dan") - # author_choice_results = self.driver.find_element_by_xpath( - # '//div[@id="filter_author_chosen"]/div/ul[@class="chosen-results"]' - # ) - # assert author_choice_results.is_displayed() - # choice = WebDriverWait(self.driver, 10).until( - # EC.visibility_of_element_located(( - # By.XPATH, - # '//div[@id="filter_author_chosen"]/div/ul[@class="chosen-results"]/li/em[contains(text(),"Dan")]/..' - # )) - # ) - # choice.click() - # author_elem = self.driver.find_element_by_xpath( - # '//div[@id="filter_author_chosen"]/ul/li/span[contains(text(), "Dan Sokolov")]' - # ) - # assert author_elem - # filter_results_button = WebDriverWait(self.driver, 10).until( - # EC.visibility_of_element_located(( - # By.XPATH, '//input[@value="Apply filters"]' - # )) - # ) - # filter_results_button.click() - # author = WebDriverWait(self.driver, 10).until( - # EC.visibility_of_element_located(( - # By.XPATH, '//p[@class="summary_byline"][contains(text(), "Dan")]' - # )) - # ) - # assert author - - # @attr('search') - # @attr('date') - # def test_filter_date_search(self): - # # scroll(self.driver) - # WebDriverWait(self.driver, 10).until( - # EC.visibility_of_element_located(( - # By.XPATH, - # '//div[@id="filter_range_date_gte-replacement"]/div[1]' - # )) - # ) - - # # click 'from month' - # self.driver.find_element_by_xpath( - # '//select[@id="filter_from_month"]/option[@value="01"]' - # ).click() - # # click 'from year' - # self.driver.find_element_by_xpath( - # '//select[@id="filter_from_year"]/option[@value="2013"]' - # ).click() - - # # click 'to month' - # self.driver.find_element_by_xpath( - # '//select[@id="filter_to_month"]/option[@value="02"]' - # ).click() - # # click 'to year' - # self.driver.find_element_by_xpath( - # '//select[@id="filter_to_year"]/option[@value="2013"]' - # ).click() - - # # Search - # WebDriverWait(self.driver, 10).until( - # EC.visibility_of_element_located(( - # By.XPATH, '//input[@value="Apply filters"]' - # )) - # ).click() - - # filtered_article_date = WebDriverWait(self.driver, 10).until( - # EC.visibility_of_element_located(( - # By.XPATH, - # '//div[@id="pagination_content"]/article[1]/div[1]/span[1]' - # )) - # ) - # filtered = 'jan' in filtered_article_date.text.lower() or 'feb' in filtered_article_date.text.lower() - # assert filtered - - def tearDown(self): - self.driver.close() - -if __name__ == '__main__': - nose.main() From 9a4a2fc1bc7c81eb652fca5d767e7f96592212fd Mon Sep 17 00:00:00 2001 From: Dan Ford Date: Fri, 21 Nov 2014 14:08:24 -0500 Subject: [PATCH 12/17] updated README --- README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7e2ec65d666..4949ef0863e 100755 --- a/README.md +++ b/README.md @@ -62,9 +62,11 @@ _More specific cfgov-refresh docs are coming soon._ ### Tests To run browser tests, you'll need to perform the following steps: -1. Download the latest [Chromedriver](http://chromedriver.storage.googleapis.com/index.html) binary and put it somehwere on your path (e.g. /path/to/your/venv/bin) -2. `pip install -r tests/requirements.txt` -3. `nosetests -x -v` +1. Install chromedriver: +* Mac: `brew install chromedriver` +* Manual (Linux/Mac): Download the latest [Chromedriver](http://chromedriver.storage.googleapis.com/index.html) binary and put it somehwere on your path (e.g. /path/to/your/venv/bin) +2. `pip install -r _tests/requirements.txt` +3. `nosetests -x -v _tests` ## How this repo is versioned From f666fda1bb90ea5ad3bd7460f72799cfc18e7f2a Mon Sep 17 00:00:00 2001 From: Dan Ford Date: Fri, 21 Nov 2014 14:11:34 -0500 Subject: [PATCH 13/17] updated README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4949ef0863e..ce697220e70 100755 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ To run browser tests, you'll need to perform the following steps: * Mac: `brew install chromedriver` * Manual (Linux/Mac): Download the latest [Chromedriver](http://chromedriver.storage.googleapis.com/index.html) binary and put it somehwere on your path (e.g. /path/to/your/venv/bin) 2. `pip install -r _tests/requirements.txt` -3. `nosetests -x -v _tests` +3. `nosetests -v _tests` ## How this repo is versioned From b0f6b9946927dd4340411a2074e69972ff668b46 Mon Sep 17 00:00:00 2001 From: Dan Ford Date: Fri, 21 Nov 2014 14:25:01 -0500 Subject: [PATCH 14/17] README formatting --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ce697220e70..d40a7e1de14 100755 --- a/README.md +++ b/README.md @@ -63,8 +63,8 @@ _More specific cfgov-refresh docs are coming soon._ To run browser tests, you'll need to perform the following steps: 1. Install chromedriver: -* Mac: `brew install chromedriver` -* Manual (Linux/Mac): Download the latest [Chromedriver](http://chromedriver.storage.googleapis.com/index.html) binary and put it somehwere on your path (e.g. /path/to/your/venv/bin) + * Mac: `brew install chromedriver` + * Manual (Linux/Mac): Download the latest [Chromedriver](http://chromedriver.storage.googleapis.com/index.html) binary and put it somehwere on your path (e.g. /path/to/your/venv/bin) 2. `pip install -r _tests/requirements.txt` 3. `nosetests -v _tests` From c967f113aa3f8923ad34215faa1cb4fb21068cb8 Mon Sep 17 00:00:00 2001 From: Dan Ford Date: Fri, 21 Nov 2014 14:52:54 -0500 Subject: [PATCH 15/17] minor fixes to tests --- _tests/test.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/_tests/test.py b/_tests/test.py index f34d00c8013..2a315003ecf 100644 --- a/_tests/test.py +++ b/_tests/test.py @@ -48,8 +48,13 @@ def test_filter_display_button(self): def test_filter_checkboxes(self): category_list = ["Op-Ed", "Press Release"] for cat in category_list: - checkbox = self.driver.find_element_by_xpath( - '//label/span[contains(text(), "{0}")]/..'.format(cat)) + checkbox = WebDriverWait(self.driver, 10).until( + EC.visibility_of_element_located(( + By.XPATH, '//label/span[contains(text(), "{0}")]/..'.format(cat) + )) + ) + # checkbox = self.driver.find_element_by_xpath( + # '//label/span[contains(text(), "{0}")]/..'.format(cat)) checkbox.click() assert "is-checked" in checkbox.get_attribute('class') checkbox.click() @@ -166,7 +171,7 @@ def test_filter_date_search(self): ).click() # click 'from year' self.driver.find_element_by_xpath( - '//select[@id="filter_from_year"]/option[@value="2013"]' + '//select[@id="filter_from_year"]/option[@value="2011"]' ).click() # click 'to month' @@ -175,7 +180,7 @@ def test_filter_date_search(self): ).click() # click 'to year' self.driver.find_element_by_xpath( - '//select[@id="filter_to_year"]/option[@value="2013"]' + '//select[@id="filter_to_year"]/option[@value="2011"]' ).click() # Search From 01abe84b74044d7254bce9aa271981e804ce58c9 Mon Sep 17 00:00:00 2001 From: Dan Ford Date: Fri, 21 Nov 2014 15:34:42 -0500 Subject: [PATCH 16/17] upped WebDriverWait times --- _tests/test.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/_tests/test.py b/_tests/test.py index 2a315003ecf..c3a7261b24b 100644 --- a/_tests/test.py +++ b/_tests/test.py @@ -48,7 +48,7 @@ def test_filter_display_button(self): def test_filter_checkboxes(self): category_list = ["Op-Ed", "Press Release"] for cat in category_list: - checkbox = WebDriverWait(self.driver, 10).until( + checkbox = WebDriverWait(self.driver, 20).until( EC.visibility_of_element_located(( By.XPATH, '//label/span[contains(text(), "{0}")]/..'.format(cat) )) @@ -66,25 +66,25 @@ def test_filter_category_search(self): category_list = ["Op-Ed", "Press Release"] for cat in category_list: click_filter_posts(self) - checkbox = WebDriverWait(self.driver, 10).until( + checkbox = WebDriverWait(self.driver, 20).until( EC.visibility_of_element_located(( By.XPATH, '//label/span[contains(text(), "{0}")]/..'.format(cat))) ) checkbox.click() - filter_results_button = WebDriverWait(self.driver, 10).until( + filter_results_button = WebDriverWait(self.driver, 20).until( EC.visibility_of_element_located(( By.XPATH, '//input[@value="Apply filters"]')) ) filter_results_button.click() cat = coerce_category_for_dom(cat) - cat_type_elem = WebDriverWait(self.driver, 10).until( + cat_type_elem = WebDriverWait(self.driver, 20).until( EC.visibility_of_element_located(( By.XPATH, '//a[@href="?filter_category={0}"]'.format(cat))) ) assert cat_type_elem click_filter_posts(self) cat = coerce_category_for_dom(cat) - checkbox = WebDriverWait(self.driver, 10).until( + checkbox = WebDriverWait(self.driver, 20).until( EC.visibility_of_element_located(( By.XPATH, '//label/span[contains(text(), "{0}")]/..'.format(cat))) ) @@ -93,7 +93,7 @@ def test_filter_category_search(self): @attr('search') @attr('topics') def test_filter_topic_search(self): - topic_input = WebDriverWait(self.driver, 10).until( + topic_input = WebDriverWait(self.driver, 20).until( EC.visibility_of_element_located(( By.XPATH, '//input[@value="Search for topics"]' )) @@ -104,7 +104,7 @@ def test_filter_topic_search(self): '//div[@id="filter_tags_chosen"]/div/ul[@class="chosen-results"]' ) assert topic_choice_results.is_displayed() - choice = WebDriverWait(self.driver, 10).until( + choice = WebDriverWait(self.driver, 20).until( EC.visibility_of_element_located(( By.XPATH, '//div[@id="filter_tags_chosen"]/div/ul[@class="chosen-results"]/li/em[contains(text(),"For")]/..' @@ -119,7 +119,7 @@ def test_filter_topic_search(self): @attr('search') @attr('authors') def test_filter_author_search(self): - author_input = WebDriverWait(self.driver, 10).until( + author_input = WebDriverWait(self.driver, 20).until( EC.visibility_of_element_located(( By.XPATH, '//input[@value="Search for authors"]' )) @@ -130,7 +130,7 @@ def test_filter_author_search(self): '//div[@id="filter_author_chosen"]/div/ul[@class="chosen-results"]' ) assert author_choice_results.is_displayed() - choice = WebDriverWait(self.driver, 10).until( + choice = WebDriverWait(self.driver, 20).until( EC.visibility_of_element_located(( By.XPATH, '//div[@id="filter_author_chosen"]/div/ul[@class="chosen-results"]/li/em[contains(text(),"Bat")]/..' @@ -141,13 +141,13 @@ def test_filter_author_search(self): '//div[@id="filter_author_chosen"]/ul/li/span[contains(text(), "Batman")]' ) assert author_elem - filter_results_button = WebDriverWait(self.driver, 10).until( + filter_results_button = WebDriverWait(self.driver, 20).until( EC.visibility_of_element_located(( By.XPATH, '//input[@value="Apply filters"]' )) ) filter_results_button.click() - author = WebDriverWait(self.driver, 10).until( + author = WebDriverWait(self.driver, 20).until( EC.visibility_of_element_located(( By.XPATH, '//p[@class="summary_byline"][contains(text(), "Bat")]' )) @@ -158,7 +158,7 @@ def test_filter_author_search(self): @attr('date') def test_filter_date_search(self): # scroll(self.driver) - WebDriverWait(self.driver, 10).until( + WebDriverWait(self.driver, 20).until( EC.visibility_of_element_located(( By.XPATH, '//div[@id="filter_range_date_gte-replacement"]/div[1]' @@ -184,13 +184,13 @@ def test_filter_date_search(self): ).click() # Search - WebDriverWait(self.driver, 10).until( + WebDriverWait(self.driver, 20).until( EC.visibility_of_element_located(( By.XPATH, '//input[@value="Apply filters"]' )) ).click() - filtered_article_date = WebDriverWait(self.driver, 10).until( + filtered_article_date = WebDriverWait(self.driver, 20).until( EC.visibility_of_element_located(( By.XPATH, '//div[@id="pagination_content"]/article[1]/div[1]/span[1]' From 230e5b4d073697be9a3ca1e717b50332b7cfddcf Mon Sep 17 00:00:00 2001 From: Dan Ford Date: Mon, 24 Nov 2014 10:55:21 -0500 Subject: [PATCH 17/17] README formatting --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index d40a7e1de14..487069aa3d6 100755 --- a/README.md +++ b/README.md @@ -62,6 +62,7 @@ _More specific cfgov-refresh docs are coming soon._ ### Tests To run browser tests, you'll need to perform the following steps: + 1. Install chromedriver: * Mac: `brew install chromedriver` * Manual (Linux/Mac): Download the latest [Chromedriver](http://chromedriver.storage.googleapis.com/index.html) binary and put it somehwere on your path (e.g. /path/to/your/venv/bin)