Beispiel #1
0
    def test_update_splits(self, mocker):
        """Test update spltis."""
        parse_legacy = mocker.Mock()
        parse_legacy.return_value = {}
        parse_yaml = mocker.Mock()
        parse_yaml.return_value = {}
        storage_mock = mocker.Mock(spec=SplitStorage)
        storage_mock.get_split_names.return_value = []

        parse_legacy.reset_mock()
        parse_yaml.reset_mock()
        sync = LocalSplitSynchronizer('something', storage_mock)
        sync._read_splits_from_legacy_file = parse_legacy
        sync._read_splits_from_yaml_file = parse_yaml
        sync.synchronize_splits()
        assert parse_legacy.mock_calls == [mocker.call('something')]
        assert parse_yaml.mock_calls == []

        parse_legacy.reset_mock()
        parse_yaml.reset_mock()
        sync = LocalSplitSynchronizer('something.yaml', storage_mock)
        sync._read_splits_from_legacy_file = parse_legacy
        sync._read_splits_from_yaml_file = parse_yaml
        sync.synchronize_splits()
        assert parse_legacy.mock_calls == []
        assert parse_yaml.mock_calls == [mocker.call('something.yaml')]

        parse_legacy.reset_mock()
        parse_yaml.reset_mock()
        sync = LocalSplitSynchronizer('something.yml', storage_mock)
        sync._read_splits_from_legacy_file = parse_legacy
        sync._read_splits_from_yaml_file = parse_yaml
        sync.synchronize_splits()
        assert parse_legacy.mock_calls == []
        assert parse_yaml.mock_calls == [mocker.call('something.yml')]

        parse_legacy.reset_mock()
        parse_yaml.reset_mock()
        sync = LocalSplitSynchronizer('something.YAML', storage_mock)
        sync._read_splits_from_legacy_file = parse_legacy
        sync._read_splits_from_yaml_file = parse_yaml
        sync.synchronize_splits()
        assert parse_legacy.mock_calls == []
        assert parse_yaml.mock_calls == [mocker.call('something.YAML')]

        parse_legacy.reset_mock()
        parse_yaml.reset_mock()
        sync = LocalSplitSynchronizer('yaml', storage_mock)
        sync._read_splits_from_legacy_file = parse_legacy
        sync._read_splits_from_yaml_file = parse_yaml
        sync.synchronize_splits()
        assert parse_legacy.mock_calls == [mocker.call('yaml')]
        assert parse_yaml.mock_calls == []
Beispiel #2
0
 def test_parse_legacy_file(self):
     """Test that aprsing a legacy file works."""
     filename = os.path.join(os.path.dirname(__file__), 'files',
                             'file1.split')
     splits = LocalSplitSynchronizer._read_splits_from_legacy_file(filename)
     assert len(splits) == 2
     for split in splits.values():
         assert isinstance(split, Split)
     assert splits['split1'].name == 'split1'
     assert splits['split2'].name == 'split2'
     assert isinstance(splits['split1'].conditions[0].matchers[0],
                       AllKeysMatcher)
     assert isinstance(splits['split2'].conditions[0].matchers[0],
                       AllKeysMatcher)