Esempio n. 1
0
    def test_add_track_with_all_fields(self, fake_tq):
        (fake_tq.expects('add')
                .with_args(
                    url=reverse('playlists.send_track_to_live_site'),
                    params={'id': arg.any_value()},
                    queue_name='live-site-playlists'
                )
                .next_call()
                .with_args(
                    url=reverse('playlists.play_count'),
                    params={'id': arg.any_value()}
                ))

        resp = self.client.post(reverse('playlists_add_event'), {
            'artist': "Squarepusher",
            'song': "Port Rhombus",
            "album": "Port Rhombus EP",
            "label": "Warp Records",
            "song_notes": "Dark melody. Really nice break down into half time."
        })

        self.assertNoFormErrors(resp)
        self.assertRedirects(resp, reverse('playlists_landing_page'))
        # simulate the redirect:
        resp = self.client.get(reverse('playlists_landing_page'))
        context = resp.context[0]
        tracks = [t for t in context['playlist_events']]
        self.assertEquals(tracks[0].artist_name, "Squarepusher")
        self.assertEquals(tracks[0].track_title, "Port Rhombus")
        self.assertEquals(tracks[0].album_title, "Port Rhombus EP")
        self.assertEquals(tracks[0].label, "Warp Records")
        self.assertEquals(tracks[0].notes,
                "Dark melody. Really nice break down into half time.")
Esempio n. 2
0
    def test_put_use_sudo_temp_dir(self):
        """
        put(use_sudo=True, temp_dir='/tmp/') works by uploading a file to /tmp/ and then moving it to a `remote_path`
        """
        # the sha1 hash is the unique filename of the file being downloaded. sha1(<filename>)
        fake_run = Fake(
            '_run_command', callable=True, expect_call=True
        ).with_matching_args(
            'mv "/tmp/7c91837ec0b3570264a325df6b7ef949ee22bc56" "/foobar.txt"',
            True,
            True,
            None,
        )
        fake_put = Fake('put', callable=True, expect_call=True).with_args(
            fudge_arg.any_value(),
            '/tmp/7c91837ec0b3570264a325df6b7ef949ee22bc56')

        local_path = self.mkfile('foobar.txt', "baz")
        with hide('everything'):
            with patched_context('fabric.operations', '_run_command',
                                 fake_run):
                with patched_context(SFTPClient, 'put', fake_put):
                    retval = put(local_path,
                                 "/",
                                 use_sudo=True,
                                 temp_dir='/tmp/')
                    # check that the downloaded file has the same name as the one requested
                    assert retval[0].endswith('foobar.txt')
Esempio n. 3
0
    def test_get_use_sudo(self):
        """
        get(use_sudo=True) works by copying to a temporary path, downloading it and then removing it at the end
        """
        # the sha1 hash is the unique filename of the file being downloaded. sha1(<filename>)
        fake_run = Fake(
            '_run_command', callable=True, expect_call=True
        ).with_matching_args(
            'cp -p "/etc/apache2/apache2.conf" "229a29e5693876645e39de0cb0532e43ad73311a"',
            True,
            True,
            None,
        ).next_call().with_matching_args(
            'chmod 404 "229a29e5693876645e39de0cb0532e43ad73311a"',
            True,
            True,
            None,
        ).next_call().with_matching_args(
            'rm -f "229a29e5693876645e39de0cb0532e43ad73311a"',
            True,
            True,
            None,
        )
        fake_get = Fake('get', callable=True, expect_call=True).with_args(
            '229a29e5693876645e39de0cb0532e43ad73311a', fudge_arg.any_value())

        with hide('everything'):
            with patched_context('fabric.operations', '_run_command',
                                 fake_run):
                with patched_context(SFTPClient, 'get', fake_get):
                    retval = get('/etc/apache2/apache2.conf',
                                 self.path(),
                                 use_sudo=True)
                    # check that the downloaded file has the same name as the one requested
                    assert retval[0].endswith('apache2.conf')
Esempio n. 4
0
def test_create_action():
    clear()
    clear_expectations()

    store_create_action.expects('add').with_args(arg.any_value())

    controller = controllers.ProjectController()

    controller.create(name=u"project_name", build_script=u"build_script", scm_repository=u"scm_repository", monitor_changes="MONITOR", branch="master")
Esempio n. 5
0
def test_authenticated_decorator_checks_for_user():
    clear_expectations()
    clear()

    class TestController(Controller):
        @authenticated
        def some_action(self):
            pass

    ctrl = TestController()

    fake_server = Fake('server')
    ctrl.server = fake_server
    ctrl.server.context = Fake('context')

    ctrl.server.expects('publish').with_args('on_before_user_authentication', arg.any_value())
    ctrl.server.next_call('publish').with_args('on_user_authentication_failed', arg.any_value())

    ctrl.some_action()
Esempio n. 6
0
def test_authenticated_decorator_executes_function_when_user_exists():
    clear_expectations()
    clear()

    class TestController(Controller):
        @authenticated
        def some_action(self):
            return "some_action_result"

    ctrl = TestController()

    fake_server = Fake('server')
    ctrl.server = fake_server
    ctrl.server.context = Fake('context')

    ctrl.server.expects('publish').with_args('on_before_user_authentication', arg.any_value())
    ctrl.server.next_call('publish').with_args('on_user_authentication_successful', arg.any_value())

    result = ctrl.some_action()

    assert result == "some_action_result"
Esempio n. 7
0
    def test_add_track_with_all_fields(self, fake_tq):
        (fake_tq.expects('add')
                .with_args(
                    url=reverse('playlists.send_track_to_live_site'),
                    params={'id': arg.any_value()},
                    queue_name='live-site-playlists'
                )
                .next_call()
                .with_args(
                    url=reverse('playlists.send_track_to_live365'),
                    params={'id': arg.any_value()}
                )
                .next_call()
                .with_args(
                    url=reverse('playlists.play_count'),
                    params={'id': arg.any_value()}
                ))

        resp = self.client.post(reverse('playlists_add_event'), {
            'artist': "Squarepusher",
            'song': "Port Rhombus",
            "album": "Port Rhombus EP",
            "label": "Warp Records",
            "song_notes": "Dark melody. Really nice break down into half time."
        })

        self.assertNoFormErrors(resp)
        self.assertRedirects(resp, reverse('playlists_landing_page'))
        # simulate the redirect:
        resp = self.client.get(reverse('playlists_landing_page'))
        context = resp.context[0]
        tracks = [t for t in context['playlist_events']]
        self.assertEquals(tracks[0].artist_name, "Squarepusher")
        self.assertEquals(tracks[0].track_title, "Port Rhombus")
        self.assertEquals(tracks[0].album_title, "Port Rhombus EP")
        self.assertEquals(tracks[0].label, "Warp Records")
        self.assertEquals(tracks[0].notes,
                "Dark melody. Really nice break down into half time.")
Esempio n. 8
0
    def test_put_use_sudo_temp_dir(self):
        """
        put(use_sudo=True, temp_dir='/tmp/') works by uploading a file to /tmp/ and then moving it to a `remote_path`
        """
        # the sha1 hash is the unique filename of the file being downloaded. sha1(<filename>)
        fake_run = Fake('_run_command', callable=True, expect_call=True).with_matching_args(
            'mv "/tmp/7c91837ec0b3570264a325df6b7ef949ee22bc56" "/foobar.txt"', True, True, None,
        )
        fake_put = Fake('put', callable=True, expect_call=True).with_args(fudge_arg.any_value(),
                                                                          '/tmp/7c91837ec0b3570264a325df6b7ef949ee22bc56')

        local_path = self.mkfile('foobar.txt', "baz")
        with hide('everything'):
            with patched_context('fabric.operations', '_run_command', fake_run):
                with patched_context(SFTPClient, 'put', fake_put):
                    retval = put(local_path, "/", use_sudo=True, temp_dir='/tmp/')
                    # check that the downloaded file has the same name as the one requested
                    assert retval[0].endswith('foobar.txt')
Esempio n. 9
0
    def test_put_use_sudo(self):
        """
        put(use_sudo=True) works by uploading a the `local_path` to a temporary path and then moving it to a `remote_path`
        """
        # the sha1 hash is the unique filename of the file being downloaded. sha1(<filename>)
        fake_run = Fake("_run_command", callable=True, expect_call=True).with_matching_args(
            'mv "7c91837ec0b3570264a325df6b7ef949ee22bc56" "/foobar.txt"', True, True, None
        )
        fake_put = Fake("put", callable=True, expect_call=True).with_args(
            fudge_arg.any_value(), "7c91837ec0b3570264a325df6b7ef949ee22bc56"
        )

        local_path = self.mkfile("foobar.txt", "baz")
        with hide("everything"):
            with patched_context("fabric.operations", "_run_command", fake_run):
                with patched_context(SFTPClient, "put", fake_put):
                    retval = put(local_path, "/", use_sudo=True)
                    # check that the downloaded file has the same name as the one requested
                    assert retval[0].endswith("foobar.txt")
Esempio n. 10
0
    def test_get_use_sudo_temp_dir(self):
        """
        get(use_sudo=True, temp_dir="/tmp") works by copying to a /tmp/sha1_hash, downloading it and then removing it at the end
        """
        # the sha1 hash is the unique filename of the file being downloaded. sha1(<filename>)
        fake_run = Fake('_run_command', callable=True, expect_call=True).with_matching_args(
            'cp -p "/etc/apache2/apache2.conf" "/tmp/229a29e5693876645e39de0cb0532e43ad73311a"', True, True, None,
        ).next_call().with_matching_args(
            'chmod 404 "/tmp/229a29e5693876645e39de0cb0532e43ad73311a"', True, True, None,
        ).next_call().with_matching_args(
            'rm -f "/tmp/229a29e5693876645e39de0cb0532e43ad73311a"', True, True, None,
        )
        fake_get = Fake('get', callable=True, expect_call=True).with_args('/tmp/229a29e5693876645e39de0cb0532e43ad73311a',
                                                                          fudge_arg.any_value())

        with hide('everything'):
            with patched_context('fabric.operations', '_run_command', fake_run):
                with patched_context(SFTPClient, 'get', fake_get):
                    retval = get('/etc/apache2/apache2.conf', self.path(), use_sudo=True, temp_dir="/tmp")
                    # check that the downloaded file has the same name as the one requested
                    assert retval[0].endswith('apache2.conf')
Esempio n. 11
0
    def test_get_use_sudo_temp_dir(self):
        """
        get(use_sudo=True, temp_dir="/tmp") works by copying to /tmp/..., downloading it and then removing it at the end
        """
        fake_run = Fake('_run_command', callable=True,
                        expect_call=True).with_matching_args(
                            fudge_arg.startswith(
                                'cp -p "/etc/apache2/apache2.conf" "/tmp/'),
                            True,
                            True,
                            None,
                        ).next_call().with_matching_args(
                            fudge_arg.startswith('chown username "/tmp/'),
                            True,
                            True,
                            None,
                        ).next_call().with_matching_args(
                            fudge_arg.startswith('chmod 400 "/tmp/'),
                            True,
                            True,
                            None,
                        ).next_call().with_matching_args(
                            fudge_arg.startswith('rm -f "/tmp/'),
                            True,
                            True,
                            None,
                        )
        fake_get = Fake('get', callable=True, expect_call=True).with_args(
            fudge_arg.startswith('/tmp/'), fudge_arg.any_value())

        with hide('everything'):
            with patched_context('fabric.operations', '_run_command',
                                 fake_run):
                with patched_context(SFTPClient, 'get', fake_get):
                    retval = get('/etc/apache2/apache2.conf',
                                 self.path(),
                                 use_sudo=True,
                                 temp_dir="/tmp")
                    # check that the downloaded file has the same name as the one requested
                    assert retval[0].endswith('apache2.conf')
Esempio n. 12
0
    def test_get_use_sudo_temp_dir(self):
        """
        get(use_sudo=True, temp_dir="/tmp") works by copying to /tmp/..., downloading it and then removing it at the end
        """
        fake_run = Fake('_run_command', callable=True, expect_call=True).with_matching_args(
            fudge_arg.startswith('cp -p "/etc/apache2/apache2.conf" "/tmp/'), True, True, None,
        ).next_call().with_matching_args(
            fudge_arg.startswith('chown username "/tmp/'), True, True, None,
        ).next_call().with_matching_args(
            fudge_arg.startswith('chmod 400 "/tmp/'), True, True, None,
        ).next_call().with_matching_args(
            fudge_arg.startswith('rm -f "/tmp/'), True, True, None,
        )
        fake_get = Fake('get', callable=True, expect_call=True).with_args(
            fudge_arg.startswith('/tmp/'), fudge_arg.any_value())

        with hide('everything'):
            with patched_context('fabric.operations', '_run_command', fake_run):
                with patched_context(SFTPClient, 'get', fake_get):
                    retval = get('/etc/apache2/apache2.conf', self.path(), use_sudo=True, temp_dir="/tmp")
                    # check that the downloaded file has the same name as the one requested
                    assert retval[0].endswith('apache2.conf')
Esempio n. 13
0
    def test_get_use_sudo(self):
        """
        get(use_sudo=True) works by copying to a temporary path, downloading it and then removing it at the end
        """
        # the sha1 hash is the unique filename of the file being downloaded. sha1(<filename>)
        name = "229a29e5693876645e39de0cb0532e43ad73311a"
        fake_run = (
            Fake("_run_command", callable=True, expect_call=True)
            .with_matching_args('cp -p "/etc/apache2/apache2.conf" "%s"' % name, True, True, None)
            .next_call()
            .with_matching_args('chown username "%s"' % name, True, True, None)
            .next_call()
            .with_matching_args('chmod 400 "%s"' % name, True, True, None)
            .next_call()
            .with_matching_args('rm -f "%s"' % name, True, True, None)
        )
        fake_get = Fake("get", callable=True, expect_call=True).with_args(name, fudge_arg.any_value())

        with hide("everything"):
            with patched_context("fabric.operations", "_run_command", fake_run):
                with patched_context(SFTPClient, "get", fake_get):
                    retval = get("/etc/apache2/apache2.conf", self.path(), use_sudo=True)
                    # check that the downloaded file has the same name as the one requested
                    assert retval[0].endswith("apache2.conf")
Esempio n. 14
0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from fudge import Fake, with_fakes, with_patched_object, clear_expectations

from fudge.inspector import arg

import ion.settings as sets
from ion import Settings, SettingsSection
from ConfigParser import ConfigParser, NoSectionError, NoOptionError

exists_fake = Fake(callable=True).with_args(arg.any_value()).returns(True)

parser = Fake("ConfigParser").expects("__init__").expects("read").with_args(arg.endswith("config.ini"))


@with_fakes
@with_patched_object(sets, "ConfigParser", parser)
@with_patched_object(sets, "exists", exists_fake)
def test_can_create_settings():
    clear_expectations()
    settings = Settings("some_dir")

    assert settings


@with_fakes
Esempio n. 15
0
def test_route_decorator_registers_route_with_custom_name():
    clear_expectations()
    clear()
    class TestController(Controller):
        @route("/something", name="named_route")
        def SomeAction(self):
            pass

    assert TestController.__routes__

    assert TestController.__routes__[0][0] == 'named_route'
    assert TestController.__routes__[0][1]['route'] == '/something'
    assert TestController.__routes__[0][1]['method'] == 'SomeAction'

dispatcher = Fake("dispatcher")
dispatcher.expects("connect").with_args("test_SomeAction", "/something", controller=arg.any_value(), action="SomeAction")
@with_fakes
def test_register_routes():
    clear_expectations()
    clear()

    class TestController(Controller):
        @route("/something")
        def SomeAction(self):
            pass

    ctrl = TestController()

    ctrl.register_routes(dispatcher)

template_context = Fake('context').has_attr(settings=Fake('settings'))