def test_negative_fields(self): data = dict(limit_days=-1, limit_size=-1, limit_duplicated=-1) form = CrashManualCleanupForm(data=data, initial=dict(type='crash__Crash')) self.assertFalse(form.is_valid()) self.assertCountEqual(list(form.errors.keys()), ['limit_duplicated', 'limit_days', 'limit_size'])
def test_form(self): data = dict(limit_days=10, limit_size=10, limit_duplicated=10) form = CrashManualCleanupForm(data=data, initial=dict(type='crash__Crash')) self.assertTrue(form.is_valid()) self.assertEqual(form.cleaned_data['limit_days'], 10) self.assertEqual(form.cleaned_data['limit_size'], 10) self.assertEqual(form.cleaned_data['limit_duplicated'], 10) self.assertEqual(type(form.fields), OrderedDict) self.assertEqual(form.fields.keys(), ['limit_duplicated', 'limit_days', 'limit_size']) with mock.patch('omaha.tasks.deferred_manual_cleanup.apply_async') as mocked: form.cleanup() mock_args, mock_kwargs = mocked.call_args self.assertTrue(mocked.called) self.assertDictEqual(mock_args[1], data)