Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gagantrivedi committed Jan 27, 2025
1 parent 7b33b15 commit 2c01365
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 10 deletions.
27 changes: 19 additions & 8 deletions api/segments/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,15 @@ def __str__(self):
)

def get_skip_create_audit_log(self) -> bool:
segment = self.get_segment()
if segment.deleted_at:
try:
segment = self.get_segment()
if segment.deleted_at:
return True
return segment.version_of_id != segment.id
except (Segment.DoesNotExist, SegmentRule.DoesNotExist):
# handle hard delete
return True

return segment.version_of_id != segment.id

def _get_project(self) -> typing.Optional[Project]:
return self.get_segment().project

Expand Down Expand Up @@ -363,11 +366,19 @@ def __str__(self):
)

def get_skip_create_audit_log(self) -> bool:
if self.rule.deleted_at:
return True
try:

segment = self.rule.get_segment()
return segment.version_of_id != segment.id
if self.rule.deleted_at:
return True

segment = self.rule.get_segment()
if segment.deleted_at:
return True

return segment.version_of_id != segment.id
except (Segment.DoesNotExist, SegmentRule.DoesNotExist):
# handle hard delete
return True

def get_update_log_message(self, history_instance) -> typing.Optional[str]:
return f"Condition updated on segment '{self._get_segment().name}'."
Expand Down
35 changes: 34 additions & 1 deletion api/tests/unit/segments/test_unit_segments_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,24 @@ def test__condition_get_skip_create_audit_log_on_segment_delete(
assert condition.get_skip_create_audit_log() is True


def test__condition_get_skip_create_audit_log_on_segment_hard_delete(
segment_rule: SegmentRule, segment: Segment
) -> None:
# Given
condition = Condition.objects.create(
rule=segment_rule,
property="foo",
operator=EQUAL,
value="bar",
created_with_segment=False,
)
# When
segment.delete()

# Then
assert condition.get_skip_create_audit_log() is True


def test_condition_get_delete_log_message_for_deleted_segment(
segment, segment_rule, mocker
):
Expand Down Expand Up @@ -440,6 +458,21 @@ def test_deep_clone_of_segment_with_grandchild_rule(
)


def test_segment_rule_get_skip_create_on_segment_hard_delete(
segment: Segment,
) -> None:
# Given
segment_rule = SegmentRule.objects.create(
segment=segment, type=SegmentRule.ALL_RULE
)

# When
segment.hard_delete()

# Then
assert segment_rule.get_skip_create_audit_log() is True


def test_segment_rule_get_skip_create_on_segment_delete(
segment: Segment,
) -> None:
Expand All @@ -452,7 +485,7 @@ def test_segment_rule_get_skip_create_on_segment_delete(
segment.delete()

# Then
assert segment_rule.get_skip_create_audit_log() is False
assert segment_rule.get_skip_create_audit_log() is True


def test_segment_rule_get_skip_create_audit_log_when_doesnt_skip(
Expand Down
2 changes: 1 addition & 1 deletion api/tests/unit/users/test_unit_users_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ def test_delete_user_social_auth_with_no_password(password):
@pytest.mark.django_db
def test_change_email_address_api(mocker):
# Given
mocked_task = mocker.patch("users.signals.send_email_changed_notification_email")
mocked_task = mocker.patch("users.tasks.send_email_changed_notification_email")
# create an user
old_email = "test_user@test.com"
first_name = "firstname"
Expand Down

0 comments on commit 2c01365

Please sign in to comment.