Repository: metno/py-mms

Issue:
Sync with go-mms api
Py-mms hasn't been updated since before last sprint, should be updated to integrate the new functionality added in last sprint..

Comments:

Patch:
diff --git a/pymms/productevent.py b/pymms/productevent.py
index f017152..11318f2 100644
--- a/pymms/productevent.py
+++ b/pymms/productevent.py
@@ -33,7 +33,8 @@ class ProductEvent():
     """
 
     def __init__(
-        self, jobName="", product="", productionHub="", productLocation="", eventInterval=0
+        self, jobName="", product="", productionHub="", productLocation="", refTime="",
+        eventInterval=0, counter=1, totalCount=1
     ):
 
         # Event properties
@@ -42,6 +43,9 @@ class ProductEvent():
         self._eventProductionHub = productionHub
         self._eventProductLocation = productLocation
         self._eventInterval = eventInterval
+        self._refTime = refTime
+        self._counter = counter
+        self._totalCount = totalCount
 
         return
 
@@ -69,6 +73,18 @@ class ProductEvent():
     def eventInterval(self):
         return self._eventInterval
 
+    @property
+    def refTime(self):
+        return self._refTime
+
+    @property
+    def counter(self):
+        return self._counter
+
+    @property
+    def totalCount(self):
+        return self._totalCount
+
     ##
     #  Setters
     ##
@@ -118,6 +134,33 @@ class ProductEvent():
             raise ValueError("ProductEvent.eventInterval must be an integer")
         return
 
+    @refTime.setter
+    def refTime(self, value):
+        if isinstance(value, str):
+            self._refTime = value
+        else:
+            self._refTime = ""
+            raise ValueError("ProductEvent.refTime must be a string")
+        return
+
+    @counter.setter
+    def counter(self, value):
+        if isinstance(value, int):
+            self._counter = value
+        else:
+            self._counter = ""
+            raise ValueError("ProductEvent.eventInterval must be an integer")
+        return
+
+    @totalCount.setter
+    def totalCount(self, value):
+        if isinstance(value, int):
+            self._totalCount = value
+        else:
+            self._totalCount = ""
+            raise ValueError("ProductEvent.eventInterval must be an integer")
+        return
+
     ##
     #  Methods
     ##
@@ -135,6 +178,9 @@ class ProductEvent():
             "ProductLocation": str(self._eventProductLocation),
             "CreatedAt":       nowTime.isoformat(),
             "NextEventAt":     nextTime.isoformat(),
+            "RefTime":         str(self._refTime),
+            "Counter":         str(self.counter),
+            "TotalCount":      str(self.totalCount)
         })
 
         apiURL = self._eventProductionHub + "/api/v1/events"


Test patch:
diff --git a/tests/test_postevent.py b/tests/test_postevent.py
index da46d46..63787c6 100644
--- a/tests/test_postevent.py
+++ b/tests/test_postevent.py
@@ -15,6 +15,9 @@ def testCreateProductEvent():
         productionHub="FirstC",
         productLocation="FirstD",
         eventInterval=42,
+        refTime="2021-06-22T12:00:00Z",
+        counter=1,
+        totalCount=1
     )
 
     assert pEvent.jobName == "FirstA"
@@ -22,6 +25,9 @@ def testCreateProductEvent():
     assert pEvent.productionHub == "FirstC"
     assert pEvent.productLocation == "FirstD"
     assert pEvent.eventInterval == 42
+    assert pEvent.refTime == "2021-06-22T12:00:00Z"
+    assert pEvent.counter == 1
+    assert pEvent.totalCount == 1
 
     with pytest.raises(ValueError):
         pEvent.jobName = 0
@@ -38,27 +44,45 @@ def testCreateProductEvent():
     with pytest.raises(ValueError):
         pEvent.eventInterval = "2"
 
+    with pytest.raises(ValueError):
+        pEvent.refTime = 0
+
+    with pytest.raises(ValueError):
+        pEvent.counter = "1"
+
+    with pytest.raises(ValueError):
+        pEvent.totalCount = "1"
+
     pEvent.jobName = "SecondA"
     pEvent.product = "SecondB"
     pEvent.productionHub = "SecondC"
     pEvent.productLocation = "SecondD"
     pEvent.eventInterval = 43
+    pEvent.refTime = "2000-01-01T00:00:00Z"
+    pEvent.counter = 2
+    pEvent.totalCount = 3
 
     assert pEvent.jobName == "SecondA"
     assert pEvent.product == "SecondB"
     assert pEvent.productionHub == "SecondC"
     assert pEvent.productLocation == "SecondD"
     assert pEvent.eventInterval == 43
+    assert pEvent.refTime == "2000-01-01T00:00:00Z"
+    assert pEvent.counter == 2
+    assert pEvent.totalCount == 3
 
 @pytest.mark.events
 def testSendProductEvent(monkeypatch):
     # Valid Event
     pEvent = ProductEvent(
+        eventInterval=3600,
         jobName="TestJob",
         product="TestProduct",
         productionHub="http://localhost:8080",
-        productLocation="/tmp",
-        eventInterval=3600,
+        productLocation="/tmp/testproduct.ext",
+        refTime="2021-06-22T12:00:00Z",
+        counter=1,
+        totalCount=1,
     )
     monkeypatch.setattr(request, "urlopen", lambda *args, **kwargs: None)
     assert pEvent.send() is None