Repository: celery/celery
File: t/unit/tasks/test_result.py (Python)

Code before:
            task='foo',
            children=None,
            args=['one', 'two'],
            kwargs={'kwarg1': 'three'},
            hostname="foo",
            retries=1,
            delivery_info={'routing_key': 'celery'}
        )
        x.backend.store_result(task_id="1", result='foo', state=states.SUCCESS,
                               traceback=None, request=request)
        assert x.name == 'foo'
        assert x.args == ['one', 'two']
        assert x.kwargs == {'kwarg1': 'three'}
        assert x.worker == 'foo'
        assert x.retries == 1
        assert x.queue == 'celery'
        assert isinstance(x.date_done, datetime.datetime)
        assert x.task_id == "1"
        assert x.state == "SUCCESS"
        result = self.app.AsyncResult(self.task4['id'])
        assert result.date_done is None

    @patch('celery.app.base.to_utc')
    @patch('celery.app.base.Celery.timezone', new_callable=mock.PropertyMock)
    @pytest.mark.parametrize('timezone, date', [
        ("utc", "2024-08-24T00:00:00+00:00"),
        ("America/Los_Angeles", "2024-08-23T17:00:00-07:00"),
        ("Pacific/Kwajalein", "2024-08-24T12:00:00+12:00"),
        ("Europe/Berlin", "2024-08-24T02:00:00+02:00"),
    ])
    def test_date_done(self, timezone_mock, utc_datetime_mock, timezone, date):
        timezone_mock.return_value = ZoneInfo(timezone)
        utc_datetime_mock.return_value = datetime.datetime(2024, 8, 24, 0, 0, 0, 0, datetime.timezone.utc)

        result = Backend(app=self.app)._get_result_meta(None, states.SUCCESS, None, None)
        assert result.get('date_done') == date


class test_ResultSet:

    def test_resultset_repr(self):
        assert repr(self.app.ResultSet(
            [self.app.AsyncResult(t) for t in ['1', '2', '3']]))

    def test_eq_other(self):
        assert self.app.ResultSet([
            self.app.AsyncResult(t) for t in [1, 3, 3]]) != 1
        rs1 = self.app.ResultSet([self.app.AsyncResult(1)])
        rs2 = self.app.ResultSet([self.app.AsyncResult(1)])
        assert rs1 == rs2


Review comment (suggestion):
```suggestion
        (None, "2024-08-24T00:00:00+00:00"),
```

Code after:
            args=['one', 'two'],
            kwargs={'kwarg1': 'three'},
            hostname="foo",
            retries=1,
            delivery_info={'routing_key': 'celery'}
        )
        x.backend.store_result(task_id="1", result='foo', state=states.SUCCESS,
                               traceback=None, request=request)
        assert x.name == 'foo'
        assert x.args == ['one', 'two']
        assert x.kwargs == {'kwarg1': 'three'}
        assert x.worker == 'foo'
        assert x.retries == 1
        assert x.queue == 'celery'
        assert isinstance(x.date_done, datetime.datetime)
        assert x.task_id == "1"
        assert x.state == "SUCCESS"
        result = self.app.AsyncResult(self.task4['id'])
        assert result.date_done is None

    @patch('celery.app.base.to_utc')
    @pytest.mark.parametrize('timezone, date', [
        ("UTC", "2024-08-24T00:00:00+00:00"),
        ("America/Los_Angeles", "2024-08-23T17:00:00-07:00"),
        ("Pacific/Kwajalein", "2024-08-24T12:00:00+12:00"),
        ("Europe/Berlin", "2024-08-24T02:00:00+02:00"),
    ])
    def test_date_done(self, utc_datetime_mock, timezone, date):
        utc_datetime_mock.return_value = datetime.datetime(2024, 8, 24, 0, 0, 0, 0, datetime.timezone.utc)
        self.app.conf.timezone = timezone
        del self.app.timezone  # reset cached timezone

        result = Backend(app=self.app)._get_result_meta(None, states.SUCCESS, None, None)
        assert result.get('date_done') == date


class test_ResultSet:

    def test_resultset_repr(self):
        assert repr(self.app.ResultSet(
            [self.app.AsyncResult(t) for t in ['1', '2', '3']]))

    def test_eq_other(self):
        assert self.app.ResultSet([
            self.app.AsyncResult(t) for t in [1, 3, 3]]) != 1
        rs1 = self.app.ResultSet([self.app.AsyncResult(1)])
        rs2 = self.app.ResultSet([self.app.AsyncResult(1)])
        assert rs1 == rs2

    def test_get(self):
        x = self.app.ResultSet([self.app.AsyncResult(t) for t in [1, 2, 3]])