gov.uk content schemas tech monthly may 2015

Post on 15-Aug-2015

86 Views

Category:

Technology

2 Downloads

Preview:

Click to see full reader

TRANSCRIPT

GOV.UK Tech Monthly - Publishing 2.0 team29th May 2015

David HeathDeveloper@dgheath21

GOV.UK Content

Schemas

GOV.UKDavid Heath

@bradwright - GOV.UKGOV.UK

What’s it for?

David Heath

@bradwright - GOV.UKGOV.UK

What’s it for?- confidence

David Heath

@bradwright - GOV.UKGOV.UK

What’s it for?- confidence- go faster

David Heath

@bradwright - GOV.UKGOV.UK

Publishing pipeline overview

David Heath

@bradwright - GOV.UKGOV.UKDavid Heath

Publishing app

Content store Frontend

JSON JSON

{ “base_path”: ..., …}

{ “base_path”: ..., …}

@bradwright - GOV.UKGOV.UKDavid Heath

Publishing app

Content store Frontend

JSON JSON

{ “base_path”: ..., …}

{ “base_path”: ..., …}Transformation

@bradwright - GOV.UKGOV.UKDavid Heath

Metadata

Details

Links

Content item{ base_path: format: public_updated_at: details: { ... }, links: { … }}

@bradwright - GOV.UKGOV.UKDavid Heath

Publisher

"required": [ "publishing_app", "rendering_app", "update_type", "format", "locale", "public_updated_at" ],

Frontend

"required": [ "base_path", "format", "locale", "public_updated_at" ],

Metadata changes

@bradwright - GOV.UKGOV.UKDavid Heath

Publisher Frontend

content_id currently optional (maybe required in future)

Absent

routes Routes (must be within base_path)

Absent

redirects Only for format==’redirect’ Absent

@bradwright - GOV.UKGOV.UKDavid Heath

Links expansion (publisher)“links”: { “lead_organisations”: [ “ab517cc2-80df-48f2-8325-1b8af95b8f71” ]}

Links expansion (frontend)“links”: { “lead_organisations”: [ { "title": "Department for International Development", "base_path": "/government/organisations/dfid", "api_url": "https://www.gov.uk/api/organisations/dfid", "web_url": "https://www.gov.uk/government/organisations/dfid", "locale": "en" } ]}

@bradwright - GOV.UKGOV.UKDavid Heath

Details hash

stays the same :-)

@bradwright - GOV.UKGOV.UKDavid Heath

Content item transformation{ base_path: format: public_updated_at: details: { ... }, links: { … }}

@bradwright - GOV.UKGOV.UKDavid Heath

Metadata (fields change)

Details (stays same)

Links (expanded)

@bradwright - GOV.UKGOV.UK

How can we test this?

David Heath

@bradwright - GOV.UKGOV.UKDavid Heath

Publishing app

Content store Frontend

@bradwright - GOV.UKGOV.UKDavid Heath

Publishing app FrontendContent

store

@bradwright - GOV.UKGOV.UKDavid Heath

Publishing app Frontend

Test that this produces the right output

Test that this works with a variety of valid inputs

@bradwright - GOV.UKGOV.UKDavid Heath

Publishing app Frontend

Schema

Examples

@bradwright - GOV.UKGOV.UKDavid Heath

Publishing app Frontend

Schema

Examples

@bradwright - GOV.UKGOV.UKDavid Heath

Publishing app Frontend

Schema

Match?

Examples

@bradwright - GOV.UKGOV.UKDavid Heath

Publishing app Frontend

Schema

Match?

GOV.UK Content Schemas

@bradwright - GOV.UKGOV.UKDavid Heath

govuk-content-schemas

@bradwright - GOV.UKGOV.UKDavid Heath

@bradwright - GOV.UKGOV.UKDavid Heath

details.json

metadata.json

links.jsonpublisher/schema.json

frontend/ schema.json

curated examplescurated examples

combine_publisher_schema

generate_frontend_schema

validate;

ensure_example_base_paths_unique

validated examples

Build process (Makefile)

Examples

@bradwright - GOV.UKGOV.UKDavid Heath

Publishing app Frontend

Schema

Match?

GOV.UK Content Schemas

@bradwright - GOV.UKGOV.UKDavid Heath

Publisher testjenkins-schema.sh

# Clone govuk-content-schemas dependency for contract testsrm -rf tmp/govuk-content-schemasgit clone git@github.com:alphagov/govuk-content-schemas.git \ tmp/govuk-content-schemascd tmp/govuk-content-schemasgit checkout $SCHEMA_GIT_COMMITcd ../..

# Run teststime bundle install --path "${HOME}/bundles/${JOB_NAME}" --deploymentRAILS_ENV=test GOVUK_CONTENT_SCHEMAS_PATH=tmp/govuk-content-schemas time bundle exec rake test:publishing_schemas --trace

@bradwright - GOV.UKGOV.UKDavid Heath

Publisher testtest_publishing_schemas.rake

namespace :test do Rake::TestTask.new(:publishing_schemas => "test:prepare") do |t| t.libs << 'test' t.test_files = FileList['test/unit/presenters/publishing_api_presenters/*_test.rb'] end Rake::Task['test:publishing_schemas'].comment = "Test publishing API presenters against external schemas"end

@bradwright - GOV.UKGOV.UKDavid Heath

Publisher testtest/unit/presenters/publishing_api_presenters/case_study_test.rb

test "links hash includes world locations" do location = create(:world_location) case_study = create(:published_case_study, world_locations: [location]) presented_hash = present(case_study) assert_valid_against_schema(presented_hash, 'case_study') assert_equal [location.content_id], presented_hash[:links][:world_locations]end

@bradwright - GOV.UKGOV.UKDavid Heath

Publisher test- use govuk-content-schema-test-helpers- define jenkins-schema.sh- contract tests should ideally be stand-

alone (separate test file)

Examples

@bradwright - GOV.UKGOV.UKDavid Heath

Publishing app Frontend

Schema

Match?

GOV.UK Content Schemas

Frontend testtest/contracts/govuk_content_schemas_test.sh

class GovukContentSchemasTest < ActionDispatch::IntegrationTest include GovukContentSchemaExamples

all_examples_for_supported_formats.each do |content_item| test "can successfully render #{content_item['base_path']} schema example" do content_store_has_item(content_item['base_path'], content_item)

get content_item['base_path'].sub(/^\//, '')

assert_response :success end endend

@bradwright - GOV.UKGOV.UKDavid Heath

Adding a field to a format

1. Branch govuk-content-schemas2. Add optional field3. Push branch, all contract tests run4. Merge!

@bradwright - GOV.UKGOV.UKDavid Heath

@bradwright - GOV.UKGOV.UKDavid Heath

Adding a new format

1. Branch govuk-content-schemas2. Add schema and examples3. Make sure publisher and frontend

tests set up4. Push branch

@bradwright - GOV.UKGOV.UKDavid Heath

Dummy content store

@bradwright - GOV.UKGOV.UKDavid Heath

@bradwright - GOV.UKGOV.UK

Summing up

David Heath

@bradwright - GOV.UK

Your safetynet

@bradwright - GOV.UK

confidence

publisher

frontend

Links● https://github.com/alphagov/govuk-content-schemas● https://github.com/alphagov/govuk-content-schema-test-helpers● https://github.com/alphagov/govuk-dummy_content_store

@bradwright - GOV.UKGOV.UKDavid Heath

GOV.UK Tech Monthly - Publishing 2.0 team29th May 2015

David HeathDeveloper@dgheath21

top related