-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest_taxonomies.py
More file actions
99 lines (86 loc) · 3.73 KB
/
test_taxonomies.py
File metadata and controls
99 lines (86 loc) · 3.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import logging
import unittest
import config
import contentstack
import pytest
API_KEY = config.APIKEY
DELIVERY_TOKEN = config.DELIVERYTOKEN
ENVIRONMENT = config.ENVIRONMENT
HOST = config.HOST
class TestTaxonomyAPI(unittest.TestCase):
def setUp(self):
self.stack = contentstack.Stack(API_KEY, DELIVERY_TOKEN, ENVIRONMENT, host=HOST)
def test_01_taxonomy_complex_query(self):
"""Test complex taxonomy query combining multiple filters"""
taxonomy = self.stack.taxonomy()
result = taxonomy.and_(
{"taxonomies.category": {"$in": ["test"]}},
{"taxonomies.test1": {"$exists": True}}
).or_(
{"taxonomies.status": {"$in": ["active"]}},
{"taxonomies.priority": {"$in": ["high"]}}
).find({'limit': 10})
if result is not None:
self.assertIn('entries', result)
def test_02_taxonomy_in_query(self):
"""Test taxonomy query with $in filter"""
taxonomy = self.stack.taxonomy()
result = taxonomy.in_("taxonomies.category", ["category1", "category2"]).find()
if result is not None:
self.assertIn('entries', result)
def test_03_taxonomy_exists_query(self):
"""Test taxonomy query with $exists filter"""
taxonomy = self.stack.taxonomy()
result = taxonomy.exists("taxonomies.test1").find()
if result is not None:
self.assertIn('entries', result)
def test_04_taxonomy_or_query(self):
"""Test taxonomy query with $or filter"""
taxonomy = self.stack.taxonomy()
result = taxonomy.or_(
{"taxonomies.category": {"$in": ["category1"]}},
{"taxonomies.test1": {"$exists": True}}
).find()
if result is not None:
self.assertIn('entries', result)
def test_05_taxonomy_and_query(self):
"""Test taxonomy query with $and filter"""
taxonomy = self.stack.taxonomy()
result = taxonomy.and_(
{"taxonomies.category": {"$in": ["category1"]}},
{"taxonomies.test1": {"$exists": True}}
).find()
if result is not None:
self.assertIn('entries', result)
def test_06_taxonomy_equal_and_below(self):
"""Test taxonomy query with $eq_below filter"""
taxonomy = self.stack.taxonomy()
result = taxonomy.equal_and_below("taxonomies.color", "blue", levels=1).find()
if result is not None:
self.assertIn('entries', result)
def test_07_taxonomy_below(self):
"""Test taxonomy query with $below filter"""
taxonomy = self.stack.taxonomy()
result = taxonomy.below("taxonomies.hierarchy", "parent_uid", levels=2).find()
if result is not None:
self.assertIn('entries', result)
def test_08_taxonomy_equal_and_above(self):
"""Test taxonomy query with $eq_above filter"""
taxonomy = self.stack.taxonomy()
result = taxonomy.equal_and_above("taxonomies.hierarchy", "child_uid", levels=3).find()
if result is not None:
self.assertIn('entries', result)
def test_09_taxonomy_above(self):
"""Test taxonomy query with $above filter"""
taxonomy = self.stack.taxonomy()
result = taxonomy.above("taxonomies.hierarchy", "child_uid", levels=2).find()
if result is not None:
self.assertIn('entries', result)
def test_10_taxonomy_find_with_params(self):
"""Test taxonomy find with additional parameters"""
taxonomy = self.stack.taxonomy()
result = taxonomy.in_("taxonomies.category", ["test"]).find({'limit': 5})
if result is not None:
self.assertIn('entries', result)
if __name__ == '__main__':
unittest.main()