I agree with Carl's comment on the PR:
"I don't think it would complicate the API too much to have a count=1
kwarg, and if count > 1 expect received_kwargs to be a list of lists
instead of just a list. This keeps the API identical to what it is
currently for the common case, but makes it possible to make assertions
about multiple signals. I think this is a better API than a totally
separate assertion (we're still asserting that a signal was sent; what
would the multiple version be named? assertSignalSentMultiple? Ugh.) This
could be an enhancement in a separate PR, though.
Failing that, I think the assertion should pass if the signal was sent at
least once with the named kwargs (if no kwargs named, then it should pass
if sent at least once, period). The current behavior of just arbitrarily
asserting against the kwargs of the most recent signal is not good, IMO."
To provide a real world use case, I tried using the assertions in Django's
test suite. The context manager is a nice improvement except that most or
all tests are testing that a single was sent once so using the assertion in
its current form ("arbitrarily asserting against the kwargs of the most
recent signal is not good") would be relaxing the assertions.
On Tuesday, January 3, 2017 at 6:51:48 AM UTC-5, James Bennett wrote:
>
> On Tue, Jan 3, 2017 at 1:14 AM, Aymeric Augustin <
> [email protected] <javascript:>> wrote:
>
>> Regarding arguments, since signal receivers must accept **kwargs (that’s
>> a document requirement), I think it’s acceptable for assertSignalSent to
>> ignore unexpected arguments.
>>
>
> It's often the case that custom signals have particular arguments they
> want when being sent, and which receivers will depend on. Having a shortcut
> for saying "needs to have at least this set of arguments provided" seemed
> useful to me.
>
> For background, this was written to test signal sending in
> django-registration, which does define a couple of custom signals. The code
> in the PR has been incorporated into a base TestCase class in
> django-registration already, and examples of how it's used can be seen in
> django-registration's tests. For example, where a repeated account
> activation should succeed and send a signal on the first try, but fail and
> send no signal on later attempts:
>
>
> https://github.com/ubernostrum/django-registration/blob/master/registration/tests/test_hmac_workflow.py#L70
>
>
--
You received this message because you are subscribed to the Google Groups
"Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-developers/0c5162ab-75fa-4335-abe8-5057cb5c742f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.