Repository: qiskit-community/ecosystem (python)

Issue:
Handling of historical test results
<!-- ⚠️ If you do not respect this template, your issue will be closed -->
<!-- ⚠️ Make sure to browse the opened and closed issues to confirm this idea does not exist. -->

### What is the expected enhancement?
Let's move `test_results` to `historical_test_results` field and leave `test_results` field only for latest run. 


### Details

- create new field `historical_test_results`
- move all test results to this new field
- leave only latest entry in `test_results` field

Pull request:
Issue-133 | Store only latest test results and move historical test results in a separate field
<!--
⚠️ If you do not respect this template, your pull request will be closed.
⚠️ Your pull request title should be short detailed and understandable for all.
⚠️ Also, please add a release note file using reno if the change needs to be
  documented in the release notes.
⚠️ If your pull request fixes an open issue, please link to the issue.

- [ ] I have added the tests to cover my changes.
- [ ] I have updated the documentation accordingly.
- [ ] I have read the CONTRIBUTING document.
-->

### Summary
- [x] Store only latest test results and move historical test results in a separate field
- [x] update tests
- [x] remove old test resulst 

### Details and comments
Closes #133 


Patch:
diff --git a/ecosystem/daos/jsondao.py b/ecosystem/daos/jsondao.py
index de88fcf..5087412 100644
--- a/ecosystem/daos/jsondao.py
+++ b/ecosystem/daos/jsondao.py
@@ -92,6 +92,7 @@ class JsonDAO:
         self, repo_url: str, tier: str, test_result: TestResult
     ) -> Optional[List[int]]:
         """Adds test result for repository.
+        Overwrites latest test results and adds to historical test results.
 
         Args:
             repo_url: url of the repo
@@ -105,18 +106,22 @@ class JsonDAO:
 
         fetched_repo_json = table.get(repository.url == repo_url)
         if fetched_repo_json is not None:
-            fetched_repo = Repository.from_dict(fetched_repo_json)
-            fetched_test_results = fetched_repo.tests_results
+            repo = Repository.from_dict(fetched_repo_json)
 
             new_test_results = [
+                tr for tr in repo.tests_results if tr.test_type != test_result.test_type
+            ] + [test_result]
+            repo.tests_results = new_test_results
+
+            new_historical_est_results = [
                 tr
-                for tr in fetched_test_results
+                for tr in repo.historical_test_results
                 if tr.test_type != test_result.test_type
                 or tr.terra_version != test_result.terra_version
             ] + [test_result]
-            fetched_repo.tests_results = new_test_results
+            repo.historical_test_results = new_historical_est_results
 
-            return table.upsert(fetched_repo.to_dict(), repository.url == repo_url)
+            return table.upsert(repo.to_dict(), repository.url == repo_url)
         return None
 
     def add_repo_style_result(
diff --git a/ecosystem/models/repository.py b/ecosystem/models/repository.py
index ef89e5c..75bcc76 100644
--- a/ecosystem/models/repository.py
+++ b/ecosystem/models/repository.py
@@ -30,6 +30,7 @@ class Repository(JsonSerializable):
         coverages_results: Optional[List[TestResult]] = None,
         configuration: Optional[RepositoryConfiguration] = None,
         skip_tests: Optional[bool] = None,
+        historical_test_results: Optional[List[TestResult]] = None,
     ):
         """Repository class.
 
@@ -48,6 +49,7 @@ class Repository(JsonSerializable):
             styles_results: styles passed by repo
             coverages_results: coverages passed by repo
             skip_tests: weather skip tests or not
+            historical_test_results: list of historical test results
         """
         self.name = name
         self.url = url
@@ -69,6 +71,7 @@ class Repository(JsonSerializable):
         self.tier = tier
         self.configuration = configuration
         self.skip_tests = skip_tests if skip_tests is not None else False
+        self.historical_test_results = historical_test_results or []
 
     @classmethod
     def from_dict(cls, dictionary: dict):
@@ -102,6 +105,13 @@ class Repository(JsonSerializable):
                 dictionary.get("configuration")
             )
 
+        historical_test_results = []
+        if "historical_test_results" in dictionary:
+            historical_test_results = [
+                TestResult.from_dict(r)
+                for r in dictionary.get("historical_test_results", [])
+            ]
+
         return Repository(
             name=dictionary.get("name"),
             url=dictionary.get("url"),
@@ -116,6 +126,7 @@ class Repository(JsonSerializable):
             coverages_results=coverages_results,
             configuration=configuration,
             skip_tests=dictionary.get("skip_tests"),
+            historical_test_results=historical_test_results,
         )
 
     def __eq__(self, other: "Repository"):
diff --git a/ecosystem/resources/members.json b/ecosystem/resources/members.json
index c025ab1..7e53a1a 100644
--- a/ecosystem/resources/members.json
+++ b/ecosystem/resources/members.json
@@ -30,14 +30,7 @@
             "tier": "Main",
             "updated_at": 1636403010.377697,
             "url": "https://github.com/Qiskit/qiskit-aer",
-            "tests_results": [
-                {
-                    "test_type": "STANDARD",
-                    "passed": true,
-                    "terra_version": "0.18.3",
-                    "timestamp": 1636403010.377469
-                }
-            ],
+            "tests_results": [],
             "affiliations": null,
             "styles_results": [],
             "coverages_results": [],
@@ -57,14 +50,7 @@
             "tier": "Main",
             "updated_at": 1636403009.538763,
             "url": "https://github.com/Qiskit/qiskit-optimization",
-            "tests_results": [
-                {
-                    "test_type": "DEV_COMPATIBLE",
-                    "passed": true,
-                    "terra_version": "0.19.0",
-                    "timestamp": 1636403009.53853
-                }
-            ],
+            "tests_results": [],
             "affiliations": null,
             "styles_results": [],
             "coverages_results": [],
@@ -101,14 +87,7 @@
             "tier": "Main",
             "updated_at": 1636403010.012956,
             "url": "https://github.com/Qiskit/qiskit-machine-learning",
-            "tests_results": [
-                {
-                    "test_type": "DEV_COMPATIBLE",
-                    "passed": true,
-                    "terra_version": "0.19.0",
-                    "timestamp": 1636403010.012718
-                }
-            ],
+            "tests_results": [],
             "affiliations": null,
             "styles_results": [],
             "coverages_results": [],
@@ -129,14 +108,7 @@
             "tier": "Main",
             "updated_at": 1636403009.167082,
             "url": "https://github.com/Qiskit/qiskit-nature",
-            "tests_results": [
-                {
-                    "test_type": "DEV_COMPATIBLE",
-                    "passed": true,
-                    "terra_version": "0.19.0",
-                    "timestamp": 1636403009.166847
-                }
-            ],
+            "tests_results": [],
             "affiliations": null,
             "styles_results": [],
             "coverages_results": [],
@@ -156,14 +128,7 @@
             "tier": "Main",
             "updated_at": 1636403009.368609,
             "url": "https://github.com/Qiskit/qiskit-finance",
-            "tests_results": [
-                {
-                    "test_type": "DEV_COMPATIBLE",
-                    "passed": true,
-                    "terra_version": "0.19.0",
-                    "timestamp": 1636403009.368369
-                }
-            ],
+            "tests_results": [],
             "affiliations": null,
             "styles_results": [],
             "coverages_results": [],
@@ -200,50 +165,9 @@
             ],
             "created_at": 1641938992.426062,
             "updated_at": 1641938992.426063,
-            "tests_results": [
-                {
-                    "test_type": "STABLE_COMPATIBLE",
-                    "passed": false,
-                    "terra_version": "0.18.3",
-                    "timestamp": 1641938992.426041
-                },
-                {
-                    "test_type": "DEV_COMPATIBLE",
-                    "passed": false,
-                    "terra_version": "0.19.0",
-                    "timestamp": 1641938992.426045
-                },
-                {
-                    "test_type": "STABLE_COMPATIBLE",
-                    "passed": false,
-                    "terra_version": "0.19.1",
-                    "timestamp": 1641938992.426047
-                },
-                {
-                    "test_type": "STANDARD",
-                    "passed": false,
-                    "terra_version": "-",
-                    "timestamp": 1641938992.426049
-                },
-                {
-                    "test_type": "DEV_COMPATIBLE",
-                    "passed": false,
-                    "terra_version": "0.20.0",
-                    "timestamp": 1641938992.426051
-                }
-            ],
-            "styles_results": [
-                {
-                    "style_type": "pylint",
-                    "passed": false
-                }
-            ],
-            "coverages_results": [
-                {
-                    "coverage_type": "",
-                    "passed": false
-                }
-            ],
+            "tests_results": [],
+            "styles_results": [],
+            "coverages_results": [],
             "tier": "Community",
             "skip_tests": false,
             "configuration": {
@@ -286,38 +210,9 @@
             ],
             "created_at": 1638807605.079218,
             "updated_at": 1638807605.079223,
-            "tests_results": [
-                {
-                    "test_type": "STANDARD",
-                    "passed": true,
-                    "terra_version": "0.18.3",
-                    "timestamp": 1638807605.079161
-                },
-                {
-                    "test_type": "STABLE_COMPATIBLE",
-                    "passed": true,
-                    "terra_version": "0.18.3",
-                    "timestamp": 1638807605.079178
-                },
-                {
-                    "test_type": "DEV_COMPATIBLE",
-                    "passed": false,
-                    "terra_version": "0.19.0",
-                    "timestamp": 1638807605.079181
-                }
-            ],
-            "styles_results": [
-                {
-                    "style_type": "pylint",
-                    "passed": false
-                }
-            ],
-            "coverages_results": [
-                {
-                    "coverage_type": "",
-                    "passed": false
-                }
-            ],
+            "tests_results": [],
+            "styles_results": [],
+            "coverages_results": [],
             "tier": "Community",
             "skip_tests": false,
             "configuration": {
@@ -363,44 +258,9 @@
             ],
             "created_at": 1641938992.280572,
             "updated_at": 1641938992.280573,
-            "tests_results": [
-                {
-                    "test_type": "DEV_COMPATIBLE",
-                    "passed": false,
-                    "terra_version": "0.19.0",
-                    "timestamp": 1641938992.280553
-                },
-                {
-                    "test_type": "DEV_COMPATIBLE",
-                    "passed": false,
-                    "terra_version": "0.20.0",
-                    "timestamp": 1641938992.280557
-                },
-                {
-                    "test_type": "STABLE_COMPATIBLE",
-                    "passed": false,
-                    "terra_version": "0.18.3",
-                    "timestamp": 1641938992.280559
-                },
-                {
-                    "test_type": "STANDARD",
-                    "passed": false,
-                    "terra_version": "0.18.3",
-                    "timestamp": 1641938992.280561
-                }
-            ],
-            "styles_results": [
-                {
-                    "style_type": "pylint",
-                    "passed": false
-                }
-            ],
-            "coverages_results": [
-                {
-                    "coverage_type": "",
-                    "passed": false
-                }
-            ],
+            "tests_results": [],
+            "styles_results": [],
+            "coverages_results": [],
             "tier": "Community",
             "skip_tests": false,
             "configuration": {
@@ -441,38 +301,9 @@
             ],
             "created_at": 1641938992.417498,
             "updated_at": 1641938992.417498,
-            "tests_results": [
-                {
-                    "test_type": "STABLE_COMPATIBLE",
-                    "passed": false,
-                    "terra_version": "-",
-                    "timestamp": 1641938992.417485
-                },
-                {
-                    "test_type": "DEV_COMPATIBLE",
-                    "passed": false,
-                    "terra_version": "-",
-                    "timestamp": 1641938992.417487
-                },
-                {
-                    "test_type": "STANDARD",
-                    "passed": false,
-                    "terra_version": "-",
-                    "timestamp": 1641938992.417052
-                }
-            ],
-            "styles_results": [
-                {
-                    "style_type": "pylint",
-                    "passed": false
-                }
-            ],
-            "coverages_results": [
-                {
-                    "coverage_type": "",
-                    "passed": false
-                }
-            ],
+            "tests_results": [],
+            "styles_results": [],
+            "coverages_results": [],
             "tier": "Community",
             "skip_tests": false,
             "configuration": {
@@ -522,50 +353,9 @@
             ],
             "created_at": 1641938992.378912,
             "updated_at": 1641938992.378913,
-            "tests_results": [
-                {
-                    "test_type": "STABLE_COMPATIBLE",
-                    "passed": false,
-                    "terra_version": "0.18.3",
-                    "timestamp": 1641938992.378893
-                },
-                {
-                    "test_type": "DEV_COMPATIBLE",
-                    "passed": false,
-                    "terra_version": "0.19.0",
-                    "timestamp": 1641938992.378896
-                },
-                {
-                    "test_type": "STANDARD",
-                    "passed": false,
-                    "terra_version": "-",
-                    "timestamp": 1641938992.3789
-                },
-                {
-                    "test_type": "STABLE_COMPATIBLE",
-                    "passed": false,
-                    "terra_version": "0.19.1",
-                    "timestamp": 1641938992.378901
-                },
-                {
-                    "test_type": "DEV_COMPATIBLE",
-                    "passed": false,
-                    "terra_version": "0.20.0",
-                    "timestamp": 1641938992.378497
-                }
-            ],
-            "styles_results": [
-                {
-                    "style_type": "pylint",
-                    "passed": false
-                }
-            ],
-            "coverages_results": [
-                {
-                    "coverage_type": "",
-                    "passed": false
-                }
-            ],
+            "tests_results": [],
+            "styles_results": [],
+            "coverages_results": [],
             "tier": "Community",
             "skip_tests": false,
             "configuration": {
@@ -609,18 +399,8 @@
             "created_at": 1641938992.295526,
             "updated_at": 1641938992.295528,
             "tests_results": [],
-            "styles_results": [
-                {
-                    "style_type": "pylint",
-                    "passed": false
-                }
-            ],
-            "coverages_results": [
-                {
-                    "coverage_type": "",
-                    "passed": false
-                }
-            ],
+            "styles_results": [],
+            "coverages_results": [],
             "tier": "Community",
             "skip_tests": false
         },
@@ -637,38 +417,9 @@
             ],
             "created_at": 1641938992.369625,
             "updated_at": 1641938992.369626,
-            "tests_results": [
-                {
-                    "test_type": "STANDARD",
-                    "passed": true,
-                    "terra_version": "0.19.1",
-                    "timestamp": 1641938992.369609
-                },
-                {
-                    "test_type": "STABLE_COMPATIBLE",
-                    "passed": false,
-                    "terra_version": "0.19.1",
-                    "timestamp": 1641938992.369614
-                },
-                {
-                    "test_type": "DEV_COMPATIBLE",
-                    "passed": false,
-                    "terra_version": "0.20.0",
-                    "timestamp": 1641938992.369615
-                }
-            ],
-            "styles_results": [
-                {
-                    "style_type": "pylint",
-                    "passed": false
-                }
-            ],
-            "coverages_results": [
-                {
-                    "coverage_type": "",
-                    "passed": true
-                }
-            ],
+            "tests_results": [],
+            "styles_results": [],
+            "coverages_results": [],
             "tier": "Community",
             "skip_tests": false,
             "configuration": {
@@ -710,38 +461,9 @@
             ],
             "created_at": 1641938992.291824,
             "updated_at": 1641938992.291825,
-            "tests_results": [
-                {
-                    "test_type": "STABLE_COMPATIBLE",
-                    "passed": false,
-                    "terra_version": "0.19.1",
-                    "timestamp": 1641938992.291806
-                },
-                {
-                    "test_type": "DEV_COMPATIBLE",
-                    "passed": false,
-                    "terra_version": "0.20.0",
-                    "timestamp": 1641938992.291811
-                },
-                {
-                    "test_type": "STANDARD",
-                    "passed": false,
-                    "terra_version": "-",
-                    "timestamp": 1641938992.291813
-                }
-            ],
-            "styles_results": [
-                {
-                    "style_type": "pylint",
-                    "passed": false
-                }
-            ],
-            "coverages_results": [
-                {
-                    "coverage_type": "",
-                    "passed": false
-                }
-            ],
+            "tests_results": [],
+            "styles_results": [],
+            "coverages_results": [],
             "tier": "Community",
             "skip_tests": false,
             "configuration": {
@@ -784,38 +506,9 @@
             ],
             "created_at": 1641938992.429689,
             "updated_at": 1641938992.42969,
-            "tests_results": [
-                {
-                    "test_type": "STANDARD",
-                    "passed": false,
-                    "terra_version": "0.19.1",
-                    "timestamp": 1641938992.429675
-                },
-                {
-                    "test_type": "DEV_COMPATIBLE",
-                    "passed": false,
-                    "terra_version": "0.20.0",
-                    "timestamp": 1641938992.429677
-                },
-                {
-                    "test_type": "STABLE_COMPATIBLE",
-                    "passed": false,
-                    "terra_version": "0.19.1",
-                    "timestamp": 1641938992.429243
-                }
-            ],
-            "styles_results": [
-                {
-                    "style_type": "pylint",
-                    "passed": false
-                }
-            ],
-            "coverages_results": [
-                {
-                    "coverage_type": "",
-                    "passed": false
-                }
-            ],
+            "tests_results": [],
+            "styles_results": [],
+            "coverages_results": [],
             "tier": "Community",
             "skip_tests": false,
             "configuration": {
@@ -857,38 +550,9 @@
             ],
             "created_at": 1641938992.441942,
             "updated_at": 1641938992.441943,
-            "tests_results": [
-                {
-                    "test_type": "STANDARD",
-                    "passed": true,
-                    "terra_version": "0.17.4",
-                    "timestamp": 1641938992.441925
-                },
-                {
-                    "test_type": "STABLE_COMPATIBLE",
-                    "passed": false,
-                    "terra_version": "0.17.4",
-                    "timestamp": 1641938992.44193
-                },
-                {
-                    "test_type": "DEV_COMPATIBLE",
-                    "passed": false,
-                    "terra_version": "0.20.0",
-                    "timestamp": 1641938992.441932
-                }
-            ],
-            "styles_results": [
-                {
-                    "style_type": "pylint",
-                    "passed": false
-                }
-            ],
-            "coverages_results": [
-                {
-                    "coverage_type": "",
-                    "passed": true
-                }
-            ],
+            "tests_results": [],
+            "styles_results": [],
+            "coverages_results": [],
             "tier": "Community",
             "skip_tests": false,
             "configuration": {
@@ -930,38 +594,9 @@
             ],
             "created_at": 1641938992.422032,
             "updated_at": 1641938992.422033,
-            "tests_results": [
-                {
-                    "test_type": "STANDARD",
-                    "passed": false,
-                    "terra_version": "-",
-                    "timestamp": 1641938992.422019
-                },
-                {
-                    "test_type": "STABLE_COMPATIBLE",
-                    "passed": false,
-                    "terra_version": "0.19.1",
-                    "timestamp": 1641938992.422021
-                },
-                {
-                    "test_type": "DEV_COMPATIBLE",
-                    "passed": false,
-                    "terra_version": "0.20.0",
-                    "timestamp": 1641938992.421483
-                }
-            ],
-            "styles_results": [
-                {
-                    "style_type": "pylint",
-                    "passed": false
-                }
-            ],
-            "coverages_results": [
-                {
-                    "coverage_type": "",
-                    "passed": false
-                }
-            ],
+            "tests_results": [],
+            "styles_results": [],
+            "coverages_results": [],
             "tier": "Community",
             "skip_tests": false,
             "configuration": {
@@ -1005,38 +640,9 @@
             ],
             "created_at": 1641938992.390322,
             "updated_at": 1641938992.390323,
-            "tests_results": [
-                {
-                    "test_type": "STANDARD",
-                    "passed": false,
-                    "terra_version": "-",
-                    "timestamp": 1641938992.39031
-                },
-                {
-                    "test_type": "DEV_COMPATIBLE",
-                    "passed": false,
-                    "terra_version": "-",
-                    "timestamp": 1641938992.390312
-                },
-                {
-                    "test_type": "STABLE_COMPATIBLE",
-                    "passed": false,
-                    "terra_version": "-",
-                    "timestamp": 1641938992.389865
-                }
-            ],
-            "styles_results": [
-                {
-                    "style_type": "pylint",
-                    "passed": false
-                }
-            ],
-            "coverages_results": [
-                {
-                    "coverage_type": "",
-                    "passed": false
-                }
-            ],
+            "tests_results": [],
+            "styles_results": [],
+            "coverages_results": [],
             "tier": "Community",
             "skip_tests": false,
             "configuration": {
@@ -1087,38 +693,9 @@
             ],
             "created_at": 1641936446.811627,
             "updated_at": 1641936446.811629,
-            "tests_results": [
-                {
-                    "test_type": "DEV_COMPATIBLE",
-                    "passed": false,
-                    "terra_version": "-",
-                    "timestamp": 1641936446.811607
-                },
-                {
-                    "test_type": "STANDARD",
-                    "passed": false,
-                    "terra_version": "-",
-                    "timestamp": 1641936446.811612
-                },
-                {
-                    "test_type": "STABLE_COMPATIBLE",
-                    "passed": false,
-                    "terra_version": "-",
-                    "timestamp": 1641936446.811196
-                }
-            ],
-            "styles_results": [
-                {
-                    "style_type": "pylint",
-                    "passed": false
-                }
-            ],
-            "coverages_results": [
-                {
-                    "coverage_type": "",
-                    "passed": false
-                }
-            ],
+            "tests_results": [],
+            "styles_results": [],
+            "coverages_results": [],
             "tier": "Community",
             "skip_tests": false,
             "configuration": {
@@ -1170,18 +747,8 @@
             "created_at": 1641938992.363096,
             "updated_at": 1641938992.363099,
             "tests_results": [],
-            "styles_results": [
-                {
-                    "style_type": "pylint",
-                    "passed": false
-                }
-            ],
-            "coverages_results": [
-                {
-                    "coverage_type": "",
-                    "passed": false
-                }
-            ],
+            "styles_results": [],
+            "coverages_results": [],
             "tier": "Community",
             "skip_tests": true
         },
@@ -1198,38 +765,9 @@
             ],
             "created_at": 1641938992.438087,
             "updated_at": 1641938992.438088,
-            "tests_results": [
-                {
-                    "test_type": "STANDARD",
-                    "passed": false,
-                    "terra_version": "-",
-                    "timestamp": 1641938992.438069
-                },
-                {
-                    "test_type": "STABLE_COMPATIBLE",
-                    "passed": false,
-                    "terra_version": "-",
-                    "timestamp": 1641938992.438074
-                },
-                {
-                    "test_type": "DEV_COMPATIBLE",
-                    "passed": false,
-                    "terra_version": "-",
-                    "timestamp": 1641938992.438076
-                }
-            ],
-            "styles_results": [
-                {
-                    "style_type": "pylint",
-                    "passed": false
-                }
-            ],
-            "coverages_results": [
-                {
-                    "coverage_type": "",
-                    "passed": false
-                }
-            ],
+            "tests_results": [],
+            "styles_results": [],
+            "coverages_results": [],
             "tier": "Community",
             "skip_tests": false,
             "configuration": {


Test patch:
diff --git a/tests/daos/test_dao.py b/tests/daos/test_dao.py
index 6ae2bda..e2ca786 100644
--- a/tests/daos/test_dao.py
+++ b/tests/daos/test_dao.py
@@ -112,6 +112,10 @@ class TestJsonDao(TestCase):
             recovered_repo.tests_results,
             [TestResult(False, "0.18.1", TestType.DEV_COMPATIBLE)],
         )
+        self.assertEqual(
+            recovered_repo.historical_test_results,
+            [TestResult(False, "0.18.1", TestType.DEV_COMPATIBLE)],
+        )
 
         res = dao.add_repo_test_result(
             main_repo.url,
@@ -119,11 +123,25 @@ class TestJsonDao(TestCase):
             TestResult(True, "0.18.2", TestType.DEV_COMPATIBLE),
         )
         self.assertEqual(res, [1])
+        res = dao.add_repo_test_result(
+            main_repo.url,
+            main_repo.tier,
+            TestResult(True, "0.18.2", TestType.STANDARD),
+        )
+        self.assertEqual(res, [1])
         recovered_repo = dao.get_by_url(main_repo.url, tier=main_repo.tier)
         self.assertEqual(
             recovered_repo.tests_results,
+            [
+                TestResult(True, "0.18.2", TestType.DEV_COMPATIBLE),
+                TestResult(True, "0.18.2", TestType.STANDARD),
+            ],
+        )
+        self.assertEqual(
+            recovered_repo.historical_test_results,
             [
                 TestResult(False, "0.18.1", TestType.DEV_COMPATIBLE),
                 TestResult(True, "0.18.2", TestType.DEV_COMPATIBLE),
+                TestResult(True, "0.18.2", TestType.STANDARD),
             ],
         )