當前位置: 首頁>>代碼示例>>Python>>正文


Python messages.get_messages方法代碼示例

本文整理匯總了Python中django.contrib.messages.get_messages方法的典型用法代碼示例。如果您正苦於以下問題:Python messages.get_messages方法的具體用法?Python messages.get_messages怎麽用?Python messages.get_messages使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.contrib.messages的用法示例。


在下文中一共展示了messages.get_messages方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_add_selected_to_grouping

# 需要導入模塊: from django.contrib import messages [as 別名]
# 或者: from django.contrib.messages import get_messages [as 別名]
def test_add_selected_to_grouping(self):
        data = {
            'grouping': self.fake_grouping.id,
            'add': True,
            'isSelectAll': 'False',
            'selected-target': [self.fake_targets[0].id, self.fake_targets[1].id],
            'query_string': '',
        }
        response = self.client.post(reverse('targets:add-remove-grouping'), data=data)

        self.assertEqual(self.fake_grouping.targets.count(), 2)
        self.assertTrue(self.fake_targets[0] in self.fake_grouping.targets.all())
        self.assertTrue(self.fake_targets[1] in self.fake_grouping.targets.all())

        messages = [(m.message, m.level) for m in get_messages(response.wsgi_request)]
        self.assertIn(('1 target(s) successfully added to group \'{}\'.'.format(self.fake_grouping.name),
                       SUCCESS), messages)
        self.assertIn(('1 target(s) already in group \'{}\': {}'.format(
            self.fake_grouping.name, self.fake_targets[0].name), WARNING), messages) 
開發者ID:TOMToolkit,項目名稱:tom_base,代碼行數:21,代碼來源:tests.py

示例2: test_add_all_to_grouping_filtered_by_sidereal

# 需要導入模塊: from django.contrib import messages [as 別名]
# 或者: from django.contrib.messages import get_messages [as 別名]
def test_add_all_to_grouping_filtered_by_sidereal(self):
        data = {
            'grouping': self.fake_grouping.id,
            'add': True,
            'isSelectAll': 'True',
            'selected-target': [],
            'query_string': 'type=SIDEREAL&name=&key=&value=&targetlist__name=',
        }
        response = self.client.post(reverse('targets:add-remove-grouping'), data=data)
        self.assertEqual(self.fake_grouping.targets.count(), 3)
        messages = [(m.message, m.level) for m in get_messages(response.wsgi_request)]
        self.assertIn(('2 target(s) successfully added to group \'{}\'.'.format(self.fake_grouping.name),
                       SUCCESS), messages)
        self.assertIn((
            '1 target(s) already in group \'{}\': {}'.format(self.fake_grouping.name, self.fake_targets[0].name),
            WARNING), messages
        ) 
開發者ID:TOMToolkit,項目名稱:tom_base,代碼行數:19,代碼來源:tests.py

示例3: test_remove_all_from_grouping_filtered_by_sidereal

# 需要導入模塊: from django.contrib import messages [as 別名]
# 或者: from django.contrib.messages import get_messages [as 別名]
def test_remove_all_from_grouping_filtered_by_sidereal(self):
        data = {
            'grouping': self.fake_grouping.id,
            'remove': True,
            'isSelectAll': 'True',
            'selected-target': [],
            'query_string': 'type=SIDEREAL&name=&key=&value=&targetlist__name=',
        }
        response = self.client.post(reverse('targets:add-remove-grouping'), data=data)
        self.assertEqual(self.fake_grouping.targets.count(), 0)
        messages = [(m.message, m.level) for m in get_messages(response.wsgi_request)]
        self.assertIn(('1 target(s) successfully removed from group \'{}\'.'.format(self.fake_grouping.name),
                       SUCCESS), messages)
        self.assertIn(('2 target(s) not in group \'{}\': {}'.format(
            self.fake_grouping.name, self.fake_targets[1].name + ', ' + self.fake_targets[2].name
        ), WARNING), messages) 
開發者ID:TOMToolkit,項目名稱:tom_base,代碼行數:18,代碼來源:tests.py

示例4: test_tag_create_create_and_success

# 需要導入模塊: from django.contrib import messages [as 別名]
# 或者: from django.contrib.messages import get_messages [as 別名]
def test_tag_create_create_and_success(admin_client):
    """Tests that tag creation and success message works as expected."""
    tag_count = models.PlanTag.objects.all().count()

    response = admin_client.post(
        reverse('dfs_tag_create'),
        {'tag': '1'},
        follow=True,
    )

    messages = list(get_messages(response.wsgi_request))

    assert models.PlanTag.objects.all().count() == tag_count + 1
    assert messages[0].tags == 'success'
    assert messages[0].message == 'Tag successfully added'


# TagUpdateView
# ----------------------------------------------------------------------------- 
開發者ID:studybuffalo,項目名稱:django-flexible-subscriptions,代碼行數:21,代碼來源:test_views_tag.py

示例5: test_tag_update_update_and_success

# 需要導入模塊: from django.contrib import messages [as 別名]
# 或者: from django.contrib.messages import get_messages [as 別名]
def test_tag_update_update_and_success(admin_client):
    """Tests that tag update and success message works as expected."""
    # Setup initial tag for update
    tag = create_tag('1')
    tag_count = models.PlanTag.objects.all().count()

    response = admin_client.post(
        reverse('dfs_tag_update', kwargs={'tag_id': tag.id}),
        {'tag': '2'},
        follow=True,
    )

    messages = list(get_messages(response.wsgi_request))

    assert models.PlanTag.objects.all().count() == tag_count
    assert models.PlanTag.objects.get(id=tag.id).tag == '2'
    assert messages[0].tags == 'success'
    assert messages[0].message == 'Tag successfully updated'


# TagDeleteView
# ----------------------------------------------------------------------------- 
開發者ID:studybuffalo,項目名稱:django-flexible-subscriptions,代碼行數:24,代碼來源:test_views_tag.py

示例6: test_plan_list_create_create_and_success

# 需要導入模塊: from django.contrib import messages [as 別名]
# 或者: from django.contrib.messages import get_messages [as 別名]
def test_plan_list_create_create_and_success(admin_client):
    """Tests that plan list creation and success message works as expected."""
    plan_list_count = models.PlanList.objects.all().count()

    response = admin_client.post(
        reverse('dfs_plan_list_create'),
        {'title': '1'},
        follow=True,
    )

    messages = list(get_messages(response.wsgi_request))

    assert models.PlanList.objects.all().count() == plan_list_count + 1
    assert messages[0].tags == 'success'
    assert messages[0].message == 'Plan list successfully added'


# PlanListUpdateView
# ----------------------------------------------------------------------------- 
開發者ID:studybuffalo,項目名稱:django-flexible-subscriptions,代碼行數:21,代碼來源:test_views_plan_list.py

示例7: test_plan_list_update_update_and_success

# 需要導入模塊: from django.contrib import messages [as 別名]
# 或者: from django.contrib.messages import get_messages [as 別名]
def test_plan_list_update_update_and_success(admin_client):
    """Tests that plan list update and success message works as expected."""
    # Setup initial plan list for update
    plan_list = create_plan_list('1')
    plan_list_count = models.PlanList.objects.all().count()

    response = admin_client.post(
        reverse('dfs_plan_list_update', kwargs={'plan_list_id': plan_list.id}),
        {'title': '2'},
        follow=True,
    )

    messages = list(get_messages(response.wsgi_request))

    assert models.PlanList.objects.all().count() == plan_list_count
    assert models.PlanList.objects.get(id=plan_list.id).title == '2'
    assert messages[0].tags == 'success'
    assert messages[0].message == 'Plan list successfully updated'


# PlanListDeleteView
# ----------------------------------------------------------------------------- 
開發者ID:studybuffalo,項目名稱:django-flexible-subscriptions,代碼行數:24,代碼來源:test_views_plan_list.py

示例8: test_plan_create_create_and_success

# 需要導入模塊: from django.contrib import messages [as 別名]
# 或者: from django.contrib.messages import get_messages [as 別名]
def test_plan_create_create_and_success(admin_client):
    """Tests that plan creation and success message works as expected."""
    plan_count = models.SubscriptionPlan.objects.all().count()

    post_data = {
        'plan_name': '1',
        'plan_description': 'a',
        'grace_period': 0,
        'costs-TOTAL_FORMS': '0',
        'costs-INITIAL_FORMS': '0',
        'costs-MIN_NUM_FORMS': '0',
        'costs-MAX_NUM_FORMS': '1000',
    }

    response = admin_client.post(
        reverse('dfs_plan_create'),
        post_data,
        follow=True,
    )

    messages = list(get_messages(response.wsgi_request))

    assert models.SubscriptionPlan.objects.all().count() == plan_count + 1
    assert messages[0].tags == 'success'
    assert messages[0].message == 'Subscription plan successfully added' 
開發者ID:studybuffalo,項目名稱:django-flexible-subscriptions,代碼行數:27,代碼來源:test_views_plans.py

示例9: test_subscription_delete_and_success

# 需要導入模塊: from django.contrib import messages [as 別名]
# 或者: from django.contrib.messages import get_messages [as 別名]
def test_subscription_delete_and_success(admin_client, django_user_model):
    """Tests for success message on successful deletion."""
    user = django_user_model.objects.create_user(username='a', password='b')
    cost = create_cost(plan=create_plan())
    subscription = create_subscription(user, cost)
    subscription_count = models.UserSubscription.objects.all().count()

    response = admin_client.post(
        reverse(
            'dfs_subscription_delete',
            kwargs={'subscription_id': subscription.id}
        ),
        follow=True,
    )

    messages = list(get_messages(response.wsgi_request))

    assert models.UserSubscription.objects.all().count() == (
        subscription_count - 1
    )
    assert messages[0].tags == 'success'
    assert messages[0].message == 'User subscription successfully deleted' 
開發者ID:studybuffalo,項目名稱:django-flexible-subscriptions,代碼行數:24,代碼來源:test_views_subscription.py

示例10: test_cancel_post_updates_instance

# 需要導入模塊: from django.contrib import messages [as 別名]
# 或者: from django.contrib.messages import get_messages [as 別名]
def test_cancel_post_updates_instance(client, dfs):
    """Tests that POST request properly updates subscription instance."""
    subscription = dfs.subscription
    subscription_id = subscription.id

    client.force_login(dfs.user)
    response = client.post(
        reverse(
            'dfs_subscribe_cancel', kwargs={'subscription_id': subscription_id}
        ),
        follow=True
    )

    subscription = models.UserSubscription.objects.get(id=subscription_id)
    messages = list(get_messages(response.wsgi_request))

    assert subscription.date_billing_end == datetime(2018, 2, 1, 1, 1, 1)
    assert subscription.date_billing_next is None
    assert messages[0].tags == 'success'
    assert messages[0].message == 'Subscription successfully cancelled' 
開發者ID:studybuffalo,項目名稱:django-flexible-subscriptions,代碼行數:22,代碼來源:test_views_subscribe.py

示例11: test_detail_delete_delete_and_success_message

# 需要導入模塊: from django.contrib import messages [as 別名]
# 或者: from django.contrib.messages import get_messages [as 別名]
def test_detail_delete_delete_and_success_message(admin_client):
    """Tests for success message on successful deletion."""
    plan_list = create_plan_list()
    detail = create_plan_list_detail(plan_list=plan_list)
    detail_count = models.PlanListDetail.objects.all().count()

    response = admin_client.post(
        reverse(
            'dfs_plan_list_detail_delete',
            kwargs={
                'plan_list_id': plan_list.id,
                'plan_list_detail_id': detail.id
            }
        ),
        follow=True,
    )

    messages = list(get_messages(response.wsgi_request))

    assert models.PlanListDetail.objects.all().count() == detail_count - 1
    assert messages[0].tags == 'success'
    assert messages[0].message == (
        'Subscription plan successfully removed from plan list'
    ) 
開發者ID:studybuffalo,項目名稱:django-flexible-subscriptions,代碼行數:26,代碼來源:test_views_plan_list_detail.py

示例12: test_create_valid_user_success

# 需要導入模塊: from django.contrib import messages [as 別名]
# 或者: from django.contrib.messages import get_messages [as 別名]
def test_create_valid_user_success(self):
        """Test creating user with valid payload is successful"""

        payload = {
            "email": "test@gmail.com",
            "password1": "test@1234567",
            "password2": "test@1234567",
            "name": "Test name"
        }

        response = self.client.post(CREATE_USER_URL, payload)
        self.assertEqual(response.status_code, 302)
        user_exists = get_user_model().objects.filter(email=payload["email"]).exists()
        self.assertTrue(user_exists)
        user_profile_exists = MyProfile.objects.filter(owner__email="test@gmail.com").exists()
        self.assertTrue(user_profile_exists)
        self.assertEqual(response['Location'], "/")
        messages = list(get_messages(response.wsgi_request))
        self.assertEqual(str(messages[0]), "You have successfully registered") 
開發者ID:LukaszMalucha,項目名稱:Project-Dashboard-with-Django,代碼行數:21,代碼來源:test_views.py

示例13: test_login_valid_user_success

# 需要導入模塊: from django.contrib import messages [as 別名]
# 或者: from django.contrib.messages import get_messages [as 別名]
def test_login_valid_user_success(self):
        """Test login user with valid payload is successful"""

        payload = {
            "email": "test@gmail.com",
            "password": "test@1234567",
            "name": "Test name"
        }

        create_user(**payload)

        response = self.client.post(LOGIN_USER_URL, payload)
        self.assertEqual(response.status_code, 302)
        self.assertEqual(response['Location'], "/")
        messages = list(get_messages(response.wsgi_request))
        self.assertEqual(str(messages[0]), "You have successfully logged in") 
開發者ID:LukaszMalucha,項目名稱:Project-Dashboard-with-Django,代碼行數:18,代碼來源:test_views.py

示例14: test_login_invalid_credentials_user

# 需要導入模塊: from django.contrib import messages [as 別名]
# 或者: from django.contrib.messages import get_messages [as 別名]
def test_login_invalid_credentials_user(self):
        """Test login user with invalid credentials"""

        payload = {
            "email": "test@gmail.com",
            "password": "test@1234567",
            "name": "Test name"
        }

        payload_invalid = {
            "email": "invalid@gmail.com",
            "password": "test@1234567",
            "name": "Test name"
        }

        create_user(**payload)
        response = self.client.post(LOGIN_USER_URL, payload_invalid)
        self.assertEqual(response.status_code, 200)
        messages = list(get_messages(response.wsgi_request))
        self.assertEqual(str(messages[0]), "Incorrect username or password") 
開發者ID:LukaszMalucha,項目名稱:Project-Dashboard-with-Django,代碼行數:22,代碼來源:test_views.py

示例15: test_views_bootstrap_elasticsearch_with_permission

# 需要導入模塊: from django.contrib import messages [as 別名]
# 或者: from django.contrib.messages import get_messages [as 別名]
def test_views_bootstrap_elasticsearch_with_permission(self, mock_command):
        """Confirm triggering the search index bootstrapping works as expected."""
        user = UserFactory(is_staff=True)
        self.client.login(username=user.username, password="password")

        # Add the necessary permission
        self.add_permission(user, "can_manage_elasticsearch")

        url = "/api/v1.0/bootstrap-elasticsearch/"
        response = self.client.post(url, follow=True)
        self.assertEqual(response.status_code, 200)
        content = json.loads(response.content)
        self.assertEqual(content, {})

        # Check the presence of a confirmation message
        messages = list(get_messages(response.wsgi_request))
        self.assertEqual(len(messages), 1)
        self.assertEqual(
            str(messages[0]), "The search index was successfully bootstrapped"
        )

        mock_command.assert_called_once_with("bootstrap_elasticsearch") 
開發者ID:openfun,項目名稱:richie,代碼行數:24,代碼來源:test_views_bootstrap_elasticsearch.py


注:本文中的django.contrib.messages.get_messages方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。