Exemple #1
0
    def test_associate_sets_foreign_key_on_model(self):
        parent = Model()
        parent.foreign_key = 'foreign.value'
        parent.get_attribute = mock.MagicMock(return_value='foreign.value')
        parent.set_attribute = mock.MagicMock()
        parent.set_relation = mock.MagicMock()
        relation = self._get_relation(parent)
        associate = flexmock(Model())
        associate.should_receive('get_attribute').once().with_args(
            'id').and_return(1)

        relation.associate(associate)

        parent.get_attribute.assert_has_calls(
            [mock.call('foreign_key'),
             mock.call('foreign_key')])
        parent.set_attribute.assert_has_calls([mock.call('foreign_key', 1)])
        parent.set_relation.assert_called_once_with('relation', associate)
    def test_associate_sets_foreign_key_on_model(self):
        parent = Model()
        parent.foreign_key = 'foreign.value'
        parent.get_attribute = mock.MagicMock(return_value='foreign.value')
        parent.set_attribute = mock.MagicMock()
        parent.set_relation = mock.MagicMock()
        relation = self._get_relation(parent)
        associate = flexmock(Model())
        associate.should_receive('get_attribute').once().with_args('id').and_return(1)

        relation.associate(associate)

        parent.get_attribute.assert_has_calls([
            mock.call('foreign_key'),
            mock.call('foreign_key')
        ])
        parent.set_attribute.assert_has_calls([
            mock.call('foreign_key', 1)
        ])
        parent.set_relation.assert_called_once_with('relation', associate)