Example #1
0
    async def test_run(self, event_loop):
        change = AddRelationChange(1, [],
                                   params={
                                       "endpoint1": "endpoint1",
                                       "endpoint2": "endpoint2"
                                   })

        rel1 = mock.Mock(name="rel1", **{"matches.return_value": False})
        rel2 = mock.Mock(name="rel2", **{"matches.return_value": True})

        model = mock.Mock()
        model.add_relation = base.AsyncMock(return_value=rel2)

        context = mock.Mock()
        context.resolveRelation = mock.Mock(
            side_effect=['endpoint_1', 'endpoint_2'])
        context.model = model
        model.relations = [rel1]

        result = await change.run(context)
        assert result is rel2

        model.add_relation.assert_called_once()
        model.add_relation.assert_called_with("endpoint_1", "endpoint_2")

        # confirm that it's idempotent
        context.resolveRelation.side_effect = ['endpoint_1', 'endpoint_2']
        model.add_relation.reset_mock()
        model.add_relation.return_value = None
        model.relations = [rel1, rel2]
        result = await change.run(context)
        assert result is rel2
        assert not model.add_relation.called
Example #2
0
 def test_dict_params(self):
     change = AddRelationChange(1, [], params={"endpoint1": "endpoint1",
                                               "endpoint2": "endpoint2"})
     self.assertEqual({"change_id": 1,
                       "requires": [],
                       "endpoint1": "endpoint1",
                       "endpoint2": "endpoint2"}, change.__dict__)
Example #3
0
    async def test_run(self, event_loop):
        change = AddRelationChange(1, [], params={"endpoint1": "endpoint1",
                                                  "endpoint2": "endpoint2"})

        model = mock.Mock()
        model.add_relation = base.AsyncMock(return_value="relation1")

        context = mock.Mock()
        context.resolveRelation = mock.Mock(side_effect=['endpoint_1', 'endpoint_2'])
        context.model = model

        result = await change.run(context)
        assert result == "relation1"

        model.add_relation.assert_called_once()
        model.add_relation.assert_called_with("endpoint_1", "endpoint_2")
Example #4
0
 def test_method(self):
     self.assertEqual("addRelation", AddRelationChange.method())