def test_post_bring_back(self, mock_post):
     e = Event(node=self.node,
               a=[Properties(a='b')],
               b='c',
               bringBackProperties=Properties(type='EXTERNAL_ID',
                                              value='01'),
               d=Properties(f='g', h=Properties(i='j')),
               k=dict(l=Properties(m='n', o='p')))
     e.post()
     mock_post.assert_called_with(self.base_url,
                                  headers=self.headers_expected,
                                  json={
                                      'bringBackProperties': {
                                          'type': 'EXTERNAL_ID',
                                          'value': '01',
                                          'nodeId': self.node.node_id
                                      },
                                      'a': [{
                                          'a': 'b'
                                      }],
                                      'b': 'c',
                                      'd': {
                                          'f': 'g',
                                          'h': {
                                              'i': 'j'
                                          }
                                      },
                                      'k': {
                                          'l': {
                                              'm': 'n',
                                              'o': 'p'
                                          }
                                      }
                                  })
 def test_post(self, mock_post):
     e = Event(node=self.node,
               a=[Properties(a='b')],
               b='c',
               d=Properties(f='g', h=Properties(i='j')),
               k=dict(l=Properties(m='n', o='p')))
     e.post()
     mock_post.assert_called_with(self.base_url,
                                  headers=self.headers_expected,
                                  json={
                                      'a': [{
                                          'a': 'b'
                                      }],
                                      'b': 'c',
                                      'd': {
                                          'f': 'g',
                                          'h': {
                                              'i': 'j'
                                          }
                                      },
                                      'k': {
                                          'l': {
                                              'm': 'n',
                                              'o': 'p'
                                          }
                                      }
                                  })
 def test_to_dict(self):
     e = Event(
         node=self.node,
         a=Properties(b=Properties(c=Properties(d=Properties(e='f')))))
     assert e.to_dict() == {
         'a': {
             'b': {
                 'c': {
                     'd': {
                         'e': 'f'
                     }
                 }
             }
         }
     }, e.to_dict()
Esempio n. 4
0
    def get_event(self, id):
        """
        Get a single event by its own id

        :param id: the id of the event to get
        :return: a new Event object representing the fetched event
        """
        return Event(node=self, **self.event_api_manager.get(_id=id))
 def test_get_event_from_customers(self, mock_get_customers,
                                   mock_get_events):
     events = self.node.get_customers()[0].get_events()
     assert isinstance(events, PaginatedList), type(events)
     assert isinstance(events[0], Event), type(events[0])
     try:
         events.append(Event(node=self.node))
     except ValueError as e:
         assert 'Read Only' in str(e)
Esempio n. 6
0
    def add_event(self, **attributes):
        """
        Add an event in this node. For adding it and associate with a known customer, specify the customer id in the
        attributes of the Event. For associate it to an external Id or a session id of a customer, specify in the
        bringBackProperties object like:
        {'type':'EXTERNAL_ID',
        'value':'value',
        'nodeId':'nodeId'
        }

        :param attributes: the attributes of the event to add in the node
        :return: a new Event object representing the event added in this node
        """
        convert_properties_obj_in_prop(properties=attributes,
                                       properties_class=Properties)
        self.event_api_manager.post(body=attributes)
        return Event(node=self, **attributes)
 def test_list_properies_constructor(self):
     e = Event(node=self.node, a=[Properties(a='b')])
     assert e.attributes == {'a': [{'a': 'b'}]}, e.attributes
 def test_list_properies(self):
     e = Event(node=self.node)
     e.a = [Properties(a='b')]
     assert e.attributes == {'a': [{'a': 'b'}]}, e.attributes
 def test_event_from_dict(self):
     d = {}
     e = Event.from_dict(node=self.node, attributes=d)
     assert e.attributes is d, (e.attributes, d)
 def test_event_from_dict_void(self):
     e = Event.from_dict(node=self.node)
     assert e.attributes == {}, e.attributes
 def test_create_new_event_properties(self):
     e = Event(node=self.node)
     e.properties = Properties(attr='attr')
     assert isinstance(e.properties, Properties), type(e.properties)