|
10 | 10 | from rest_framework import status
|
11 | 11 | from rest_framework.exceptions import ValidationError
|
12 | 12 |
|
13 |
| -from airone.lib.elasticsearch import FilterKey |
14 | 13 | from airone.lib.log import Logger
|
15 | 14 | from airone.lib.test import AironeViewTest
|
16 | 15 | from airone.lib.types import (
|
|
36 | 35 | from user.models import User
|
37 | 36 |
|
38 | 37 |
|
39 |
| -class ViewTest(AironeViewTest): |
40 |
| - def _create_user( |
41 |
| - self, |
42 |
| - name, |
43 |
| - email="email", |
44 |
| - is_superuser=False, |
45 |
| - authenticate_type=User.AuthenticateType.AUTH_TYPE_LOCAL, |
46 |
| - ): |
47 |
| - user = User( |
48 |
| - username=name, |
49 |
| - email=email, |
50 |
| - is_superuser=is_superuser, |
51 |
| - authenticate_type=authenticate_type, |
52 |
| - ) |
53 |
| - user.set_password(name) |
54 |
| - user.save() |
55 |
| - |
56 |
| - return user |
57 |
| - |
| 38 | +class BaseViewTest(AironeViewTest): |
58 | 39 | def setUp(self):
|
59 |
| - super(ViewTest, self).setUp() |
| 40 | + super(BaseViewTest, self).setUp() |
60 | 41 |
|
61 | 42 | self.user: User = self.guest_login()
|
62 | 43 |
|
@@ -87,6 +68,26 @@ def setUp(self):
|
87 | 68 | }
|
88 | 69 | )
|
89 | 70 |
|
| 71 | + |
| 72 | +class ViewTest(BaseViewTest): |
| 73 | + def _create_user( |
| 74 | + self, |
| 75 | + name, |
| 76 | + email="email", |
| 77 | + is_superuser=False, |
| 78 | + authenticate_type=User.AuthenticateType.AUTH_TYPE_LOCAL, |
| 79 | + ): |
| 80 | + user = User( |
| 81 | + username=name, |
| 82 | + email=email, |
| 83 | + is_superuser=is_superuser, |
| 84 | + authenticate_type=authenticate_type, |
| 85 | + ) |
| 86 | + user.set_password(name) |
| 87 | + user.save() |
| 88 | + |
| 89 | + return user |
| 90 | + |
90 | 91 | def test_retrieve_entry(self):
|
91 | 92 | entry: Entry = self.add_entry(
|
92 | 93 | self.user,
|
@@ -3155,189 +3156,6 @@ def test_advanced_search(self):
|
3155 | 3156 | },
|
3156 | 3157 | )
|
3157 | 3158 |
|
3158 |
| - def test_advanced_search_with_join_attrs(self): |
3159 |
| - # create Items to be search by join_attrs parameter |
3160 |
| - ref_entries = [ |
3161 |
| - self.add_entry( |
3162 |
| - self.user, |
3163 |
| - "RefEntry-%s" % i, |
3164 |
| - self.ref_entity, |
3165 |
| - values={ |
3166 |
| - "val": "hoge-%s" % i if i % 2 == 0 else "", |
3167 |
| - "ref": self.ref_entry.id, |
3168 |
| - "name": {"name": "abcd-%s" % i, "id": self.ref_entry.id}, |
3169 |
| - }, |
3170 |
| - ) |
3171 |
| - for i in range(2) |
3172 |
| - ] |
3173 |
| - |
3174 |
| - # create Items that are search by ordinary processing |
3175 |
| - for index, (val, ref_id) in enumerate( |
3176 |
| - [ |
3177 |
| - ("foo", ref_entries[0].id), |
3178 |
| - ("bar", ref_entries[0].id), |
3179 |
| - ("baz", ref_entries[1].id), |
3180 |
| - ("qux", None), |
3181 |
| - ] |
3182 |
| - ): |
3183 |
| - self.add_entry( |
3184 |
| - self.user, |
3185 |
| - "Entry%s" % index, |
3186 |
| - self.entity, |
3187 |
| - values={ |
3188 |
| - "val": val, |
3189 |
| - "ref": ref_id, |
3190 |
| - "name": {"name": "fuga", "id": ref_id}, |
3191 |
| - }, |
3192 |
| - ) |
3193 |
| - |
3194 |
| - # send request to search Entries with join_attrs |
3195 |
| - params = { |
3196 |
| - "entities": [self.entity.id], |
3197 |
| - "attrinfo": [ |
3198 |
| - {"name": "val"}, |
3199 |
| - {"name": "ref"}, |
3200 |
| - {"name": "name"}, |
3201 |
| - ], |
3202 |
| - "join_attrs": [ |
3203 |
| - { |
3204 |
| - "name": "ref", |
3205 |
| - "attrinfo": [ |
3206 |
| - {"name": "val"}, |
3207 |
| - {"name": "ref"}, |
3208 |
| - {"name": "name"}, |
3209 |
| - ], |
3210 |
| - }, |
3211 |
| - ], |
3212 |
| - } |
3213 |
| - resp = self.client.post( |
3214 |
| - "/entry/api/v2/advanced_search/", json.dumps(params), "application/json" |
3215 |
| - ) |
3216 |
| - self.assertEqual(resp.status_code, 200) |
3217 |
| - |
3218 |
| - # prepare comparison data with returned result |
3219 |
| - REF_DATA = {"id": self.ref_entry.id, "name": self.ref_entry.name} |
3220 |
| - expected_results = [ |
3221 |
| - ( |
3222 |
| - "Entry0", |
3223 |
| - { |
3224 |
| - "ref.val": {"as_string": "hoge-0"}, |
3225 |
| - "ref.ref": {"as_object": REF_DATA}, |
3226 |
| - "ref.name": {"as_named_object": {"name": "abcd-0", "object": REF_DATA}}, |
3227 |
| - }, |
3228 |
| - ), |
3229 |
| - ( |
3230 |
| - "Entry1", |
3231 |
| - { |
3232 |
| - "ref.val": {"as_string": "hoge-0"}, |
3233 |
| - "ref.ref": {"as_object": REF_DATA}, |
3234 |
| - "ref.name": {"as_named_object": {"name": "abcd-0", "object": REF_DATA}}, |
3235 |
| - }, |
3236 |
| - ), |
3237 |
| - ( |
3238 |
| - "Entry2", |
3239 |
| - { |
3240 |
| - "ref.val": {"as_string": ""}, |
3241 |
| - "ref.ref": {"as_object": REF_DATA}, |
3242 |
| - "ref.name": {"as_named_object": {"name": "abcd-1", "object": REF_DATA}}, |
3243 |
| - }, |
3244 |
| - ), |
3245 |
| - ( |
3246 |
| - "Entry3", |
3247 |
| - { |
3248 |
| - "ref.val": {"as_string": ""}, |
3249 |
| - "ref.ref": {"as_string": ""}, |
3250 |
| - "ref.name": {"as_string": ""}, |
3251 |
| - }, |
3252 |
| - ), |
3253 |
| - ] |
3254 |
| - |
3255 |
| - # check returned processing has expected values |
3256 |
| - for index, result in enumerate(resp.json()["values"]): |
3257 |
| - (e_name, e_attrinfo) = expected_results[index] |
3258 |
| - self.assertEqual(result["entry"]["name"], e_name) |
3259 |
| - |
3260 |
| - for attrname, attrvalue in e_attrinfo.items(): |
3261 |
| - self.assertEqual(result["attrs"][attrname]["value"], attrvalue) |
3262 |
| - |
3263 |
| - # This sends request with keyword in join_attrs parameter and |
3264 |
| - # confirms filter processing works with its filter parameter of attrinfo |
3265 |
| - params = { |
3266 |
| - "entities": [self.entity.id], |
3267 |
| - "attrinfo": [ |
3268 |
| - {"name": "val", "keyword": "bar"}, |
3269 |
| - {"name": "ref"}, |
3270 |
| - ], |
3271 |
| - "join_attrs": [ |
3272 |
| - { |
3273 |
| - "name": "ref", |
3274 |
| - "attrinfo": [ |
3275 |
| - {"name": "val", "keyword": "hoge-0"}, |
3276 |
| - ], |
3277 |
| - }, |
3278 |
| - ], |
3279 |
| - } |
3280 |
| - resp = self.client.post( |
3281 |
| - "/entry/api/v2/advanced_search/", json.dumps(params), "application/json" |
3282 |
| - ) |
3283 |
| - self.assertEqual(resp.status_code, 200) |
3284 |
| - self.assertEqual([x["entry"]["name"] for x in resp.json()["values"]], ["Entry1"]) |
3285 |
| - |
3286 |
| - # This sends request with join_attrs that have filter_key to get empty Items |
3287 |
| - params = { |
3288 |
| - "entities": [self.entity.id], |
3289 |
| - "attrinfo": [], |
3290 |
| - "join_attrs": [ |
3291 |
| - { |
3292 |
| - "name": "ref", |
3293 |
| - "attrinfo": [ |
3294 |
| - {"name": "val", "filter_key": FilterKey.EMPTY}, |
3295 |
| - ], |
3296 |
| - }, |
3297 |
| - ], |
3298 |
| - } |
3299 |
| - resp = self.client.post( |
3300 |
| - "/entry/api/v2/advanced_search/", json.dumps(params), "application/json" |
3301 |
| - ) |
3302 |
| - self.assertEqual(resp.status_code, 200) |
3303 |
| - self.assertEqual([x["entry"]["name"] for x in resp.json()["values"]], ["Entry2"]) |
3304 |
| - self.assertEqual( |
3305 |
| - [x["attrs"]["ref.val"]["value"] for x in resp.json()["values"]], [{"as_string": ""}] |
3306 |
| - ) |
3307 |
| - |
3308 |
| - # This sends request with join_attrs that have filter_key to get non-empty Items |
3309 |
| - params = { |
3310 |
| - "entities": [self.entity.id], |
3311 |
| - "attrinfo": [], |
3312 |
| - "join_attrs": [ |
3313 |
| - { |
3314 |
| - "name": "ref", |
3315 |
| - "attrinfo": [ |
3316 |
| - {"name": "val", "filter_key": FilterKey.NON_EMPTY}, |
3317 |
| - ], |
3318 |
| - }, |
3319 |
| - ], |
3320 |
| - } |
3321 |
| - resp = self.client.post( |
3322 |
| - "/entry/api/v2/advanced_search/", json.dumps(params), "application/json" |
3323 |
| - ) |
3324 |
| - self.assertEqual(resp.status_code, 200) |
3325 |
| - self.assertEqual([x["entry"]["name"] for x in resp.json()["values"]], ["Entry0", "Entry1"]) |
3326 |
| - self.assertEqual( |
3327 |
| - [x["attrs"]["ref.val"]["value"] for x in resp.json()["values"]], |
3328 |
| - [ |
3329 |
| - {"as_string": "hoge-0"}, |
3330 |
| - {"as_string": "hoge-0"}, |
3331 |
| - ], |
3332 |
| - ) |
3333 |
| - |
3334 |
| - def test_advanced_search_with_join_attrs_that_have_filter_key1(self): |
3335 |
| - """ |
3336 |
| - Test advanced_search APIv2 with join_attrs parameter that have |
3337 |
| - valid filter_key attribute. |
3338 |
| - """ |
3339 |
| - pass |
3340 |
| - |
3341 | 3159 | def test_advanced_search_all_entities(self):
|
3342 | 3160 | params = {
|
3343 | 3161 | "entities": [],
|
|
0 commit comments