DJANGO TESTS: TypeError: test_suit_row_attributes() missing 1 required positional argument: 'request'

73 views Asked by At

I want to resolve this error and finish the test:

admin.py

def suit_row_attributes(self, obj, request):
    """Add colours to the rows according to the status"""

    type_error = 'notSent'
    status_colours = {Transaction.STATUS_REJECTED: 'error', Transaction.STATUS_RECEIVED: 'received',
                      Transaction.STATUS_PENDING: 'warning', Transaction.STATUS_ACCEPTED: 'success',
                      type_error: 'notSent'}
    try:
        tt_status = Transaction.objects.get(txid=obj.numero).last_status
    except Transaction.DoesNotExist:
        tt_status = type_error
    return {'class': status_colours.get(tt_status, 'success')}

in tests.py

def test_suit_row_attributes(self):
    self.assertEqual(self.admin_instance.suit_row_attributes(self.errortr_obj), {'class': 'notSent'})

Can someone help me, please?

1

There are 1 answers

0
Sandip Mahato On
from django.contrib.admin import ModelAdmin

class CountryAdmin(ModelAdmin):
    ...

    def suit_row_attributes(self, obj, request):
        return {'class': 'type-%s' % obj.type}

    # Or bit more advanced example
    def suit_row_attributes(self, obj, request):
        css_class = {
            1: 'success',
            0: 'warning',
            -1: 'error',
        }.get(obj.status)
        if css_class:
            return {'class': css_class, 'data': obj.name}

For more :- https://django-suit.readthedocs.io/en/develop/list_attributes.html