Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit a389475

Browse files
committed
Merge pull request #21 from ambitioninc/develop
Changed behavior of is_type filter
2 parents e21b3a1 + d895382 commit a389475

File tree

4 files changed

+25
-8
lines changed

4 files changed

+25
-8
lines changed

entity/models.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ def is_type(self, *entity_types):
4444
"""
4545
Returns entities that have any of the types listed in entity_types.
4646
"""
47-
return self.filter(entity_type__in=entity_types)
47+
return self.filter(entity_type__in=entity_types) if entity_types else self
4848

4949
def is_not_type(self, *entity_types):
5050
"""
5151
Returns entities that are not any of the types listed in entity_types.
5252
"""
53-
return self.exclude(entity_type__in=entity_types)
53+
return self.exclude(entity_type__in=entity_types) if entity_types else self
5454

5555
def cache_relationships(self):
5656
"""
@@ -153,9 +153,9 @@ def inactive(self):
153153
def is_type(self, *entity_types):
154154
"""
155155
Returns True if the entity's type is in any of the types given. If no entity types are given,
156-
returns False.
156+
returns True.
157157
"""
158-
return self.entity_type_id in (entity_type.id for entity_type in entity_types)
158+
return self.entity_type_id in (entity_type.id for entity_type in entity_types) if entity_types else True
159159

160160
def is_not_type(self, *entity_types):
161161
"""

entity/tests/entity_filtering_tests.py

+14
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,20 @@ def test_is_type_super_entities(self):
160160
self.assertEquals(
161161
list(account_entity.get_super_entities().is_type(self.team_type, self.account_type)), [team_entity])
162162

163+
def test_is_type_none(self):
164+
"""
165+
Tests the is_type method using no arguments
166+
"""
167+
# Create an account that belongs to a team
168+
team = Team.objects.create(name='Team')
169+
account = Account.objects.create(email='[email protected]', team=team)
170+
171+
# Get the entity related to the account
172+
account_entity = Entity.objects.get_for_obj(account)
173+
team_entity = Entity.objects.get_for_obj(team)
174+
self.assertEquals(
175+
set(account_entity.get_super_entities().is_type()), set([team_entity]))
176+
163177
def test_is_type_sub_entities(self):
164178
"""
165179
Tests the is_type method on sub entities.

entity/tests/model_tests.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,12 @@ def test_filter_manager_is_type_none(self):
128128
Tests filtering by entity type when no type is given.
129129
"""
130130
team = Team.objects.create()
131-
for i in range(5):
132-
Account.objects.create(team=team)
133-
self.assertEquals([], list(Entity.objects.is_type()))
131+
team_entity = Entity.objects.get_for_obj(team)
132+
account_entities = [
133+
Entity.objects.get_for_obj(Account.objects.create(team=team))
134+
for i in range(5)
135+
]
136+
self.assertEquals(set([team_entity] + account_entities), set(Entity.objects.is_type()))
134137

135138
def test_filter_manager_one_type(self):
136139
"""

entity/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.3.2'
1+
__version__ = '0.3.3'

0 commit comments

Comments
 (0)