Example #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 == []
Example #2
0
    def test_parse_yaml_file(self):
        """Test that parsing a yaml file works."""
        filename = os.path.join(os.path.dirname(__file__), 'files',
                                'file2.yaml')
        splits = LocalSplitSynchronizer._read_splits_from_yaml_file(filename)
        assert len(splits) == 4
        for split in splits.values():
            assert isinstance(split, Split)
        assert splits['my_feature'].name == 'my_feature'
        assert splits['other_feature'].name == 'other_feature'
        assert splits['other_feature_2'].name == 'other_feature_2'
        assert splits['other_feature_3'].name == 'other_feature_3'

        # test that all_keys conditions are pushed to the bottom so that they don't override
        # whitelists
        condition_types = [[
            cond.matchers[0].__class__.__name__ for cond in split.conditions
        ] for split in splits.values()]
        assert all(
            'WhitelistMatcher' not in
            c[c.index('AllKeysMatcher'):] if 'AllKeysMatcher' in c else True
            for c in condition_types)