Skip to content

Commit

Permalink
Merge pull request #46 from thread/update-example.yaml
Browse files Browse the repository at this point in the history
Update example.yaml and add tests
  • Loading branch information
danpalmer committed Apr 23, 2018
2 parents 7c6c1c4 + f667acd commit 1be3552
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 10 deletions.
16 changes: 7 additions & 9 deletions example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@ state_machines:
user_lifecycle:
feeds:
- name: jacquard
url: http://localhost:1212/<label_id>
url: http://localhost:1212/<label>

states:
- gate: start
triggers:
- interval: 1m
exit_condition: >
jacquard.has_redesigned_first_two_drip_emails is defined
feeds.jacquard.has_redesigned_first_two_drip_emails is defined
next:
type: context
path: jacquard.has_redesigned_first_two_drip_emails
path: feeds.jacquard.has_redesigned_first_two_drip_emails
default: send_welcome_email
destinations:
- value: false
state: send_welcome_email
- value: true
state: send_welcome_email_test

Expand All @@ -42,13 +41,12 @@ state_machines:
- metadata: metadata.recs.has_first_recommendations
exit_condition: >
recs.has_first_recommendations and
(jacquard.has_redesigned_first_two_drip_emails is defined)
(feeds.jacquard.has_redesigned_first_two_drip_emails is defined)
next:
type: context
path: jacquard.has_redesigned_first_two_drip_emails
path: feeds.jacquard.has_redesigned_first_two_drip_emails
default: send_stylist_onboarding_email
destinations:
- value: false
state: send_stylist_onboarding_email
- value: true
state: send_stylist_onboarding_email_test

Expand Down
29 changes: 29 additions & 0 deletions routemaster/config/tests/test_loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import re
import datetime
import contextlib
from pathlib import Path
from unittest import mock

import yaml
Expand Down Expand Up @@ -356,3 +357,31 @@ def test_raises_for_unparseable_database_port_in_environment_variable():
def test_multiple_feeds_same_name_invalid():
with assert_config_error("FeedConfigs must have unique names at state_machines.example.feeds"):
load_config(yaml_data('multiple_feeds_same_name_invalid'))


def test_example_config_loads():
"""
Test that the example.yaml in this repo can be loaded.
This ensures that the example file itself is valid and is not intended as a
test of the system.
"""

repo_root = Path(__file__).parent.parent.parent.parent
example_yaml = repo_root / 'example.yaml'

assert example_yaml.exists(), "Example file is missing! (is this test set up correctly?)"

example_config = load_config(yaml.load(example_yaml.read_text()))

# Some basic assertions that we got the right thing loaded
assert list(example_config.state_machines.keys()) == ['user_lifecycle']

user_lifecycle_machine = example_config.state_machines['user_lifecycle']

jacquard_feed = FeedConfig('jacquard', 'http://localhost:1212/<label>')
assert user_lifecycle_machine.feeds == [jacquard_feed]

assert len(user_lifecycle_machine.states) == 10
assert user_lifecycle_machine.states[0].name == 'start'
assert user_lifecycle_machine.states[9].name == 'end'
31 changes: 30 additions & 1 deletion routemaster/tests/test_validation.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from pathlib import Path

import yaml
import pytest

from routemaster.config import (
Expand All @@ -7,8 +10,13 @@
ConstantNextState,
ContextNextStates,
ContextNextStatesOption,
load_config,
)
from routemaster.validation import (
ValidationError,
validate_config,
_validate_state_machine,
)
from routemaster.validation import ValidationError, _validate_state_machine
from routemaster.exit_conditions import ExitConditionProgram


Expand Down Expand Up @@ -163,3 +171,24 @@ def test_label_in_deleted_state_on_per_state_machine_basis(

# Should not care about our label as it is in a different state machine.
_validate_state_machine(app, state_machine)


def test_example_config_is_valid(app):
"""
Test that the example.yaml in this repo is valid.
This ensures that the example file itself is valid and is not intended as a
test of the system.
"""

repo_root = Path(__file__).parent.parent.parent
example_yaml = repo_root / 'example.yaml'

assert example_yaml.exists(), "Example file is missing! (is this test set up correctly?)"

example_config = load_config(yaml.load(example_yaml.read_text()))

# quick check that we've loaded the config we expect
assert list(example_config.state_machines.keys()) == ['user_lifecycle']

validate_config(app, example_config)

0 comments on commit 1be3552

Please sign in to comment.