Exemplo n.º 1
0
    def test_on_fetched_item_contacts(self):
        """ Verify that on_fetched_item_contacts events are fired for versioned
        requests.
        """
        devent = DummyEvent(lambda: True)
        self.app.on_fetched_item_contacts += devent
        response, status = self.get(self.known_resource,
                                    item=self.item_id,
                                    query='?version=1')
        self.assertEqual(self.item_id,
                         str(devent.called[0][self.app.config['ID_FIELD']]))
        self.assertEqual(1, len(devent.called))

        # check for ?version=all requests
        devent = DummyEvent(lambda: True)
        self.app.on_fetched_item_contacts += devent
        response, status = self.get(self.known_resource,
                                    item=self.item_id,
                                    query='?version=all')
        self.assertEqual(self.item_id,
                         str(devent.called[0][self.app.config['ID_FIELD']]))
        self.assertEqual(1, len(devent.called))

        # check for ?version=diffs requests
        devent = DummyEvent(lambda: True)
        self.app.on_fetched_item_contacts += devent
        response, status = self.get(self.known_resource,
                                    item=self.item_id,
                                    query='?version=diffs')
        self.assertEqual(None, devent.called)
Exemplo n.º 2
0
 def test_on_delete_resource_contacts(self):
     devent1 = DummyEvent(self.before_delete)
     self.app.on_delete_resource_contacts += devent1
     devent2 = DummyEvent(self.before_delete)
     self.app.on_delete_resource_originals_contacts += devent2
     self.delete_resource()
     self.assertEqual(tuple(), devent1.called)
     self.assertFalse(devent2.called is None)
Exemplo n.º 3
0
 def test_on_replaced_people(self):
     devent = DummyEvent(self.after_replace)
     self.app.on_replaced_people += devent
     self.put()
     self.assertEqual(self.new_person['firstname'],
                      devent.called[0]['firstname'])
     self.assertEqual(2, len(devent.called))
Exemplo n.º 4
0
 def test_on_delete_item(self):
     devent = DummyEvent(self.before_delete)
     self.app.on_delete_item += devent
     self.delete_item()
     self.assertEqual("contacts", devent.called[0])
     id_field = self.domain["contacts"]["id_field"]
     self.assertEqual(self.item_id, str(devent.called[1][id_field]))
Exemplo n.º 5
0
 def test_on_delete_item(self):
     devent = DummyEvent(self.before_delete)
     self.app.on_delete_item += devent
     self.delete_item()
     self.assertEqual('contacts', devent.called[0])
     self.assertEqual(self.item_id,
                      str(devent.called[1][self.app.config['ID_FIELD']]))
Exemplo n.º 6
0
 def test_on_post_PUT(self):
     devent = DummyEvent(self.after_replace)
     self.app.on_post_PUT += devent
     self.put()
     self.assertEqual(self.known_resource, devent.called[0])
     self.assertEqual(200, devent.called[2].status_code)
     self.assertEqual(3, len(devent.called))
Exemplo n.º 7
0
 def test_on_inserted(self):
     devent = DummyEvent(self.after_insert, True)
     self.app.on_inserted += devent
     self.post()
     self.assertEqual(self.known_resource, devent.called[0])
     self.assertEqual(self.new_person['firstname'],
                      devent.called[1][0]['firstname'])
Exemplo n.º 8
0
 def test_on_deleted_item(self):
     devent = DummyEvent(self.after_delete)
     self.app.on_deleted_item += devent
     self.delete_item()
     self.assertEqual('contacts', devent.called[0])
     id_field = self.domain['contacts']['id_field']
     self.assertEqual(self.item_id, str(devent.called[1][id_field]))
Exemplo n.º 9
0
 def test_on_replace(self):
     devent = DummyEvent(self.before_replace)
     self.app.on_replace += devent
     self.put()
     self.assertEqual(self.known_resource, devent.called[0])
     self.assertEqual(self.new_ref, devent.called[1]['ref'])
     self.assertEqual(3, len(devent.called))
Exemplo n.º 10
0
 def test_on_post_PATCH(self):
     devent = DummyEvent(self.after_update)
     self.app.on_post_PATCH += devent
     self.patch()
     self.assertEqual(self.known_resource, devent.called[0])
     self.assertEqual(200, devent.called[2].status_code)
     self.assertEqual(3, len(devent.called))
Exemplo n.º 11
0
 def test_on_deleted_item(self):
     devent = DummyEvent(self.after_delete)
     self.app.on_deleted_item += devent
     self.delete_item()
     self.assertEqual('people', devent.called[0])
     self.assertEqual(
         self.item_id, devent.called[1][self.app.config['ID_FIELD']])
Exemplo n.º 12
0
 def test_on_replaced(self):
     devent = DummyEvent(self.after_replace)
     self.app.on_replaced += devent
     self.put()
     self.assertEqual(self.known_resource, devent.called[0])
     self.assertEqual(self.new_ref, devent.called[1]["ref"])
     self.assertEqual(3, len(devent.called))
Exemplo n.º 13
0
 def test_on_replaced(self):
     devent = DummyEvent(self.after_replace)
     self.app.on_replaced += devent
     self.put()
     self.assertEqual(self.known_resource, devent.called[0])
     self.assertEqual(self.new_person['firstname'],
                      devent.called[1]['firstname'])
     self.assertEqual(3, len(devent.called))
Exemplo n.º 14
0
 def test_on_delete_item_contacts(self):
     devent = DummyEvent(self.before_delete)
     self.app.on_delete_item_contacts += devent
     self.delete_item()
     id_field = self.domain['contacts']['id_field']
     # Eve test casts devent.called[1][id_field] to string, which may be
     # appropriate for ObjectIds, but not for integer ids.
     # TODO: Fix directly in Eve and remove this override
     self.assertEqual(self.item_id, devent.called[0][id_field])
Exemplo n.º 15
0
 def test_on_pre_PATCH_contacts(self):
     devent = DummyEvent(self.before_update)
     self.app.on_pre_PATCH_contacts += devent
     self.patch()
     self.assertEqual(2, len(devent.called))
Exemplo n.º 16
0
 def test_on_pre_PATCH(self):
     devent = DummyEvent(self.before_update)
     self.app.on_pre_PATCH += devent
     self.patch()
     self.assertEqual(self.known_resource, devent.called[0])
     self.assertEqual(3, len(devent.called))
Exemplo n.º 17
0
 def setUp(self):
     super(TestEvents, self).setUp()
     self.devent = DummyEvent(lambda: True)
Exemplo n.º 18
0
 def test_on_pre_POST_contacts(self):
     devent = DummyEvent(self.before_insert)
     self.app.on_pre_POST_contacts += devent
     self.post()
     self.assertFalse(devent.called is None)
Exemplo n.º 19
0
 def test_on_inserted_contacts(self):
     devent = DummyEvent(self.after_insert, True)
     self.app.on_inserted_contacts += devent
     self.post()
     self.assertEqual(self.new_contact_id, devent.called[0][0]['ref'])
Exemplo n.º 20
0
 def test_on_inserted(self):
     devent = DummyEvent(self.after_insert, True)
     self.app.on_inserted += devent
     self.post()
     self.assertEqual(self.known_resource, devent.called[0])
     self.assertEqual(self.new_contact_id, devent.called[1][0]['ref'])
Exemplo n.º 21
0
 def test_on_POST_post_resource(self):
     devent = DummyEvent(self.after_insert)
     self.app.on_post_POST_contacts += devent
     self.post()
     self.assertFalse(devent.called is None)
Exemplo n.º 22
0
 def test_on_post_POST(self):
     devent = DummyEvent(self.after_insert)
     self.app.on_post_POST += devent
     self.post()
     self.assertEqual(devent.called[0], self.known_resource)
Exemplo n.º 23
0
 def test_on_replace_contacts(self):
     devent = DummyEvent(self.before_replace)
     self.app.on_replace_contacts += devent
     self.put()
     self.assertEqual(self.new_ref, devent.called[0]['ref'])
     self.assertEqual(2, len(devent.called))
Exemplo n.º 24
0
 def test_on_pre_PUT(self):
     devent = DummyEvent(self.before_replace)
     self.app.on_pre_PUT += devent
     self.put()
     self.assertEqual(self.known_resource, devent.called[0])
     self.assertEqual(3, len(devent.called))
Exemplo n.º 25
0
 def test_on_updated(self):
     devent = DummyEvent(self.after_update)
     self.app.on_updated += devent
     self.patch()
     self.assertEqual(self.known_resource, devent.called[0])
     self.assertEqual(3, len(devent.called))
Exemplo n.º 26
0
 def test_on_pre_PUT_contacts(self):
     devent = DummyEvent(self.before_replace)
     self.app.on_pre_PUT_contacts += devent
     self.put()
     self.assertEqual(2, len(devent.called))
Exemplo n.º 27
0
 def test_on_post_PATCH_contacts(self):
     devent = DummyEvent(self.after_update)
     self.app.on_post_PATCH_contacts += devent
     self.patch()
     self.assertEqual(200, devent.called[1].status_code)
     self.assertEqual(2, len(devent.called))
Exemplo n.º 28
0
 def test_on_replaced_contacts(self):
     devent = DummyEvent(self.after_replace)
     self.app.on_replaced_contacts += devent
     self.put()
     self.assertEqual(self.new_ref, devent.called[0]["ref"])
     self.assertEqual(2, len(devent.called))
Exemplo n.º 29
0
 def test_on_updated_contacts(self):
     devent = DummyEvent(self.after_update)
     self.app.on_updated_contacts += devent
     self.patch()
     self.assertEqual(2, len(devent.called))
Exemplo n.º 30
0
 def test_on_post_PUT_contacts(self):
     devent = DummyEvent(self.after_replace)
     self.app.on_post_PUT_contacts += devent
     self.put()
     self.assertEqual(200, devent.called[1].status_code)
     self.assertEqual(2, len(devent.called))