forked from ansible/awx
-
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.
Avoid updating modified_by from None to None (ansible#11838)
This should help the case of inventory updates in particular where imported hosts are managed by the system
- Loading branch information
1 parent
e87fabe
commit 4a8613c
Showing
2 changed files
with
45 additions
and
4 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
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,40 @@ | ||
from unittest import mock | ||
import pytest | ||
|
||
from crum import impersonate | ||
|
||
from awx.main.models import Host | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_modified_by_not_changed(inventory): | ||
with impersonate(None): | ||
host = Host.objects.create(name='foo', inventory=inventory) | ||
assert host.modified_by == None | ||
host.variables = {'foo': 'bar'} | ||
with mock.patch('django.db.models.Model.save') as save_mock: | ||
host.save(update_fields=['variables']) | ||
save_mock.assert_called_once_with(update_fields=['variables']) | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_modified_by_changed(inventory, alice): | ||
with impersonate(None): | ||
host = Host.objects.create(name='foo', inventory=inventory) | ||
assert host.modified_by == None | ||
with impersonate(alice): | ||
host.variables = {'foo': 'bar'} | ||
with mock.patch('django.db.models.Model.save') as save_mock: | ||
host.save(update_fields=['variables']) | ||
save_mock.assert_called_once_with(update_fields=['variables', 'modified_by']) | ||
assert host.modified_by == alice | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_created_by(inventory, alice): | ||
with impersonate(alice): | ||
host = Host.objects.create(name='foo', inventory=inventory) | ||
assert host.created_by == alice | ||
with impersonate(None): | ||
host = Host.objects.create(name='bar', inventory=inventory) | ||
assert host.created_by == None |