def test_list_autofetches_two_workflows(self):
        user = User.objects.create(username="******", email="*****@*****.**")
        UserProfile.objects.create(user=user, max_fetches_per_day=500)
        workflow = Workflow.create_and_init(
            owner=user, name="W1", last_viewed_at=IsoDate1.replace("Z", "")
        )
        step1 = workflow.tabs.first().steps.create(
            order=0,
            slug="step-1",
            module_id_name="loadurl",
            auto_update_data=True,
            next_update=datetime.datetime.now(),
            update_interval=600,
        )
        workflow2 = Workflow.create_and_init(
            owner=user, name="W2", last_viewed_at=IsoDate2.replace("Z", "")
        )
        step2 = workflow2.tabs.first().steps.create(
            order=0,
            slug="step-1",
            module_id_name="loadurl",
            auto_update_data=True,
            next_update=datetime.datetime.now(),
            update_interval=1200,
        )

        result = list_autofetches_json({"user": user, "session": None})
        self.assertEqual(
            result,
            {
                "maxFetchesPerDay": 500,
                "nFetchesPerDay": 216,
                "autofetches": [
                    {
                        "workflow": {
                            "id": workflow.id,
                            "name": "W1",
                            "createdAt": isoformat(workflow.creation_date),
                            "lastViewedAt": IsoDate1,
                        },
                        "tab": {"slug": "tab-1", "name": "Tab 1"},
                        "step": {"id": step1.id, "fetchInterval": 600, "order": 0},
                    },
                    {
                        "workflow": {
                            "id": workflow2.id,
                            "name": "W2",
                            "createdAt": isoformat(workflow2.creation_date),
                            "lastViewedAt": IsoDate2,
                        },
                        "tab": {"slug": "tab-1", "name": "Tab 1"},
                        "step": {"id": step2.id, "fetchInterval": 1200, "order": 0},
                    },
                ],
            },
        )
    def test_list_autofetches_two_workflows(self):
        user = User.objects.create(username='******', email='*****@*****.**')
        workflow = Workflow.create_and_init(owner=user, name='W1',
                                            last_viewed_at=IsoDate1)
        step1 = workflow.tabs.first().wf_modules.create(
            order=0,
            module_id_name='loadurl',
            auto_update_data=True,
            next_update=timezone.now(),
            update_interval=600,
        )
        workflow2 = Workflow.create_and_init(owner=user, name='W2',
                                             last_viewed_at=IsoDate2)
        step2 = workflow2.tabs.first().wf_modules.create(
            order=0,
            module_id_name='loadurl',
            auto_update_data=True,
            next_update=timezone.now(),
            update_interval=1200,
        )

        result = list_autofetches_json({'user': user, 'session': None})
        self.assertEqual(result, {
            'maxFetchesPerDay': 500,
            'nFetchesPerDay': 216,
            'autofetches': [
                {
                    'workflow': {
                        'id': workflow.id,
                        'name': 'W1',
                        'createdAt': isoformat(workflow.creation_date),
                        'lastViewedAt': IsoDate1,
                    },
                    'tab': {'slug': 'tab-1', 'name': 'Tab 1'},
                    'wfModule': {
                        'id': step1.id,
                        'fetchInterval': 600,
                        'order': 0,
                    },
                },
                {
                    'workflow': {
                        'id': workflow2.id,
                        'name': 'W2',
                        'createdAt': isoformat(workflow2.creation_date),
                        'lastViewedAt': IsoDate2,
                    },
                    'tab': {'slug': 'tab-1', 'name': 'Tab 1'},
                    'wfModule': {
                        'id': step2.id,
                        'fetchInterval': 1200,
                        'order': 0,
                    },
                },
            ],
        })