def test_skip_pk(table): names = sorted([ 'title', 'body', 'views', 'average_note', 'pictures', 'published_at', 'tags' ]) traf = validator_from_table(table, 'id', skip_pk=True) result_names = sorted([key.name for key in traf.keys]) assert result_names == names
def test_validation(table): traf = validator_from_table(table, 'id', skip_pk=False) data = {'id': '1', 'title': 'title string', 'body': 'body text', 'views': '42', 'average_note': '0.11', 'pictures': {'foo': 'bar'}, 'published_at': '2015-12-15', 'tags': [1, 2, 3]} data = traf(data) assert data['id'] == 1 assert data['views'] == 42 assert data['average_note'] == 0.11
def test_validation_bad_input(table): traf = validator_from_table(table, 'id', skip_pk=False) with pytest.raises(t.DataError): data = {'id': 'not a string', # not valid data 'title': 'title string', 'body': 'body text', 'views': 42, 'average_note': 0.11, 'pictures': {'foo': 'bar'}, 'published_at': '2015-12-15', 'tags': [1, 2, 3]} traf(data) with pytest.raises(t.DataError): data = {} traf(data)
def test_validation(table): traf = validator_from_table(table, 'id', skip_pk=False) data = { 'id': '1', 'title': 'title string', 'body': 'body text', 'views': '42', 'average_note': '0.11', 'pictures': { 'foo': 'bar' }, 'published_at': '2015-12-15', 'tags': [1, 2, 3] } data = traf(data) assert data['id'] == 1 assert data['views'] == 42 assert data['average_note'] == 0.11
def test_validation_bad_input(table): traf = validator_from_table(table, 'id', skip_pk=False) with pytest.raises(t.DataError): data = { 'id': 'not a string', # not valid data 'title': 'title string', 'body': 'body text', 'views': 42, 'average_note': 0.11, 'pictures': { 'foo': 'bar' }, 'published_at': '2015-12-15', 'tags': [1, 2, 3] } traf(data) with pytest.raises(t.DataError): data = {} traf(data)
def test_skip_pk(table): names = sorted(['title', 'body', 'views', 'average_note', 'pictures', 'published_at', 'tags']) traf = validator_from_table(table, 'id', skip_pk=True) result_names = sorted([key.name for key in traf.keys]) assert result_names == names