当前位置: 首页>>代码示例>>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;未经允许,请勿转载。