aboutsummaryrefslogtreecommitdiffstats
path: root/app/test/event_based_scan/test_instance_update.py
blob: b16a5b765f9b82737288201f4273f36b243f35ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
###############################################################################
# Copyright (c) 2017 Koren Lev (Cisco Systems), Yaron Yogev (Cisco Systems)   #
# and others                                                                  #
#                                                                             #
# All rights reserved. This program and the accompanying materials            #
# are made available under the terms of the Apache License, Version 2.0       #
# which accompanies this distribution, and is available at                    #
# http://www.apache.org/licenses/LICENSE-2.0                                  #
###############################################################################
from discover.events.event_instance_update import EventInstanceUpdate
from test.event_based_scan.test_data.event_payload_instance_update \
    import EVENT_PAYLOAD_INSTANCE_UPDATE, INSTANCE_DOCUMENT, \
    UPDATED_INSTANCE_FIELDS
from test.event_based_scan.test_event import TestEvent


class TestInstanceUpdate(TestEvent):

    def test_handle_normal_situation(self):
        self.values = EVENT_PAYLOAD_INSTANCE_UPDATE
        payload = self.values['payload']
        self.instance_id = payload['instance_id']

        instance = INSTANCE_DOCUMENT

        self.inv.get_by_id.return_value = instance

        # update instance document
        res = EventInstanceUpdate().handle(self.env, self.values)

        self.assertTrue(res.result)
        self.assertTrue(self.inv.values_replace.called)
        self.assertTrue(self.inv.set.called)

        # check that all changed fields are updated
        call_args, _ = self.inv.set.call_args
        self.assertTrue(all(item in call_args[0].items()
                            for item in UPDATED_INSTANCE_FIELDS.items()))