Exemplo n.º 1
0
 def setUp(self) -> None:
     self.value_history1 = ValueHistory(
         {ValueHistory.DATE_MS: self.DATE_MS1,
          ValueHistory.VALUE: self.VALUE1})
     self.value_history_list = \
         [ValueHistory.build(self.VALUE1, self.DATE_MS1),
          ValueHistory.build(self.VALUE2, self.DATE_MS2),
          ValueHistory.build(self.VALUE3, self.DATE_MS3)]
Exemplo n.º 2
0
    def update(self, value: DecimalNumber, date_ms: int):
        if not self.is_exist(date_ms):
            raise ApplicationException(
                f'History in [{date_ms}] not exist'
                f' in collection {self.collection_name}')

        filter = \
            {ValueHistory.DATE_MS: {MongoDbModifierEnum.EQ.value: date_ms}}
        value_history = ValueHistory.build(value, date_ms)
        update = {'$set': value_history.document}

        self.collection.update_one(
            filter=filter, update=update)
Exemplo n.º 3
0
    def add(self, value: DecimalNumber, date_ms: int):
        """
        Add history document that not exist.

        :param value: Value.
        :param date_ms: Date in ms.
        :return:
        """

        if self.is_exist(date_ms):
            raise ApplicationException(
                f'History in date ms [{date_ms}] already exist'
                f' in collection {self.collection_name}')
        value_history = ValueHistory.build(value, date_ms)
        self.collection.insert_one(value_history.document)
Exemplo n.º 4
0
 def test_08_eq(self):
     value_history = ValueHistory.build(self.VALUE1, self.DATE_MS1)
     self.assertTrue(self.value_history1 == value_history)