2011-08-08 23:51:10 +00:00
|
|
|
import nose
|
|
|
|
import random
|
|
|
|
import string
|
|
|
|
import yaml
|
|
|
|
|
|
|
|
from s3tests.fuzz_headers import *
|
|
|
|
|
|
|
|
from nose.tools import eq_ as eq
|
|
|
|
from nose.plugins.attrib import attr
|
|
|
|
|
|
|
|
from .utils import assert_raises
|
|
|
|
|
|
|
|
_decision_graph = {}
|
|
|
|
|
|
|
|
def check_access_denied(fn, *args, **kwargs):
|
|
|
|
e = assert_raises(boto.exception.S3ResponseError, fn, *args, **kwargs)
|
|
|
|
eq(e.status, 403)
|
|
|
|
eq(e.reason, 'Forbidden')
|
|
|
|
eq(e.error_code, 'AccessDenied')
|
|
|
|
|
|
|
|
|
2011-08-09 18:56:38 +00:00
|
|
|
def build_graph():
|
|
|
|
graph = {}
|
|
|
|
graph['start'] = {
|
|
|
|
'set': {},
|
|
|
|
'choices': ['node1']
|
|
|
|
}
|
|
|
|
graph['leaf'] = {
|
|
|
|
'set': {
|
|
|
|
'key1': 'value1',
|
|
|
|
'key2': 'value2'
|
|
|
|
},
|
|
|
|
'choices': []
|
|
|
|
}
|
|
|
|
graph['node1'] = {
|
|
|
|
'set': {
|
|
|
|
'key3': 'value3'
|
|
|
|
},
|
|
|
|
'choices': ['leaf']
|
|
|
|
}
|
|
|
|
graph['bad_node'] = {
|
|
|
|
'set': {
|
|
|
|
'key1': 'value1'
|
|
|
|
},
|
|
|
|
'choices': ['leaf']
|
|
|
|
}
|
|
|
|
return graph
|
|
|
|
|
|
|
|
|
|
|
|
def test_load_graph():
|
2011-08-08 23:51:10 +00:00
|
|
|
graph_file = open('request_decision_graph.yml', 'r')
|
2011-08-09 18:56:38 +00:00
|
|
|
graph = yaml.safe_load(graph_file)
|
|
|
|
graph['start']
|
|
|
|
|
|
|
|
|
|
|
|
def test_descend_leaf_node():
|
|
|
|
graph = build_graph()
|
|
|
|
prng = random.Random(1)
|
|
|
|
decision = descend_graph(graph, 'leaf', prng)
|
|
|
|
|
|
|
|
eq(decision['key1'], 'value1')
|
|
|
|
eq(decision['key2'], 'value2')
|
|
|
|
e = assert_raises(KeyError, lambda x: decision[x], 'key3')
|
|
|
|
|
|
|
|
def test_descend_node():
|
|
|
|
graph = build_graph()
|
|
|
|
prng = random.Random(1)
|
|
|
|
decision = descend_graph(graph, 'node1', prng)
|
2011-08-08 23:51:10 +00:00
|
|
|
|
2011-08-09 18:56:38 +00:00
|
|
|
eq(decision['key1'], 'value1')
|
|
|
|
eq(decision['key2'], 'value2')
|
|
|
|
eq(decision['key3'], 'value3')
|
2011-08-08 23:51:10 +00:00
|
|
|
|
2011-08-09 18:56:38 +00:00
|
|
|
def test_descend_bad_node():
|
|
|
|
graph = build_graph()
|
2011-08-08 23:51:10 +00:00
|
|
|
prng = random.Random(1)
|
2011-08-09 18:56:38 +00:00
|
|
|
assert_raises(KeyError, descend_graph, graph, 'bad_node', prng)
|
2011-08-08 23:51:10 +00:00
|
|
|
|