コード例 #1
0
    def test_not_found(self, token_is_valid, requests_mock):
        token_is_valid.return_value = True
        request = RequestFactory().get("/")
        request.session = {"tsuru_token": "admin"}
        requests_mock.return_value = Mock(status_code=404)

        service_instances_mock = Mock()
        service_instances_mock.return_value = [{"service": "mongodb", "instances": ["mymongo"]}]
        AppDetail.service_instances = service_instances_mock

        with self.assertRaises(Http404):
            AppDetail.as_view()(request, app_name="app1")
コード例 #2
0
    def test_not_found(self, token_is_valid, requests_mock):
        token_is_valid.return_value = True
        request = RequestFactory().get("/")
        request.session = {"tsuru_token": "admin"}
        requests_mock.return_value = Mock(status_code=404)

        service_instances_mock = Mock()
        service_instances_mock.return_value = [{
            "service": "mongodb",
            "instances": ["mymongo"]
        }]
        AppDetail.service_instances = service_instances_mock

        with self.assertRaises(Http404):
            AppDetail.as_view()(request, app_name="app1")
コード例 #3
0
ファイル: test_app_detail_view.py プロジェクト: hfeeki/abyss
 def test_should_use_detail_template(self):
     request = RequestFactory().get("/")
     request.session = {"tsuru_token":"admin"}
     with mock.patch("requests.get") as get:
         get.return_value = mock.Mock(status_code=200, json={})
         response = AppDetail.as_view()(request, app_name="app1")
     self.assertEqual("apps/details.html", response.template_name)
コード例 #4
0
    def setUp(self, requests_mock):
        request = RequestFactory().get("/")
        request.session = {"tsuru_token": "admin"}
        self.expected = {
            "name": "app1",
            "framework": "php",
            "repository": "[email protected]:php.git",
            "state": "dead",
            "units": [{
                "Ip": "10.10.10.10"
            }, {
                "Ip": "9.9.9.9"
            }],
            "teams": ["tsuruteam", "crane"]
        }
        json_mock = Mock()
        json_mock.json.return_value = self.expected
        requests_mock.return_value = json_mock

        service_instances_mock = Mock()
        service_instances_mock.return_value = [{
            "service": "mongodb",
            "instances": ["mymongo"]
        }]

        self.old_service_instances = AppDetail.service_instances
        AppDetail.service_instances = service_instances_mock

        self.response = AppDetail.as_view()(request, app_name="app1")
        self.request = request
コード例 #5
0
    def setUp(self, requests_mock):
        request = RequestFactory().get("/")
        request.session = {"tsuru_token": "admin"}
        self.expected = {
            "name": "app1",
            "framework": "php",
            "repository": "[email protected]:php.git",
            "state": "dead",
            "units": [
                {"Ip": "10.10.10.10", "Status": "started", "ProcessName": "web"},
                {"Ip": "9.9.9.9", "Status": "stopped", "ProcessName": "worker"},
            ],
            "teams": ["tsuruteam", "crane"]
        }
        json_mock = Mock(status_code=200)
        json_mock.json.return_value = self.expected
        requests_mock.return_value = json_mock

        service_instances_mock = Mock()
        service_instances_mock.return_value = [{"service": "mongodb", "instances": ["mymongo"]}]

        self.old_service_instances = AppDetail.service_instances
        AppDetail.service_instances = service_instances_mock

        self.response = AppDetail.as_view()(request, app_name="app1")
        self.request = request
コード例 #6
0
 def setUp(self, get, requests_mock):
     request = RequestFactory().get("/")
     request.session = {"tsuru_token": "admin"}
     self.expected = {
         "name": "app1",
         "framework": "php",
         "repository": "[email protected]:php.git",
         "state": "dead",
         "units": [
             {"Ip": "10.10.10.10"},
             {"Ip": "9.9.9.9"}
         ],
         "teams": ["tsuruteam", "crane"]
     }
     schema = Schema(
         "",
         type="object",
         properties={
             "units":
             {
                 "type": "array",
                 "items": {},
             },
             "teams":
             {
                 "type": "array",
                 "items": {},
             }
         }
     )
     resource = Resource(
         url="url.com",
         data=self.expected,
         schema=schema
     )
     get.return_value = resource
     json_mock = mock.Mock()
     json_mock.json.return_value = self.expected
     requests_mock.return_value = json_mock
     service_list_mock = mock.Mock()
     service_list_mock.return_value = [{"service": "mongodb",
                                        "instances": ["mymongo"]}]
     service_info_mock = mock.Mock()
     service_info_mock.return_value = {"Name": "mymongo",
                                       "ServiceName": "mongodb",
                                       "Apps": ["app1"]}
     self.old_service_list = AppDetail.service_list
     AppDetail.service_list = service_list_mock
     self.old_service_info = AppDetail.service_info
     AppDetail.service_info = service_info_mock
     self.response = AppDetail.as_view()(request, app_name="app1")
     self.request = request
コード例 #7
0
ファイル: test_app_detail_view.py プロジェクト: hfeeki/abyss
 def test_should_get_the_app_info_from_tsuru(self):
     request = RequestFactory().get("/")
     request.session = {"tsuru_token":"admin"}
     expected = {
         "Name": "app1",
         "Framework": "php",
         "Repository": "[email protected]:php.git",
         "State": "dead",
         "Units": [
             {"Ip": "10.10.10.10"},
             {"Ip": "9.9.9.9"}
         ],
         "Teams": ["tsuruteam", "crane"]
     }
     with mock.patch("requests.get") as get:
         get.return_value = mock.Mock(status_code=200, json=expected)
         response = AppDetail.as_view()(request, app_name="app1")
     self.assertDictEqual(expected, response.context_data["app"])
コード例 #8
0
 def setUp(self, get):
     request = RequestFactory().get("/")
     request.session = {"tsuru_token": "admin"}
     self.expected = {
         "name": "app1",
         "framework": "php",
         "repository": "[email protected]:php.git",
         "state": "dead",
         "units": [
             {"Ip": "10.10.10.10"},
             {"Ip": "9.9.9.9"}
         ],
         "teams": ["tsuruteam", "crane"]
     }
     schema = Schema(
         "",
         type="object",
         properties={
             "units":
             {
                 "type": "array",
                 "items": {},
             },
             "teams":
             {
                 "type": "array",
                 "items": {},
             }
         }
     )
     resource = Resource(
         url="url.com",
         data=self.expected,
         schema=schema
     )
     get.return_value = resource
     self.response = AppDetail.as_view()(request, app_name="app1")
コード例 #9
0
ファイル: urls.py プロジェクト: approom/approom
from django.conf.urls import patterns, include, url
from django.contrib.auth.decorators import login_required
from apps.views import AppList, AppDetail
urlpatterns = patterns('',
    url(r'^$', AppList.as_view(), name='applist'),
    url(r'^(?P<slug>[-\w]+)/$', AppDetail.as_view(), name='app'),
)
コード例 #10
0
ファイル: urls.py プロジェクト: hfeeki/abyss
class TextPlainView(TemplateView):
    def render_to_response(self, context, **kwargs):
        return super(TextPlainView, self).render_to_response(
            context, content_type='text/plain', **kwargs)

urlpatterns = patterns('',
    url(r'^robots\.txt$', TextPlainView.as_view(template_name='robots.txt')),
    url(r'^favicon\.ico$', RedirectView.as_view(url='/static/img/favicon.ico')),
    url(r'^$', Login.as_view(), name='login'),

    url(r'^login$', Login.as_view(), name='login'),
    url(r'^logout$', Logout.as_view(), name='logout'),
    url(r'^team/$', Team.as_view(), name='team'),
    url(r'^key/$', Key.as_view(), name='token'),
    url(r'^signup$', Signup.as_view(), name='signup'),

    url(r'^apps/$', ListApp.as_view(), name='list-app'),
    url(r'^apps/create/$', CreateApp.as_view(), name='create-app'),
    url(r'^app/run/$', Run.as_view(), name='run'),
    url(r'^app/(?P<app_name>[\w-]+)/$', AppDetail.as_view(), name='detail-app'),
    url(r'^app/(?P<name>[\w-]+)/remove/$', RemoveApp.as_view(), name='remove_app'),
    url(r'^app/(?P<app_name>[\w-]+)/log/$', AppLog.as_view(), name='app_log'),
    url(r'^app/(?P<app_name>[\w-]+)/env/$', AppEnv.as_view(), name='get-env'),
    url(r'^app/(?P<app_name>[\w-]+)/teams/$', AppTeams.as_view(), name='app-teams'),
    url(r'^app/(?P<app_name>[\w-]+)/team/add/$', AppAddTeam.as_view(), name='app-add-team'),
    url(r'^envs/$', "auth.views.env_vars", name='envs'),
)

urlpatterns += staticfiles_urlpatterns()