Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add integration tests for weekly policy entries

  • Loading branch information...
commit 3ee5197bd5b676fccf64dab42b20c4c1eee3f329 1 parent 0a235eb
@robyoung robyoung authored
View
1  spec/fixtures/insidegov-weekly-policy-entries-from-2012-12-09.json
@@ -0,0 +1 @@
+{"kind":"analytics#gaData","id":"https://www.googleapis.com/analytics/v3/data/ga?ids=ga:53872948&dimensions=ga:week,ga:eventAction&metrics=ga:totalEvents&filters=ga:eventCategory%3D%3DIG_policy;ga:eventLabel%3D%3DEntry&start-date=2012-12-09&end-date=2012-12-15","query":{"start-date":"2012-12-09","end-date":"2012-12-15","ids":"ga:53872948","dimensions":"ga:week,ga:eventAction","metrics":["ga:totalEvents"],"filters":"ga:eventCategory==IG_policy;ga:eventLabel==Entry","start-index":1,"max-results":1000},"itemsPerPage":1000,"totalResults":72,"selfLink":"https://www.googleapis.com/analytics/v3/data/ga?ids=ga:53872948&dimensions=ga:week,ga:eventAction&metrics=ga:totalEvents&filters=ga:eventCategory%3D%3DIG_policy;ga:eventLabel%3D%3DEntry&start-date=2012-12-09&end-date=2012-12-15","profileInfo":{"profileId":"53872948","accountId":"26179049","webPropertyId":"UA-26179049-1","internalWebPropertyId":"50705554","profileName":"1. GOV.UK (Entire site - Filtered)","tableId":"ga:53872948"},"containsSampledData":false,"columnHeaders":[{"name":"ga:week","columnType":"DIMENSION","dataType":"STRING"},{"name":"ga:eventAction","columnType":"DIMENSION","dataType":"STRING"},{"name":"ga:totalEvents","columnType":"METRIC","dataType":"INTEGER"}],"totalsForAllResults":{"ga:totalEvents":"38219"},"rows":[["50","boosting-private-sector-employment-in-england","206"],["50","bringing-people-together-in-strong-united-communities","287"],["50","controlling-defence-security-and-dual-use-strategic-exports--2","638"],["50","countering-weapons-proliferation","271"],["50","developing-a-new-high-speed-rail-network","762"],["50","engaging-the-public-in-science-and-engineering--3","320"],["50","ensuring-the-future-of-the-universal-postal-service-and-post-office-network-services","127"],["50","establishing-stability-in-afghanistan","1113"],["50","expanding-and-improving-the-rail-network","748"],["50","giving-communities-more-power-in-planning-local-development","1081"],["50","giving-local-authorities-more-control-over-how-they-spend-public-money-in-their-area--2","1266"],["50","giving-people-more-power-over-what-happens-in-their-neighbourhood","375"],["50","helping-people-to-buy-a-home","409"],["50","helping-troubled-families-turn-their-lives-around","1036"],["50","improving-high-streets-and-town-centres","575"],["50","improving-local-transport","1136"],["50","improving-the-energy-efficiency-of-buildings-and-using-planning-to-protect-the-environment","1045"],["50","improving-the-quality-of-further-education-and-skills-training","1668"],["50","improving-the-rented-housing-sector--2","623"],["50","increasing-investment-in-research-development-and-innovation-for-growth","136"],["50","increasing-the-number-of-available-homes","2477"],["50","increasing-the-uk-s-exports-and-attracting-inward-investment","128"],["50","leading-international-efforts-to-resolve-concerns-about-irans-nuclear-programme","26"],["50","maintaining-an-effective-independent-nuclear-deterrent","80"],["50","maintaining-operational-readiness-to-provide-military-support-for-activities-in-the-uk","85"],["50","making-companies-more-accountable-to-shareholders-and-the-public","282"],["50","making-consumer-credit-markets-fairer--6","58"],["50","making-it-easier-to-set-up-and-grow-a-business--6","1009"],["50","making-it-easier-to-trade","25"],["50","making-local-councils-more-transparent-and-accountable-to-local-people","756"],["50","making-roads-safer","1046"],["50","making-sure-council-tax-payers-get-good-value-for-money","437"],["50","making-sure-uk-airports-and-airlines-are-safe-secure-and-competitive-while-reducing-their-impacts-on-the-environment-and-communities","426"],["50","making-the-higher-education-system-more-efficient-and-diverse","307"],["50","making-the-labour-market-more-flexible-efficient-and-fair","1044"],["50","making-the-planning-system-work-more-efficiently-and-effectively","2683"],["50","making-the-single-market-more-effective","182"],["50","making-transport-more-accessible-to-all","1078"],["50","managing-improving-and-investing-in-the-road-network","768"],["50","managing-the-risk-to-transport-networks-from-terrorism-and-other-crimes","377"],["50","meeting-nato-and-eu-treaty-defence-commitments","41"],["50","modernising-company-law--2","135"],["50","preventing-and-reducing-anti-competitive-activities","75"],["50","preventing-and-reducing-piracy-off-the-coast-of-somalia","221"],["50","preventing-conflict-in-fragile-states--2","63"],["50","promoting-human-rights-internationally","625"],["50","promoting-stability-throughout-the-western-balkans--2","35"],["50","protecting-and-developing-the-overseas-territories","323"],["50","protecting-the-uk-against-terrorism","167"],["50","providing-better-information-and-protection-for-consumers","153"],["50","providing-effective-building-regulations-so-that-new-and-altered-buildings-are-safe-accessible-and-efficient","2067"],["50","providing-effective-regulation-of-freight-transport","485"],["50","providing-housing-support-for-older-and-vulnerable-people","616"],["50","providing-versatile-agile-and-battle-winning-armed-forces-and-a-smaller-more-professional-ministry-of-defence","254"],["50","reducing-barriers-to-international-free-trade--3","390"],["50","reducing-corruption-in-international-trade--2","13"],["50","reducing-greenhouse-gases-and-other-emissions-from-transport","630"],["50","reducing-the-impact-of-regulation-on-business","498"],["50","strengthening-the-commonwealth--2","30"],["50","strengthening-uk-relationships-in-asia-latin-america-and-africa-to-support-uk-prosperity-and-security","63"],["50","supporting-british-nationals-overseas","48"],["50","supporting-economic-development-projects-in-coastal-and-seaside-areas--4","122"],["50","supporting-economic-growth-through-local-enterprise-partnerships-and-enterprise-zones","1035"],["50","supporting-economic-growth-through-managing-the-european-regional-development-fund","1112"],["50","supporting-fire-and-rescue-authorities-to-reduce-the-number-and-impact-of-fires","641"],["50","supporting-the-falkland-islanders-right-to-self-determination","158"],["50","sustaining-a-thriving-maritime-sector","177"],["50","taking-international-action-to-mitigate-climate-change","329"],["50","widening-participation-in-higher-education--4","72"],["50","working-for-peace-and-long-term-stability-in-the-middle-east-and-north-africa","428"],["50","working-towards-nuclear-disarmament","37"],["50","working-with-local-partners-to-plan-for-and-respond-to-emergencies","80"]]}
View
1  spec/fixtures/insidegov-weekly-policy-entries-from-2012-12-16.json
@@ -0,0 +1 @@
+{"kind":"analytics#gaData","id":"https://www.googleapis.com/analytics/v3/data/ga?ids=ga:53872948&dimensions=ga:week,ga:eventAction&metrics=ga:totalEvents&filters=ga:eventCategory%3D%3DIG_policy;ga:eventLabel%3D%3DEntry&start-date=2012-12-16&end-date=2012-12-22","query":{"start-date":"2012-12-16","end-date":"2012-12-22","ids":"ga:53872948","dimensions":"ga:week,ga:eventAction","metrics":["ga:totalEvents"],"filters":"ga:eventCategory==IG_policy;ga:eventLabel==Entry","start-index":1,"max-results":1000},"itemsPerPage":1000,"totalResults":74,"selfLink":"https://www.googleapis.com/analytics/v3/data/ga?ids=ga:53872948&dimensions=ga:week,ga:eventAction&metrics=ga:totalEvents&filters=ga:eventCategory%3D%3DIG_policy;ga:eventLabel%3D%3DEntry&start-date=2012-12-16&end-date=2012-12-22","profileInfo":{"profileId":"53872948","accountId":"26179049","webPropertyId":"UA-26179049-1","internalWebPropertyId":"50705554","profileName":"1. GOV.UK (Entire site - Filtered)","tableId":"ga:53872948"},"containsSampledData":false,"columnHeaders":[{"name":"ga:week","columnType":"DIMENSION","dataType":"STRING"},{"name":"ga:eventAction","columnType":"DIMENSION","dataType":"STRING"},{"name":"ga:totalEvents","columnType":"METRIC","dataType":"INTEGER"}],"totalsForAllResults":{"ga:totalEvents":"44656"},"rows":[["51","boosting-private-sector-employment-in-england","843"],["51","bringing-people-together-in-strong-united-communities","216"],["51","controlling-defence-security-and-dual-use-strategic-exports--2","903"],["51","countering-weapons-proliferation","374"],["51","developing-a-new-high-speed-rail-network","662"],["51","engaging-the-public-in-science-and-engineering--3","370"],["51","ensuring-the-future-of-the-universal-postal-service-and-post-office-network-services","213"],["51","establishing-stability-in-afghanistan","640"],["51","expanding-and-improving-the-rail-network","630"],["51","giving-communities-more-power-in-planning-local-development","1141"],["51","giving-local-authorities-more-control-over-how-they-spend-public-money-in-their-area--2","1755"],["51","giving-people-more-power-over-what-happens-in-their-neighbourhood","528"],["51","helping-people-to-buy-a-home","378"],["51","helping-troubled-families-turn-their-lives-around","1041"],["51","helping-troubled-families-turn-their-lives-around%20","1"],["51","improving-high-streets-and-town-centres","348"],["51","improving-local-transport","1079"],["51","improving-the-energy-efficiency-of-buildings-and-using-planning-to-protect-the-environment","1012"],["51","improving-the-quality-of-further-education-and-skills-training","2158"],["51","improving-the-rented-housing-sector--2","639"],["51","increasing-investment-in-research-development-and-innovation-for-growth","142"],["51","increasing-the-number-of-available-homes","999"],["51","increasing-the-uk-s-exports-and-attracting-inward-investment","207"],["51","investing-in-research-development-and-innovation","273"],["51","leading-international-efforts-to-resolve-concerns-about-irans-nuclear-programme","52"],["51","maintaining-an-effective-independent-nuclear-deterrent","195"],["51","maintaining-operational-readiness-to-provide-military-support-for-activities-in-the-uk","154"],["51","making-companies-more-accountable-to-shareholders-and-the-public","603"],["51","making-consumer-credit-markets-fairer--6","106"],["51","making-it-easier-to-set-up-and-grow-a-business--6","1961"],["51","making-it-easier-to-trade","45"],["51","making-local-councils-more-transparent-and-accountable-to-local-people","877"],["51","making-roads-safer","1066"],["51","making-sure-council-tax-payers-get-good-value-for-money","1023"],["51","making-sure-uk-airports-and-airlines-are-safe-secure-and-competitive-while-reducing-their-impacts-on-the-environment-and-communities","440"],["51","making-the-higher-education-system-more-efficient-and-diverse","660"],["51","making-the-labour-market-more-flexible-efficient-and-fair","1243"],["51","making-the-planning-system-work-more-efficiently-and-effectively","2718"],["51","making-the-single-market-more-effective","289"],["51","making-transport-more-accessible-to-all","1007"],["51","managing-improving-and-investing-in-the-road-network","947"],["51","managing-the-risk-to-transport-networks-from-terrorism-and-other-crimes","386"],["51","meeting-nato-and-eu-treaty-defence-commitments","73"],["51","modernising-company-law--2","130"],["51","preventing-and-reducing-anti-competitive-activities","172"],["51","preventing-and-reducing-piracy-off-the-coast-of-somalia","353"],["51","preventing-conflict-in-fragile-states--2","118"],["51","promoting-human-rights-internationally","773"],["51","promoting-stability-throughout-the-western-balkans--2","52"],["51","protecting-and-developing-the-overseas-territories","1270"],["51","protecting-the-uk-against-terrorism","182"],["51","providing-better-information-and-protection-for-consumers","352"],["51","providing-effective-building-regulations-so-that-new-and-altered-buildings-are-safe-accessible-and-efficient","2105"],["51","providing-effective-regulation-of-freight-transport","532"],["51","providing-housing-support-for-older-and-vulnerable-people","502"],["51","providing-versatile-agile-and-battle-winning-armed-forces-and-a-smaller-more-professional-ministry-of-defence","450"],["51","reducing-barriers-to-international-free-trade--3","439"],["51","reducing-corruption-in-international-trade--2","22"],["51","reducing-greenhouse-gases-and-other-emissions-from-transport","620"],["51","reducing-the-impact-of-regulation-on-business","1273"],["51","strengthening-the-commonwealth--2","53"],["51","strengthening-uk-relationships-in-asia-latin-america-and-africa-to-support-uk-prosperity-and-security","79"],["51","supporting-british-nationals-overseas","175"],["51","supporting-economic-development-projects-in-coastal-and-seaside-areas--4","95"],["51","supporting-economic-growth-through-local-enterprise-partnerships-and-enterprise-zones","1151"],["51","supporting-economic-growth-through-managing-the-european-regional-development-fund","1002"],["51","supporting-fire-and-rescue-authorities-to-reduce-the-number-and-impact-of-fires","950"],["51","supporting-the-falkland-islanders-right-to-self-determination","124"],["51","sustaining-a-thriving-maritime-sector","232"],["51","taking-international-action-to-mitigate-climate-change","249"],["51","widening-participation-in-higher-education--4","94"],["51","working-for-peace-and-long-term-stability-in-the-middle-east-and-north-africa","617"],["51","working-towards-nuclear-disarmament","34"],["51","working-with-local-partners-to-plan-for-and-respond-to-emergencies","59"]]}
View
1  spec/fixtures/insidegov-weekly-policy-entries-from-2012-12-23.json
@@ -0,0 +1 @@
+{"kind":"analytics#gaData","id":"https://www.googleapis.com/analytics/v3/data/ga?ids=ga:53872948&dimensions=ga:week,ga:eventAction&metrics=ga:totalEvents&filters=ga:eventCategory%3D%3DIG_policy;ga:eventLabel%3D%3DEntry&start-date=2012-12-23&end-date=2012-12-29","query":{"start-date":"2012-12-23","end-date":"2012-12-29","ids":"ga:53872948","dimensions":"ga:week,ga:eventAction","metrics":["ga:totalEvents"],"filters":"ga:eventCategory==IG_policy;ga:eventLabel==Entry","start-index":1,"max-results":1000},"itemsPerPage":1000,"totalResults":72,"selfLink":"https://www.googleapis.com/analytics/v3/data/ga?ids=ga:53872948&dimensions=ga:week,ga:eventAction&metrics=ga:totalEvents&filters=ga:eventCategory%3D%3DIG_policy;ga:eventLabel%3D%3DEntry&start-date=2012-12-23&end-date=2012-12-29","profileInfo":{"profileId":"53872948","accountId":"26179049","webPropertyId":"UA-26179049-1","internalWebPropertyId":"50705554","profileName":"1. GOV.UK (Entire site - Filtered)","tableId":"ga:53872948"},"containsSampledData":false,"columnHeaders":[{"name":"ga:week","columnType":"DIMENSION","dataType":"STRING"},{"name":"ga:eventAction","columnType":"DIMENSION","dataType":"STRING"},{"name":"ga:totalEvents","columnType":"METRIC","dataType":"INTEGER"}],"totalsForAllResults":{"ga:totalEvents":"14358"},"rows":[["52","boosting-private-sector-employment-in-england","194"],["52","bringing-people-together-in-strong-united-communities","91"],["52","controlling-defence-security-and-dual-use-strategic-exports--2","240"],["52","countering-weapons-proliferation","148"],["52","developing-a-new-high-speed-rail-network","368"],["52","engaging-the-public-in-science-and-engineering--3","54"],["52","ensuring-the-future-of-the-universal-postal-service-and-post-office-network-services","59"],["52","establishing-stability-in-afghanistan","289"],["52","expanding-and-improving-the-rail-network","273"],["52","giving-communities-more-power-in-planning-local-development","320"],["52","giving-local-authorities-more-control-over-how-they-spend-public-money-in-their-area--2","318"],["52","giving-people-more-power-over-what-happens-in-their-neighbourhood","151"],["52","helping-people-to-buy-a-home","266"],["52","helping-troubled-families-turn-their-lives-around","304"],["52","improving-high-streets-and-town-centres","76"],["52","improving-local-transport","448"],["52","improving-the-energy-efficiency-of-buildings-and-using-planning-to-protect-the-environment","443"],["52","improving-the-quality-of-further-education-and-skills-training","341"],["52","improving-the-rented-housing-sector--2","233"],["52","increasing-the-number-of-available-homes","277"],["52","increasing-the-uk-s-exports-and-attracting-inward-investment","76"],["52","investing-in-research-development-and-innovation","171"],["52","leading-international-efforts-to-resolve-concerns-about-irans-nuclear-programme","26"],["52","maintaining-an-effective-independent-nuclear-deterrent","36"],["52","maintaining-operational-readiness-to-provide-military-support-for-activities-in-the-uk","32"],["52","making-companies-more-accountable-to-shareholders-and-the-public","162"],["52","making-consumer-credit-markets-fairer--6","30"],["52","making-it-easier-to-set-up-and-grow-a-business--6","665"],["52","making-it-easier-to-trade","10"],["52","making-local-councils-more-transparent-and-accountable-to-local-people","176"],["52","making-roads-safer","542"],["52","making-sure-council-tax-payers-get-good-value-for-money","143"],["52","making-sure-uk-airports-and-airlines-are-safe-secure-and-competitive-while-reducing-their-impacts-on-the-environment-and-communities","116"],["52","making-the-higher-education-system-more-efficient-and-diverse","299"],["52","making-the-labour-market-more-flexible-efficient-and-fair","308"],["52","making-the-planning-system-work-more-efficiently-and-effectively","972"],["52","making-the-single-market-more-effective","84"],["52","making-transport-more-accessible-to-all","525"],["52","managing-improving-and-investing-in-the-road-network","321"],["52","managing-the-risk-to-transport-networks-from-terrorism-and-other-crimes","159"],["52","meeting-nato-and-eu-treaty-defence-commitments","33"],["52","modernising-company-law--2","34"],["52","preventing-and-reducing-anti-competitive-activities","38"],["52","preventing-and-reducing-piracy-off-the-coast-of-somalia","123"],["52","preventing-conflict-in-fragile-states--2","46"],["52","promoting-human-rights-internationally","201"],["52","promoting-stability-throughout-the-western-balkans--2","43"],["52","protecting-and-developing-the-overseas-territories","482"],["52","protecting-the-uk-against-terrorism","109"],["52","providing-better-information-and-protection-for-consumers","70"],["52","providing-effective-building-regulations-so-that-new-and-altered-buildings-are-safe-accessible-and-efficient","902"],["52","providing-effective-regulation-of-freight-transport","190"],["52","providing-housing-support-for-older-and-vulnerable-people","202"],["52","providing-versatile-agile-and-battle-winning-armed-forces-and-a-smaller-more-professional-ministry-of-defence","137"],["52","reducing-barriers-to-international-free-trade--3","99"],["52","reducing-corruption-in-international-trade--2","9"],["52","reducing-greenhouse-gases-and-other-emissions-from-transport","234"],["52","reducing-the-impact-of-regulation-on-business","210"],["52","strengthening-the-commonwealth--2","40"],["52","strengthening-uk-relationships-in-asia-latin-america-and-africa-to-support-uk-prosperity-and-security","54"],["52","supporting-british-nationals-overseas","50"],["52","supporting-economic-development-projects-in-coastal-and-seaside-areas--4","13"],["52","supporting-economic-growth-through-local-enterprise-partnerships-and-enterprise-zones","202"],["52","supporting-economic-growth-through-managing-the-european-regional-development-fund","310"],["52","supporting-fire-and-rescue-authorities-to-reduce-the-number-and-impact-of-fires","212"],["52","supporting-the-falkland-islanders-right-to-self-determination","50"],["52","sustaining-a-thriving-maritime-sector","121"],["52","taking-international-action-to-mitigate-climate-change","104"],["52","widening-participation-in-higher-education--4","34"],["52","working-for-peace-and-long-term-stability-in-the-middle-east-and-north-africa","203"],["52","working-towards-nuclear-disarmament","21"],["52","working-with-local-partners-to-plan-for-and-respond-to-emergencies","36"]]}
View
110 spec/integration/insidegov_weekly_policy_entries_spec.rb
@@ -0,0 +1,110 @@
+require_relative "spec_helper"
+
+describe "Inside gov weekly policy entries collector" do
+ before(:each) do
+ stub_credentials
+ register_oauth_refresh
+ register_api_discovery
+
+ @ga_request = setup_ga_request(
+ :ids => "ga:53872948",
+ :metrics => "ga:totalEvents",
+ :dimensions => "ga:week,ga:eventAction",
+ :filters => "ga:eventCategory==IG_policy;ga:eventLabel==Entry"
+ )
+ end
+
+ it "should query google analytics for specific dates" do
+ @ga_request.register(
+ "2012-12-23", "2012-12-29",
+ "insidegov-weekly-policy-entries-from-2012-12-23.json"
+ )
+
+ configs = [GoogleAnalytics::Config::InsideGovWeeklyPolicyEntries.new(Date.new(2012, 12, 23), Date.new(2012, 12, 29))]
+ collector = GoogleAnalytics::Collector.new(nil, configs)
+
+ response = collector.collect_as_json
+ response.should have(72).item
+
+ response.each do |message|
+ message.should be_for_collector("Google Analytics")
+ message.should be_for_time_period(
+ DateTime.new(2012, 12, 23), DateTime.new(2012, 12, 30))
+ end
+ response[0].should have_payload_value(
+ "site" => "insidegov",
+ "entries" => 194,
+ "slug" => "boosting-private-sector-employment-in-england"
+ )
+ end
+
+ it "should query google analytics for last week today" do
+ @ga_request.register(
+ "2012-12-23", "2012-12-29",
+ "insidegov-weekly-policy-entries-from-2012-12-23.json"
+ )
+
+ Timecop.travel(DateTime.parse("2012-12-31")) do
+ configs = GoogleAnalytics::Config::InsideGovWeeklyPolicyEntries.all_within(Date.today - 1, Date.today)
+ collector = GoogleAnalytics::Collector.new(nil, configs)
+
+ response = collector.collect_as_json
+ response.should have(72).item
+
+ response.each do |message|
+ message.should be_for_collector("Google Analytics")
+ message.should be_for_time_period(
+ DateTime.new(2012, 12, 23), DateTime.new(2012, 12, 30))
+ end
+ response[0].should have_payload_value(
+ "site" => "insidegov",
+ "entries" => 194,
+ "slug" => "boosting-private-sector-employment-in-england"
+ )
+ end
+ end
+
+ it "should query google analytics for the previous three weeks" do
+ @ga_request.register(
+ "2012-12-09", "2012-12-15",
+ "insidegov-weekly-policy-entries-from-2012-12-09.json"
+ )
+ @ga_request.register(
+ "2012-12-16", "2012-12-22",
+ "insidegov-weekly-policy-entries-from-2012-12-16.json"
+ )
+ @ga_request.register(
+ "2012-12-23", "2012-12-29",
+ "insidegov-weekly-policy-entries-from-2012-12-23.json"
+ )
+ Timecop.travel(DateTime.parse("2012-12-31")) do
+ configs = GoogleAnalytics::Config::InsideGovWeeklyPolicyEntries.all_within(
+ Date.new(2012, 12, 10),
+ Date.today
+ )
+ collector = GoogleAnalytics::Collector.new(nil, configs)
+
+ response = collector.collect_as_json
+ response.should have(218).items
+
+ (0...72).each do |i|
+ response[i].should be_for_collector("Google Analytics")
+ response[i].should be_for_time_period(DateTime.new(2012, 12, 9), DateTime.new(2012, 12, 16))
+ end
+ (72...146).each do |i|
+ response[i].should be_for_collector("Google Analytics")
+ response[i].should be_for_time_period(DateTime.new(2012, 12, 16), DateTime.new(2012, 12, 23))
+ end
+ (146...218).each do |i|
+ response[i].should be_for_collector("Google Analytics")
+ response[i].should be_for_time_period(DateTime.new(2012, 12, 23), DateTime.new(2012, 12, 30))
+ end
+
+ response[0].should have_payload_value(
+ "site" => "insidegov",
+ "entries" => 206,
+ "slug" => "boosting-private-sector-employment-in-england"
+ )
+ end
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.