def test_change_number(self, mocker): """Test storing and retrieving segment changeNumber.""" storage = InMemorySegmentStorage() storage.set_change_number('some_segment', 123) # Change number is not updated if segment doesn't exist assert storage.get_change_number('some_segment') is None assert storage.get_change_number('nonexistant-segment') is None # Change number is updated if segment does exist. storage = InMemorySegmentStorage() segment = mocker.Mock(spec=Segment) name_property = mocker.PropertyMock() name_property.return_value = 'some_segment' type(segment).name = name_property storage.put(segment) storage.set_change_number('some_segment', 123) assert storage.get_change_number('some_segment') == 123
def test_segment_update(self): """Test updating a segment.""" storage = InMemorySegmentStorage() segment = Segment('some_segment', ['key1', 'key2', 'key3'], 123) storage.put(segment) assert storage.get('some_segment') == segment storage.update('some_segment', ['key4', 'key5'], ['key2', 'key3'], 456) assert storage.segment_contains('some_segment', 'key1') assert storage.segment_contains('some_segment', 'key4') assert storage.segment_contains('some_segment', 'key5') assert not storage.segment_contains('some_segment', 'key2') assert not storage.segment_contains('some_segment', 'key3') assert storage.get_change_number('some_segment') == 456