Refactor dummy version creation method
Add argument to be able to create both Version and RadioVersion
instances with the same method.
Issue: HIC-221
Change-Id: I0cc4d5fe658c4f15a650281613ba8f02718eafbd
diff --git a/crashreport_stats/tests/test_rest_endpoints.py b/crashreport_stats/tests/test_rest_endpoints.py
index 623f86a..7cef128 100644
--- a/crashreport_stats/tests/test_rest_endpoints.py
+++ b/crashreport_stats/tests/test_rest_endpoints.py
@@ -243,7 +243,7 @@
@staticmethod
def _create_dummy_version(**kwargs):
- return Dummy.create_dummy_radio_version(**kwargs)
+ return Dummy.create_dummy_version(RadioVersion, **kwargs)
class VersionDailyTestCase(_VersionTestCase):
@@ -348,13 +348,7 @@
@staticmethod
def _create_dummy_version(**kwargs):
- entity = RadioVersion(
- **Dummy.update_copy(
- Dummy.DEFAULT_DUMMY_RADIO_VERSION_VALUES, kwargs
- )
- )
- entity.save()
- return entity
+ return Dummy.create_dummy_version(RadioVersion, **kwargs)
@staticmethod
def _create_dummy_daily_version(version, **kwargs):
diff --git a/crashreport_stats/tests/test_stats_management_command.py b/crashreport_stats/tests/test_stats_management_command.py
index 2bd5df9..d6d0221 100644
--- a/crashreport_stats/tests/test_stats_management_command.py
+++ b/crashreport_stats/tests/test_stats_management_command.py
@@ -657,7 +657,7 @@
"""
# Create dummy version instances
version = Dummy.create_dummy_version()
- radio_version = Dummy.create_dummy_radio_version()
+ radio_version = Dummy.create_dummy_version(RadioVersion)
Dummy.create_dummy_daily_version(version)
Dummy.create_dummy_daily_radio_version(radio_version)
Dummy.create_dummy_stats_metadata()
diff --git a/crashreport_stats/tests/utils.py b/crashreport_stats/tests/utils.py
index c7c85f8..d8f0d9d 100644
--- a/crashreport_stats/tests/utils.py
+++ b/crashreport_stats/tests/utils.py
@@ -221,40 +221,37 @@
return archive.read(logfile_name)
@staticmethod
- def create_dummy_version(**kwargs):
+ def create_dummy_version(version_type=Version, **kwargs):
"""Create a dummy version instance.
The dummy instance is created and saved to the database.
Args:
+ version_type: The class of the version type to be created.
**kwargs:
Optional arguments to extend/overwrite the default values.
Returns: The created version instance.
- """
- entity = Version(
- **Dummy.update_copy(Dummy.DEFAULT_DUMMY_VERSION_VALUES, kwargs)
- )
- entity.save()
- return entity
-
- @staticmethod
- def create_dummy_radio_version(**kwargs):
- """Create a dummy radio version instance.
-
- The dummy instance is created and saved to the database.
- Args:
- **kwargs:
- Optional arguments to extend/overwrite the default values.
-
- Returns: The created radio version instance.
+ Raises:
+ ValueError: If version_type is not a valid version class type.
"""
- entity = RadioVersion(
- **Dummy.update_copy(
- Dummy.DEFAULT_DUMMY_RADIO_VERSION_VALUES, kwargs
+ if version_type == Version:
+ entity = Version(
+ **Dummy.update_copy(Dummy.DEFAULT_DUMMY_VERSION_VALUES, kwargs)
)
- )
+ elif version_type == RadioVersion:
+ entity = RadioVersion(
+ **Dummy.update_copy(
+ Dummy.DEFAULT_DUMMY_RADIO_VERSION_VALUES, kwargs
+ )
+ )
+ else:
+ raise ValueError(
+ "No dummy version instance can be created for {}".format(
+ version_type.__name__
+ )
+ )
entity.save()
return entity