예제 #1
0
 def test_pools_when_api_returns_pools_in_new_format(self, get):
     mocked_response = Mock(status_code=200)
     mocked_response.json.return_value = json.loads('[{"name": "theonepool"}]')
     get.return_value = mocked_response
     view = CreateApp()
     pools = view.pools(self.request)
     self.assertEqual([("", ""), ("theonepool", "theonepool")], pools)
예제 #2
0
 def test_pools_when_api_returns_pools_in_older_format(self, get):
     mocked_response = Mock(status_code=200)
     mocked_response.json.return_value = json.loads('[{"Name": "dead"}]')
     get.return_value = mocked_response
     view = CreateApp()
     pools = view.pools(self.request)
     self.assertListEqual([("", ""), ("dead", "dead")], pools)
예제 #3
0
 def test_pools_when_api_returns_pools_in_older_format(self, get):
     mocked_response = Mock(status_code=200)
     mocked_response.json.return_value = json.loads('[{"Name": "dead"}]')
     get.return_value = mocked_response
     view = CreateApp()
     pools = view.pools(self.request)
     self.assertListEqual([("", ""), ("dead", "dead")], pools)
예제 #4
0
 def test_pools_when_api_returns_pools_in_new_format(self, get):
     mocked_response = Mock(status_code=200)
     mocked_response.json.return_value = json.loads(
         '[{"name": "theonepool"}]')
     get.return_value = mocked_response
     view = CreateApp()
     pools = view.pools(self.request)
     self.assertEqual([("", ""), ("theonepool", "theonepool")], pools)
    def test_teams_empty(self, get):
        m = Mock(status_code=204)
        get.return_value = m
        request = RequestFactory().get("/")
        request.session = {"tsuru_token": "tokentest"}

        view = CreateApp()
        teams = view.teams(request)
        self.assertEqual([("", "")], teams)
    def test_teams_empty(self, get):
        m = Mock(status_code=204)
        get.return_value = m
        request = RequestFactory().get("/")
        request.session = {"tsuru_token": "tokentest"}

        view = CreateApp()
        teams = view.teams(request)
        self.assertEqual([("", "")], teams)
예제 #7
0
    def test_post_should_split_tags(self, get):
        data = {"name": "myepe", "platform": "django", "tags": " tag 1 , tag 2, tag 3  ,, , "}
        request = RequestFactory().post("/", data)
        request.session = {'tsuru_token': 'tokentest'}

        view = CreateApp()
        view.plans = lambda r: ("basic", [("basic", "basic")])
        view.platforms = lambda r: [("django", "django")]
        view.post(request)

        CreateApp.client.apps.create.assert_called_with(name="myepe", platform="django", tag=["tag 1", "tag 2", "tag 3"])
예제 #8
0
    def test_post_should_send_to_tsuru_removing_empty_keys(self, get):
        data = {"name": "myepe", "platform": "django", "plan": ""}
        request = RequestFactory().post("/", data)
        request.session = {'tsuru_token': 'tokentest'}

        view = CreateApp()
        view.plans = lambda r: ("basic", [("basic", "basic")])
        view.platforms = lambda r: [("django", "django")]
        view.post(request)

        CreateApp.client.apps.create.assert_called_with(name="myepe", platform="django")
    def test_plans(self, get):
        content = u"""[{"name": "plan1"}]"""
        m = Mock(status_code=200, content=content)
        m.json.return_value = json.loads(content)
        get.return_value = m
        request = RequestFactory().get("/")
        request.session = {"tsuru_token": "tokentest"}

        view = CreateApp()
        plans = view.plans(request)
        self.assertEqual(("", [("", ""), ('plan1', 'plan1')]), plans)
    def test_pools_1_0(self, get):
        content = u"""[{"Name": "dead"}]"""
        m = Mock(status_code=200, content=content)
        m.json.return_value = json.loads(content)
        get.return_value = m
        request = RequestFactory().get("/")
        request.session = {'tsuru_token': 'tokentest'}

        view = CreateApp()
        pools = view.pools(request)
        self.assertListEqual([("", ""), ('dead', 'dead')], pools)
    def test_pools_empty(self, get):
        content = u"[]"
        m = Mock(status_code=200, content=content)
        m.json.return_value = json.loads(content)
        get.return_value = m
        request = RequestFactory().get("/")
        request.session = {'tsuru_token': 'tokentest'}

        view = CreateApp()
        pools = view.pools(request)
        self.assertListEqual([('', '')], pools)
    def test_pools_empty(self, get):
        content = u"[]"
        m = Mock(status_code=200, content=content)
        m.json.return_value = json.loads(content)
        get.return_value = m
        request = RequestFactory().get("/")
        request.session = {'tsuru_token': 'tokentest'}

        view = CreateApp()
        pools = view.pools(request)
        self.assertListEqual([('', '')], pools)
    def test_plans(self, get):
        content = u"""[{"name": "plan1"}]"""
        m = Mock(status_code=200, content=content)
        m.json.return_value = json.loads(content)
        get.return_value = m
        request = RequestFactory().get("/")
        request.session = {"tsuru_token": "tokentest"}

        view = CreateApp()
        plans = view.plans(request)
        self.assertEqual(("", [("", ""), ('plan1', 'plan1')]), plans)
    def test_pools_old_format(self, get):
        content = u"""[{"Pools": ["basic", "one"], "Team": "andrews"}]"""
        m = Mock(status_code=200, content=content)
        m.json.return_value = json.loads(content)
        get.return_value = m
        request = RequestFactory().get("/")
        request.session = {'tsuru_token': 'tokentest'}

        view = CreateApp()
        pools = view.pools(request)
        self.assertListEqual([("", ""), ('one', 'one'), ('basic', 'basic')], pools)
    def test_pools_1_0(self, get):
        content = u"""[{"Name": "dead"}]"""
        m = Mock(status_code=200, content=content)
        m.json.return_value = json.loads(content)
        get.return_value = m
        request = RequestFactory().get("/")
        request.session = {'tsuru_token': 'tokentest'}

        view = CreateApp()
        pools = view.pools(request)
        self.assertListEqual([("", ""), ('dead', 'dead')], pools)
    def test_pools_new_api(self, get):
        content = u"""{"pools_by_team": [{"Pools": ["one"], "Team": "admin"}],
            "public_pools": [{"Default": "True", "Public": "True", "Name": "basic", "Teams": []}]}"""
        m = Mock(status_code=200, content=content)
        m.json.return_value = json.loads(content)
        get.return_value = m
        request = RequestFactory().get("/")
        request.session = {"tsuru_token": "tokentest"}

        view = CreateApp()
        pools = view.pools(request)
        self.assertEqual([("", ""), ('one', 'one'), ('basic', 'basic')], pools)
    def test_pools_new_api(self, get):
        content = u"""{"pools_by_team": [{"Pools": ["one"], "Team": "admin"}],
            "public_pools": [{"Default": "True", "Public": "True", "Name": "basic", "Teams": []}]}"""
        m = Mock(status_code=200, content=content)
        m.json.return_value = json.loads(content)
        get.return_value = m
        request = RequestFactory().get("/")
        request.session = {"tsuru_token": "tokentest"}

        view = CreateApp()
        pools = view.pools(request)
        self.assertEqual([("", ""), ('one', 'one'), ('basic', 'basic')], pools)
    def test_pools_old_format(self, get):
        content = u"""[{"Pools": ["basic", "one"], "Team": "andrews"}]"""
        m = Mock(status_code=200, content=content)
        m.json.return_value = json.loads(content)
        get.return_value = m
        request = RequestFactory().get("/")
        request.session = {'tsuru_token': 'tokentest'}

        view = CreateApp()
        pools = view.pools(request)
        self.assertListEqual([("", ""), ('one', 'one'), ('basic', 'basic')],
                             pools)
    def test_plans_is_None(self, get_mock):
        response_mock = Mock()
        response_mock.json.return_value = None
        get_mock.return_value = response_mock

        data = {"name": "myepe", "platform": "django", "plan": "basic"}
        request = RequestFactory().post("/", data)
        request.session = {'tsuru_token': 'tokentest'}

        view = CreateApp()
        default, plans = view.plans(request)
        self.assertEqual(default, '')
        self.assertListEqual([('', '')], plans)
예제 #20
0
    def test_post_with_success_should_redirect_to_app_list(self, get, success):
        data = {"name": "myepe", "platform": "django", "plan": ""}
        request = RequestFactory().post("/", data)
        request.session = {'tsuru_token': 'tokentest'}

        view = CreateApp()
        view.plans = lambda r: ("basic", [("basic", "basic")])
        view.platforms = lambda r: [("django", "django")]
        response = view.post(request)

        success.assert_called_with(request, u'App was successfully created', fail_silently=True)
        self.assertEquals(302, response.status_code)
        self.assertEquals("/apps/", response.url)
    def test_plans_is_None(self, get_mock):
        response_mock = Mock()
        response_mock.json.return_value = None
        get_mock.return_value = response_mock

        data = {"name": "myepe", "platform": "django", "plan": "basic"}
        request = RequestFactory().post("/", data)
        request.session = {'tsuru_token': 'tokentest'}

        view = CreateApp()
        default, plans = view.plans(request)
        self.assertEqual(default, '')
        self.assertListEqual([('', '')], plans)
    def test_should_use_create_template(self, get):
        content = u"""[{"Name":"python"},{"Name":"ruby"},{"Name":"static"}]"""
        m = Mock(status_code=200, content=content)
        m.json.return_value = json.loads(content)
        get.return_value = m
        request = RequestFactory().get("/")
        request.session = {}

        view = CreateApp()
        view.plans = lambda r: ("small", [("small", "small")])
        view.teams = lambda r: []
        view.pools = lambda r: []
        response = view.get(request)

        self.assertEqual("apps/create.html", response.template_name)
    def test_post_with_success_should_redirect_to_app_list(self, get, success):
        data = {"name": "myepe", "platform": "django", "plan": ""}
        request = RequestFactory().post("/", data)
        request.session = {'tsuru_token': 'tokentest'}

        view = CreateApp()
        view.plans = lambda r: ("basic", [("basic", "basic")])
        view.platforms = lambda r: [("django", "django")]
        response = view.post(request)

        success.assert_called_with(request,
                                   u'App was successfully created',
                                   fail_silently=True)
        self.assertEquals(302, response.status_code)
        self.assertEquals("/apps/", response.url)
    def test_AppForm_should_be_in_context(self, get):
        content = u"""[{"Name":"python"},{"Name":"ruby"},{"Name":"static"}]"""
        m = Mock(status_code=200, content=content)
        m.json.return_value = json.loads(content)
        get.return_value = m
        request = RequestFactory().get("/")
        request.session = {}

        view = CreateApp()
        view.plans = lambda r: ("basic", [("basic", "basic")])
        view.teams = lambda r: []
        view.pools = lambda r: []
        response = view.get(request)

        app_form = response.context_data['app_form']
        self.assertIsInstance(app_form, forms.AppForm)
    def test_post_without_name_should_return_form_with_errors(self, get):
        content = u"""[{"Name":"python"},{"Name":"ruby"},{"Name":"static"}]"""
        m = Mock(status_code=200, content=content)
        m.json.return_value = json.loads(content)
        get.return_value = m
        request = RequestFactory().post("/", {"name": ""})
        request.session = {}

        view = CreateApp()
        view.plans = lambda r: ("small", [("small", "small")])
        view.teams = lambda r: []
        view.pools = lambda r: []
        response = view.post(request)

        form = response.context_data.get('app_form')
        self.assertIn('name', form.errors)
        self.assertIn(u'This field is required.', form.errors.get('name'))
    def test_post_should_send_to_tsuru_with_args_expected(self, post, get):
        post.return_value = Mock(status_code=200)

        data = {"name": "myepe", "platform": "django", "plan": "basic"}
        request = RequestFactory().post("/", data)
        request.session = {'tsuru_token': 'tokentest'}

        view = CreateApp()
        view.plans = lambda r: ("basic", [("basic", "basic")])
        view.platforms = lambda r: [("django", "django")]
        view.post(request)

        self.assertEqual(1, post.call_count)
        url = '{}/apps'.format(settings.TSURU_HOST)
        post.assert_called_with(
            url,
            data='{"platform": "django", "name": "myepe", "plan": {"name": "basic"}}',
            headers={'authorization': request.session['tsuru_token']}
        )
    def test_post_should_send_to_tsuru_removing_empty_keys(self, get):
        data = {"name": "myepe", "platform": "django", "plan": ""}
        request = RequestFactory().post("/", data)
        request.session = {'tsuru_token': 'tokentest'}

        view = CreateApp()
        view.plans = lambda r: ("basic", [("basic", "basic")])
        view.platforms = lambda r: [("django", "django")]
        view.post(request)

        CreateApp.client.apps.create.assert_called_with(name="myepe",
                                                        platform="django")
    def test_should_use_create_template(self, get):
        content = u"""[{"Name":"python"},{"Name":"ruby"},{"Name":"static"}]"""
        m = Mock(status_code=200, content=content)
        m.json.return_value = json.loads(content)
        get.return_value = m
        request = RequestFactory().get("/")
        request.session = {}

        view = CreateApp()
        view.plans = lambda r: ("small", [("small", "small")])
        view.teams = lambda r: []
        view.pools = lambda r: []
        response = view.get(request)

        self.assertEqual("apps/create.html", response.template_name)
    def test_post_should_split_tags(self, get):
        data = {
            "name": "myepe",
            "platform": "django",
            "tags": " tag 1 , tag 2, tag 3  ,, , "
        }
        request = RequestFactory().post("/", data)
        request.session = {'tsuru_token': 'tokentest'}

        view = CreateApp()
        view.plans = lambda r: ("basic", [("basic", "basic")])
        view.platforms = lambda r: [("django", "django")]
        view.post(request)

        CreateApp.client.apps.create.assert_called_with(
            name="myepe", platform="django", tag=["tag 1", "tag 2", "tag 3"])
    def test_AppForm_should_be_in_context(self, get):
        content = u"""[{"Name":"python"},{"Name":"ruby"},{"Name":"static"}]"""
        m = Mock(status_code=200, content=content)
        m.json.return_value = json.loads(content)
        get.return_value = m
        request = RequestFactory().get("/")
        request.session = {}

        view = CreateApp()
        view.plans = lambda r: ("basic", [("basic", "basic")])
        view.teams = lambda r: []
        view.pools = lambda r: []
        response = view.get(request)

        app_form = response.context_data['app_form']
        self.assertIsInstance(app_form, forms.AppForm)
예제 #31
0
    def test_post_with_invalid_name_should_return_500(self, post, get, error):
        content = u"""[{"Name":"python"},{"Name":"ruby"},{"Name":"static"}]"""
        m = Mock(status_code=200, content=content)
        m.json.return_value = json.loads(content)
        get.return_value = m
        request = RequestFactory().post("/", {
            "name": "myepe",
            "platform": "python"
        })
        request.session = {}
        post.return_value = Mock(status_code=500, content='Error')

        view = CreateApp()
        view.plans = lambda r: ("small", [("small", "small")])
        view.teams = lambda r: []
        view.pools = lambda r: []

        view.post(request)

        error.assert_called_with(request, u'Error', fail_silently=True)
    def test_post_without_name_should_return_form_with_errors(self, get):
        content = u"""[{"Name":"python"},{"Name":"ruby"},{"Name":"static"}]"""
        m = Mock(status_code=200, content=content)
        m.json.return_value = json.loads(content)
        get.return_value = m
        request = RequestFactory().post("/", {"name": ""})
        request.session = {}

        view = CreateApp()
        view.plans = lambda r: ("small", [("small", "small")])
        view.teams = lambda r: []
        view.pools = lambda r: []
        response = view.post(request)

        form = response.context_data.get('app_form')
        self.assertIn('name', form.errors)
        self.assertIn(u'This field is required.', form.errors.get('name'))
예제 #33
0
    def test_post_with_errors_should_show_error_message(self, get, error):
        content = u"""[{"Name":"python"},{"Name":"ruby"},{"Name":"static"}]"""
        m = Mock(status_code=200, content=content)
        m.json.return_value = json.loads(content)
        get.return_value = m
        request = RequestFactory().post(
            "/",
            {"name": "myepe", "platform": "python"})
        request.session = {}

        view = CreateApp()
        view.plans = lambda r: ("small", [("small", "small")])
        view.teams = lambda r: []
        view.pools = lambda r: []

        view.post(request)

        error.assert_called_with(request, u'Error creating app', fail_silently=True)
예제 #34
0
    def test_post_should_send_to_tsuru_removing_empty_keys(self, post, get):
        post.return_value = Mock(status_code=200)

        data = {"name": "myepe", "platform": "django", "plan": ""}
        request = RequestFactory().post("/", data)
        request.session = {'tsuru_token': 'tokentest'}

        view = CreateApp()
        view.plans = lambda r: ("basic", [("basic", "basic")])
        view.platforms = lambda r: [("django", "django")]
        view.post(request)

        self.assertEqual(1, post.call_count)
        url = '{}/apps'.format(settings.TSURU_HOST)
        post.assert_called_with(
            url,
            data={
                "platform": "django",
                "name": "myepe"
            },
            headers={'authorization': request.session['tsuru_token']})
예제 #35
0
 def test_pools_when_api_returns_no_content(self, get):
     mocked_response = Mock(status_code=204)
     get.return_value = mocked_response
     view = CreateApp()
     pools = view.pools(self.request)
     self.assertListEqual([('', '')], pools)
예제 #36
0
 def test_pools_when_api_returns_no_content(self, get):
     mocked_response = Mock(status_code=204)
     get.return_value = mocked_response
     view = CreateApp()
     pools = view.pools(self.request)
     self.assertListEqual([('', '')], pools)