Skip to content
Snippets Groups Projects
Commit b833308f authored by Martin Burchell's avatar Martin Burchell
Browse files

Refactored tests

parent 19a41aee
No related branches found
No related tags found
1 merge request!7Data Layer updates a "last edit date" field on the Item
......@@ -34,29 +34,32 @@ def num_updates(old_time, new_time):
return elapsed_time.seconds / time_granularity().seconds
@pytest.mark.django_db
def test_last_modified_date_updates_on_body_change():
item = ItemFactory()
magic_mock = MagicMock(wraps=timezone.now,
side_effect=now_iter(timezone.now()))
@pytest.fixture
def item():
return ItemFactory()
@pytest.fixture
def mock_time_now():
return MagicMock(wraps=timezone.now,
side_effect=now_iter(timezone.now()))
with patch('django.utils.timezone.now', new=magic_mock):
@pytest.mark.django_db
def test_last_modified_date_updates_on_body_change(item, mock_time_now):
with patch('django.utils.timezone.now', new=mock_time_now):
orig_last_modified = last_modified(item)
item.body = 'replacement text'
item.save()
assert num_updates(orig_last_modified, last_modified(item)) == 1
assert num_updates(orig_last_modified, last_modified(item)) == 1
@pytest.mark.django_db
def test_last_modified_date_updates_on_category_change():
item = ItemFactory()
magic_mock = MagicMock(wraps=timezone.now,
side_effect=now_iter(timezone.now()))
with patch('django.utils.timezone.now', new=magic_mock):
def test_last_modified_date_updates_on_category_change(item, mock_time_now):
with patch('django.utils.timezone.now', new=mock_time_now):
orig_last_modified = last_modified(item)
term = TermFactory()
item.terms.add(term)
assert num_updates(orig_last_modified, last_modified(item)) == 1
assert num_updates(orig_last_modified, last_modified(item)) == 1
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment