def test_form(self):

        # Set up a mock result for R.metric_slugs & R._category_slugs
        config = {
            'return_value.metric_slugs.return_value': ['test-slug'],
            'return_value._category_slugs.return_value': ['test-slug']
        }
        with patch('redis_metrics.forms.R', **config) as mock_R:
            # No Category
            form = MetricCategoryForm()
            self.assertFalse(form.fields['metrics'].required)

            mock_R.assert_has_calls([
                call(),
                call().metric_slugs(),
            ])
            self.assertEqual(
                form.fields['metrics'].choices,
                [('test-slug', 'test-slug')]
            )
            self.assertEqual(form.fields['metrics'].initial, None)
            self.assertEqual(form.fields['category_name'].initial, None)
            self.assertFalse(mock_R._category_slugs.called)
            mock_R.reset_mock()

            # With a Category
            initial = {'category_name': "Sample Category"}
            form = MetricCategoryForm(initial=initial)
            self.assertFalse(form.fields['metrics'].required)

            self.assertEqual(form.fields['metrics'].initial, ['test-slug'])
            self.assertEqual(
                form.fields['category_name'].initial,
                "Sample Category"
            )
            r = mock_R.return_value
            r._category_slugs.assert_called_once_with("Sample Category")
Star an XMPP session and send a message, then exit.
dataset/ETHPy150Open bradmontgomery/django-redis-metrics/redis_metrics/tests/test_forms.py/TestMetricCategoryForm.test_form--crossover with--dataset/ETHPy150Open kuri65536/python-for-android/python3-alpha/python-libs/pyxmpp2/simple.py/send_message