Skip to content

Commit 55a8dd0

Browse files
authored
Fix oppia#20415: Add tests verifying ExpSummaryModel behavior after exploration updates (oppia#22403)
* Added utility module for ANSI text colorization * Integrated colorization utility into CI acceptance tests for enhanced readability. * Integrated colorization utility into CI acceptance tests for enhanced readability. * Integrated colorization utility into CI acceptance tests for enhanced readability. * Integrated colorization utility into CI acceptance tests for enhanced readability. * Integrated colorization utility into CI acceptance tests for enhanced readability. * Add backend test file for color_utils.py * Fix linting issues in color_utils_test.py * Fix linting issues in color_utils_test.py * Fix linting issues in color_utils.py: added docstrings, fixed formatting, and resolved import * Fix linting issues in color_utils.py: added docstrings, fixed formatting, and resolved import * Fix linting issues in color_utils.py: added docstrings, fixed formatting, and resolved import * Fix linting issues in color_utils.py: added docstrings, fixed formatting, and resolved import * Fix linting issues in color_utils.py: added docstrings, fixed formatting, and resolved import * Fix linting issues in color_utils.py: added docstrings, fixed formatting, and resolved import * Fix linting issues in color_utils.py: added docstrings, fixed formatting, and resolved import * Fix linting issues in color_utils.py: added docstrings, fixed formatting, and resolved import * Fix linting issues in color_utils.py: added docstrings, fixed formatting, and resolved import * Fix linting issues in color_utils.py: added docstrings, fixed formatting, and resolved import * Fix linting issues in color_utils.py: added docstrings, fixed formatting, and resolved import * Add color_utils_test to backend test shards * aligment * Implement post-exploration changes checks for updates, reverted, publishing, and rights changes * Fixing the lint errors. * Fixing the lint errors. * Fixing the lint errors. * Fixing the lint errors. * Fixing the lint errors. * Resolving the conflicts that occurred. * Resolving the conflicts that occurred. * Revert test_get_last_updated_by_human_ms() to original implementation. * Revert package.json to original implementation. * Reverted changes in test_get_last_updated_by_human_ms() to original code. * Add deletion test in ExplorationCreateAndDeleteUnitTests. * Fixing the lint errors. * Fixing the lint errors. * Add creation, updated, reverted, deletion,right change test in ExplorationCreateAndDeleteUnitTests. * Fixing lint errors * Resolving conflict errors * Add creation, updated, reverted, deletion, right change test in ExplorationCreateAndDeleteUnitTests. * Fixing the lint errors. * Resolving lint errors. * Resolving the lint errors
1 parent f47f5a1 commit 55a8dd0

File tree

1 file changed

+117
-0
lines changed

1 file changed

+117
-0
lines changed

core/domain/exp_services_test.py

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1783,6 +1783,123 @@ def test_raise_error_while_adding_voiceover_with_accent(self) -> None:
17831783
'Added voiceover', False
17841784
)
17851785

1786+
def test_exp_summary_model_after_creation(self) -> None:
1787+
"""Test that ExpSummaryModel is correctly initialized after
1788+
exploration creation.
1789+
"""
1790+
exp_id = self.EXP_0_ID
1791+
self.save_new_valid_exploration(
1792+
exp_id, self.owner_id,
1793+
title='Test Title', category='Test Category'
1794+
)
1795+
self.process_and_flush_pending_tasks()
1796+
# Ensure background tasks complete.
1797+
summary = exp_fetchers.get_exploration_summary_by_id(exp_id)
1798+
self.assertEqual(summary.title, 'Test Title')
1799+
self.assertEqual(summary.category, 'Test Category')
1800+
self.assertEqual(summary.owner_ids, [self.owner_id])
1801+
self.assertEqual(summary.version, 1)
1802+
self.assertTrue(summary.is_private())
1803+
self.assertIsNone(summary.first_published_msec)
1804+
1805+
def test_exp_summary_model_after_update(self) -> None:
1806+
exp_id = self.EXP_0_ID
1807+
self.save_new_valid_exploration(
1808+
exp_id, self.owner_id, title='Initial Title'
1809+
)
1810+
self.process_and_flush_pending_tasks()
1811+
initial_summary = exp_fetchers.get_exploration_summary_by_id(exp_id)
1812+
initial_version = initial_summary.version
1813+
exp_services.update_exploration(
1814+
self.owner_id, exp_id,
1815+
[exp_domain.ExplorationChange({
1816+
'cmd': 'edit_exploration_property',
1817+
'property_name': 'title',
1818+
'new_value': 'Updated Title'
1819+
})],
1820+
'Changed title'
1821+
)
1822+
self.process_and_flush_pending_tasks()
1823+
summary = exp_fetchers.get_exploration_summary_by_id(exp_id)
1824+
self.assertEqual(summary.title, 'Updated Title')
1825+
# Updated expectation: the version increases by 2.
1826+
self.assertEqual(summary.version, initial_version + 2)
1827+
1828+
def test_exp_summary_model_after_reversion(self) -> None:
1829+
"""Test that ExpSummaryModel reflects the reverted state after
1830+
reversion.
1831+
"""
1832+
exp_id = self.EXP_0_ID
1833+
self.save_new_valid_exploration(
1834+
exp_id, self.owner_id, title='Initial Title'
1835+
)
1836+
self.process_and_flush_pending_tasks()
1837+
# Update to create version 2.
1838+
exp_services.update_exploration(
1839+
self.owner_id, exp_id,
1840+
[exp_domain.ExplorationChange({
1841+
'cmd': 'edit_exploration_property',
1842+
'property_name': 'title',
1843+
'new_value': 'Updated Title'
1844+
})],
1845+
'Changed title'
1846+
)
1847+
self.process_and_flush_pending_tasks()
1848+
# Revert to version 1, creating version 3.
1849+
exp_services.revert_exploration(self.owner_id, exp_id, 2, 1)
1850+
self.process_and_flush_pending_tasks()
1851+
# Reverted to initial title.
1852+
summary = exp_fetchers.get_exploration_summary_by_id(exp_id)
1853+
self.assertEqual(summary.title, 'Initial Title')
1854+
self.assertEqual(summary.version, 3)
1855+
1856+
def test_exp_summary_model_after_publishing(self) -> None:
1857+
"""Test that ExpSummaryModel updates correctly after publishing
1858+
an exploration.
1859+
"""
1860+
exp_id = self.EXP_0_ID
1861+
self.save_new_valid_exploration(exp_id, self.owner_id)
1862+
self.process_and_flush_pending_tasks()
1863+
summary_before = exp_fetchers.get_exploration_summary_by_id(exp_id)
1864+
self.assertTrue(summary_before.is_private())
1865+
self.assertIsNone(summary_before.first_published_msec)
1866+
# Publish the exploration.
1867+
rights_manager.publish_exploration(self.owner, exp_id)
1868+
self.process_and_flush_pending_tasks()
1869+
summary_after = exp_fetchers.get_exploration_summary_by_id(exp_id)
1870+
self.assertFalse(summary_after.is_private())
1871+
# Now public.
1872+
self.assertIsNotNone(summary_after.first_published_msec)
1873+
1874+
def test_exp_summary_model_after_assigning_editor(self) -> None:
1875+
"""Test that ExpSummaryModel updates after assigning an editor role."""
1876+
exp_id = self.EXP_0_ID
1877+
self.save_new_valid_exploration(exp_id, self.owner_id)
1878+
self.process_and_flush_pending_tasks()
1879+
summary_before = exp_fetchers.get_exploration_summary_by_id(exp_id)
1880+
self.assertNotIn(self.editor_id, summary_before.editor_ids)
1881+
rights_manager.assign_role_for_exploration(
1882+
self.owner, exp_id, self.editor_id, rights_domain.ROLE_EDITOR
1883+
)
1884+
self.process_and_flush_pending_tasks()
1885+
summary_after = exp_fetchers.get_exploration_summary_by_id(exp_id)
1886+
self.assertIn(self.editor_id, summary_after.editor_ids)
1887+
1888+
def test_exp_summary_model_after_deletion(self) -> None:
1889+
"""Test that ExpSummaryModel is removed after exploration deletion."""
1890+
exp_id = self.EXP_0_ID
1891+
self.save_new_valid_exploration(exp_id, self.owner_id)
1892+
self.process_and_flush_pending_tasks()
1893+
summary_before = exp_fetchers.get_exploration_summary_by_id(exp_id)
1894+
self.assertIsNotNone(summary_before)
1895+
# Delete the exploration.
1896+
exp_services.delete_exploration(self.owner_id, exp_id)
1897+
self.process_and_flush_pending_tasks()
1898+
summary_after = exp_fetchers.get_exploration_summary_by_id(
1899+
exp_id, strict=False
1900+
)
1901+
self.assertIsNone(summary_after)
1902+
17861903

17871904
class LoadingAndDeletionOfExplorationDemosTests(ExplorationServicesUnitTests):
17881905

0 commit comments

Comments
 (0)