1
# Copyright 2008 Canonical Ltd. All rights reserved.
2
"""Tests for ETag generation."""
6
from lazr.restful._resource import make_entry_etag_cores
8
class TestEntryResourceETags(unittest.TestCase):
9
# The EntryResource uses the field values that can be written or might
10
# othwerise change as the basis for its ETags. The make_entry_etag_cores
11
# function is passed the data about the fields and returns the read and
14
def test_no_field_details(self):
15
# If make_entry_etag_cores is given no field details (because no
16
# fields exist), the resulting cores empty strings.
17
self.assertEquals(make_entry_etag_cores([]), ['', ''])
19
def test_writable_fields(self):
20
# If there are writable fields, their values are incorporated into the
21
# writable portion of the cores.
33
make_entry_etag_cores(field_details), ['', 'first\0second'])
35
def test_modifiable_fields(self):
36
# If there are modifiable fields -- fields that aren't writable, but
37
# might change nonetheless -- their values are incorporated into the
38
# "readable" portion of the cores.
50
make_entry_etag_cores(field_details), ['first\0second', ''])
52
def test_unchanging_fields(self):
53
# If there are fields that are not modifiable their values are not
54
# reflected in the generated cores.
59
'value': 'the value'}),
62
make_entry_etag_cores(field_details),
65
def test_combinations_of_fields(self):
66
# If there are a combination of writable, changable, and unchanable
67
# fields, their values are -- or are not in the case of unchanable
68
# fields -- reflected in the resulting cores.
73
'value': 'first-writable'}),
77
'value': 'second-writable'}),
81
'value': 'first-modifiable'}),
85
'value': 'second-modifiable'}),
89
'value': 'first-unchanging'}),
93
'value': 'second-unchanging'}),
96
make_entry_etag_cores(field_details),
97
['first-modifiable\0second-modifiable',
98
'first-writable\0second-writable'])