-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Updating test matrix for 7.6 + removing oss for now. * Resolving 7.6.0 docs issues * Updating ML docs * Minor mod to support 6.x style indices. Currently, there is no specific test for this as it requires a 6.x cluster. 6.x is not officially supported by 7.x clients, but this is a friendly option for users. * Adding unittest for FieldMappings._extract_fields_from_mapping * Changing to f-string formatting and adding exception test * Reverting to OrderedDict Will change after elastic/eland#150 is merged.
- Loading branch information
1 parent
953e626
commit 9ff9d42
Showing
2 changed files
with
146 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
eland/tests/field_mappings/test_mappings_with_type_pytest.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
# Copyright 2020 Elasticsearch BV | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from collections import OrderedDict | ||
|
||
# File called _pytest for PyCharm compatability | ||
import pytest | ||
|
||
from eland import FieldMappings | ||
from eland.tests.common import TestData | ||
|
||
|
||
class TestMappingsWithType(TestData): | ||
|
||
def test_mappings_with_type(self): | ||
# Unless we spin up a 6.x index, this is difficult | ||
# to test. This is not ideal, but supporting some basic | ||
# features on 6.x indices makes eland more generally usable. | ||
# | ||
# For now, just test function: | ||
mapping7x = OrderedDict({ | ||
"my_index": { | ||
"mappings": { | ||
"properties": { | ||
"city": { | ||
"type": "text", | ||
"fields": { | ||
"keyword": { | ||
"type": "keyword" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}) | ||
|
||
expected7x_source_only_false = {'city': ('text', None), 'city.keyword': ('keyword', None)} | ||
expected7x_source_only_true = {'city': ('text', None)} | ||
|
||
mapping6x = OrderedDict({ | ||
"my_index": { | ||
"mappings": { | ||
"doc": { | ||
"properties": { | ||
"city": { | ||
"type": "text", | ||
"fields": { | ||
"keyword": { | ||
"type": "keyword" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}) | ||
|
||
expected6x_source_only_false = {'city': ('text', None), 'city.keyword': ('keyword', None)} | ||
expected6x_source_only_true = {'city': ('text', None)} | ||
|
||
# add a 5x mapping to get coverage of error | ||
mapping5x = OrderedDict({ | ||
"my_index": { | ||
"mappings": { | ||
"user": { | ||
"properties": { | ||
"name": {"type": "text"}, | ||
"user_name": {"type": "keyword"}, | ||
"email": {"type": "keyword"} | ||
} | ||
}, | ||
"tweet": { | ||
"properties": { | ||
"content": {"type": "text"}, | ||
"user_name": {"type": "keyword"}, | ||
"tweeted_at": {"type": "date"} | ||
} | ||
} | ||
} | ||
} | ||
}) | ||
|
||
result7x = FieldMappings._extract_fields_from_mapping(mapping7x) | ||
assert expected7x_source_only_false == result7x | ||
|
||
result7x = FieldMappings._extract_fields_from_mapping(mapping7x, source_only=True) | ||
assert expected7x_source_only_true == result7x | ||
|
||
result6x = FieldMappings._extract_fields_from_mapping(mapping6x) | ||
assert expected6x_source_only_false == result6x | ||
|
||
result6x = FieldMappings._extract_fields_from_mapping(mapping6x, source_only=True) | ||
assert expected6x_source_only_true == result6x | ||
|
||
with pytest.raises(NotImplementedError): | ||
FieldMappings._extract_fields_from_mapping(mapping5x) |