Add tests for creating stats from reports of different devices

These test cases are more realistic as the counters have to be
calculated by accumulating the reports from different devices.

Issue: HIC-184
Change-Id: I9e18d58f66c4eb8d6dc2fb44be908ef1feff382b
diff --git a/crashreport_stats/tests/test_stats_management_command.py b/crashreport_stats/tests/test_stats_management_command.py
index 51860e9..2bd5df9 100644
--- a/crashreport_stats/tests/test_stats_management_command.py
+++ b/crashreport_stats/tests/test_stats_management_command.py
@@ -193,6 +193,72 @@
             Crashreport, numbers, counter_attribute_name, **boot_reason_param
         )
 
+    def _assert_accumulated_counters_are_correct(
+        self, report_type, counter_attribute_name, **kwargs
+    ):
+        """Validate a counter distribution with reports of different devices."""
+        # Create some devices and corresponding reports
+        devices = [
+            Dummy.create_dummy_device(Dummy.create_dummy_user(username=name))
+            for name in Dummy.USERNAMES
+        ]
+        num_reports = 5
+        for device in devices:
+            self._create_reports(
+                report_type,
+                self.unique_entries[0],
+                device,
+                num_reports,
+                **kwargs
+            )
+
+        # Run the command to update the database
+        call_command("stats", "update")
+
+        # Check whether the numbers of reports match
+        version = self.version_class.objects.get(
+            **{self.unique_entry_name: self.unique_entries[0]}
+        )
+        self.assertEqual(
+            len(Dummy.USERNAMES) * num_reports,
+            getattr(version, counter_attribute_name),
+        )
+
+    def test_accumulated_heartbeats_counter(self):
+        """Test heartbeats counter with reports from different devices."""
+        report_type = HeartBeat
+        counter_attribute_name = "heartbeats"
+        self._assert_accumulated_counters_are_correct(
+            report_type, counter_attribute_name
+        )
+
+    def test_accumulated_crash_reports_counter(self):
+        """Test crash reports counter with reports from different devices."""
+        report_type = Crashreport
+        counter_attribute_name = "prob_crashes"
+        boot_reason_param = {"boot_reason": Crashreport.CRASH_BOOT_REASONS[0]}
+        self._assert_accumulated_counters_are_correct(
+            report_type, counter_attribute_name, **boot_reason_param
+        )
+
+    def test_accumulated_smpl_reports_counter(self):
+        """Test smpl reports counter with reports from different devices."""
+        report_type = Crashreport
+        counter_attribute_name = "smpl"
+        boot_reason_param = {"boot_reason": Crashreport.SMPL_BOOT_REASONS[0]}
+        self._assert_accumulated_counters_are_correct(
+            report_type, counter_attribute_name, **boot_reason_param
+        )
+
+    def test_accumulated_other_reports_counter(self):
+        """Test other reports counter with reports from different devices."""
+        report_type = Crashreport
+        counter_attribute_name = "other"
+        boot_reason_param = {"boot_reason": "random boot reason"}
+        self._assert_accumulated_counters_are_correct(
+            report_type, counter_attribute_name, **boot_reason_param
+        )
+
     def _assert_reports_with_same_timestamp_are_counted(
         self, report_type, counter_attribute_name, **kwargs
     ):
diff --git a/crashreport_stats/tests/utils.py b/crashreport_stats/tests/utils.py
index f1b9d92..c7c85f8 100644
--- a/crashreport_stats/tests/utils.py
+++ b/crashreport_stats/tests/utils.py
@@ -49,7 +49,7 @@
     ]
     UUIDs = ["e1c0cc95-ab8d-461a-a768-cb8d9d7fdb04"]
 
-    USERNAMES = ["testuser1", "testuser2"]
+    USERNAMES = ["testuser1", "testuser2", "testuser3"]
 
     DATES = [date(2018, 3, 19), date(2018, 3, 26), date(2018, 5, 1)]