import pytest
from mock import Mock, patch, call

from ramses import generators
from .fixtures import engine_mock, config_mock


class TestHelperFunctions(object):
    @patch.object(generators, 'get_static_parent')
    def test_get_nefertari_parent_resource_no_parent(self, mock_get):
        mock_get.return_value = None
        assert generators._get_nefertari_parent_resource(1, 2, 3) == 3
        mock_get.assert_called_once_with(1)

    @patch.object(generators, 'get_static_parent')
    def test_get_nefertari_parent_resource_parent_not_defined(
            self, mock_get):
        mock_get.return_value = Mock(path='foo')
        assert generators._get_nefertari_parent_resource(
            1, {}, 3) == 3
        mock_get.assert_called_once_with(1)

    @patch.object(generators, 'get_static_parent')
    def test_get_nefertari_parent_resource_parent_defined(
            self, mock_get):
        mock_get.return_value = Mock(path='foo')
        assert generators._get_nefertari_parent_resource(
            1, {'foo': 'bar'}, 3) == 'bar'