Esempio n. 1
0
def recheck_poll_flow_data(org_id=None):

    active_orgs = Org.objects.filter(is_active=True)
    if org_id:
        active_orgs = Org.objects.filter(pk=org_id)

    for org in active_orgs:
        update_poll_flow_data(org)

    print "Task: recheck_poll_flow_data done"
Esempio n. 2
0
def recheck_poll_flow_data(org_id=None):

    active_orgs = Org.objects.filter(is_active=True)
    if org_id:
        active_orgs = Org.objects.filter(pk=org_id)

    for org in active_orgs:
        update_poll_flow_data(org)

    logger.info("Task: recheck_poll_flow_data done")
Esempio n. 3
0
def fetch_poll(poll_id):
    try:
        # get our poll
        from .models import Poll
        poll = Poll.objects.get(pk=poll_id)

        # update poll flow_archived
        update_poll_flow_data(poll.org)

        poll.fetch_poll_results()
    except Exception as e:
        logger.exception("Error fetching poll results: %s" % str(e))
Esempio n. 4
0
def fetch_poll(poll_id):
    try:
        # get our poll
        from .models import Poll
        poll = Poll.objects.get(pk=poll_id)

        # update poll flow_archived
        update_poll_flow_data(poll.org)

        poll.fetch_poll_results()
    except Exception as e:
        logger.exception("Error fetching poll results: %s" % str(e))
Esempio n. 5
0
    def test_update_poll_flow_data(self):
        poll = Poll.objects.filter(pk=self.poll.pk).first()
        self.assertFalse(poll.flow_archived)
        self.assertEqual(poll.runs_count, 0)

        with patch("ureport.utils.get_flows") as mock_get_flows:
            mock_get_flows.return_value = dict()

            update_poll_flow_data(self.org)
            poll = Poll.objects.filter(pk=self.poll.pk).first()
            self.assertFalse(poll.flow_archived)
            self.assertEqual(poll.runs_count, 0)

            mock_get_flows.return_value = {"uuid-1": {"uuid": "uuid-1", "archived": True}}

            update_poll_flow_data(self.org)
            poll = Poll.objects.filter(pk=self.poll.pk).first()
            self.assertTrue(poll.flow_archived)
            self.assertEqual(poll.runs_count, 0)

            mock_get_flows.return_value = {"uuid-1": {"uuid": "uuid-1", "archived": True, "runs": 0}}

            update_poll_flow_data(self.org)
            poll = Poll.objects.filter(pk=self.poll.pk).first()
            self.assertTrue(poll.flow_archived)
            self.assertEqual(poll.runs_count, 0)

            mock_get_flows.return_value = {"uuid-1": {"uuid": "uuid-1", "archived": True, "runs": 5}}

            update_poll_flow_data(self.org)
            poll = Poll.objects.filter(pk=self.poll.pk).first()
            self.assertTrue(poll.flow_archived)
            self.assertEqual(poll.flow_uuid, "uuid-1")
            self.assertEqual(poll.runs_count, 5)

            mock_get_flows.return_value = {"uuid-1": {"uuid": "uuid-1", "archived": True, "runs": 0}}

            update_poll_flow_data(self.org)
            poll = Poll.objects.filter(pk=self.poll.pk).first()
            self.assertTrue(poll.flow_archived)
            self.assertEqual(poll.runs_count, 5)

            mock_get_flows.return_value = {"uuid-1": {"uuid": "uuid-1", "archived": False, "runs": 0}}

            update_poll_flow_data(self.org)
            poll = Poll.objects.filter(pk=self.poll.pk).first()
            self.assertFalse(poll.flow_archived)
            self.assertEqual(poll.runs_count, 5)

            mock_get_flows.return_value = {"uuid-1": {"uuid": "uuid-1", "archived": False, "runs": 3}}

            update_poll_flow_data(self.org)
            poll = Poll.objects.filter(pk=self.poll.pk).first()
            self.assertFalse(poll.flow_archived)
            self.assertEqual(poll.runs_count, 3)

            mock_get_flows.return_value = {"uuid-1": {"uuid": "uuid-1", "archived": True, "runs": 2}}

            update_poll_flow_data(self.org)
            poll = Poll.objects.filter(pk=self.poll.pk).first()
            self.assertTrue(poll.flow_archived)
            self.assertEqual(poll.runs_count, 2)

            mock_get_flows.return_value = {"uuid-1": {"uuid": "uuid-1"}}

            update_poll_flow_data(self.org)
            poll = Poll.objects.filter(pk=self.poll.pk).first()
            self.assertFalse(poll.flow_archived)
            self.assertEqual(poll.runs_count, 2)
Esempio n. 6
0
    def test_update_poll_flow_data(self):
        poll = Poll.objects.filter(pk=self.poll.pk).first()
        self.assertFalse(poll.flow_archived)
        self.assertEqual(poll.runs_count, 0)

        with patch("ureport.utils.get_flows") as mock_get_flows:
            mock_get_flows.return_value = dict()

            update_poll_flow_data(self.org)
            poll = Poll.objects.filter(pk=self.poll.pk).first()
            self.assertFalse(poll.flow_archived)
            self.assertEqual(poll.runs_count, 0)

            mock_get_flows.return_value = {'uuid-1': {'uuid': 'uuid-1', 'archived': True}}

            update_poll_flow_data(self.org)
            poll = Poll.objects.filter(pk=self.poll.pk).first()
            self.assertTrue(poll.flow_archived)
            self.assertEqual(poll.runs_count, 0)

            mock_get_flows.return_value = {'uuid-1': {'uuid': 'uuid-1', 'archived': True, 'runs': 0}}

            update_poll_flow_data(self.org)
            poll = Poll.objects.filter(pk=self.poll.pk).first()
            self.assertTrue(poll.flow_archived)
            self.assertEqual(poll.runs_count, 0)

            mock_get_flows.return_value = {'uuid-1': {'uuid': 'uuid-1', 'archived': True, 'runs': 5}}

            update_poll_flow_data(self.org)
            poll = Poll.objects.filter(pk=self.poll.pk).first()
            self.assertTrue(poll.flow_archived)
            self.assertEqual(poll.flow_uuid, 'uuid-1')
            self.assertEqual(poll.runs_count, 5)

            mock_get_flows.return_value = {'uuid-1': {'uuid': 'uuid-1', 'archived': True, 'runs': 0}}

            update_poll_flow_data(self.org)
            poll = Poll.objects.filter(pk=self.poll.pk).first()
            self.assertTrue(poll.flow_archived)
            self.assertEqual(poll.runs_count, 5)

            mock_get_flows.return_value = {'uuid-1': {'uuid': 'uuid-1', 'archived': False, 'runs': 0}}

            update_poll_flow_data(self.org)
            poll = Poll.objects.filter(pk=self.poll.pk).first()
            self.assertFalse(poll.flow_archived)
            self.assertEqual(poll.runs_count, 5)

            mock_get_flows.return_value = {'uuid-1': {'uuid': 'uuid-1', 'archived': False, 'runs': 3}}

            update_poll_flow_data(self.org)
            poll = Poll.objects.filter(pk=self.poll.pk).first()
            self.assertFalse(poll.flow_archived)
            self.assertEqual(poll.runs_count, 3)

            mock_get_flows.return_value = {'uuid-1': {'uuid': 'uuid-1', 'archived': True, 'runs': 2}}

            update_poll_flow_data(self.org)
            poll = Poll.objects.filter(pk=self.poll.pk).first()
            self.assertTrue(poll.flow_archived)
            self.assertEqual(poll.runs_count, 2)

            mock_get_flows.return_value = {'uuid-1': {'uuid': 'uuid-1'}}

            update_poll_flow_data(self.org)
            poll = Poll.objects.filter(pk=self.poll.pk).first()
            self.assertFalse(poll.flow_archived)
            self.assertEqual(poll.runs_count, 2)
Esempio n. 7
0
    def test_update_poll_flow_data(self):
        poll = Poll.objects.filter(pk=self.poll.pk).first()
        self.assertFalse(poll.flow_archived)
        self.assertEqual(poll.runs_count, 0)

        with patch("ureport.utils.get_flows") as mock_get_flows:
            mock_get_flows.return_value = dict()

            update_poll_flow_data(self.org)
            poll = Poll.objects.filter(pk=self.poll.pk).first()
            self.assertFalse(poll.flow_archived)
            self.assertEqual(poll.runs_count, 0)

            mock_get_flows.return_value = {"uuid-1": {"uuid": "uuid-1", "archived": True}}

            update_poll_flow_data(self.org)
            poll = Poll.objects.filter(pk=self.poll.pk).first()
            self.assertTrue(poll.flow_archived)
            self.assertEqual(poll.runs_count, 0)

            mock_get_flows.return_value = {"uuid-1": {"uuid": "uuid-1", "archived": True, "runs": 0}}

            update_poll_flow_data(self.org)
            poll = Poll.objects.filter(pk=self.poll.pk).first()
            self.assertTrue(poll.flow_archived)
            self.assertEqual(poll.runs_count, 0)

            mock_get_flows.return_value = {"uuid-1": {"uuid": "uuid-1", "archived": True, "runs": 5}}

            update_poll_flow_data(self.org)
            poll = Poll.objects.filter(pk=self.poll.pk).first()
            self.assertTrue(poll.flow_archived)
            self.assertEqual(poll.flow_uuid, "uuid-1")
            self.assertEqual(poll.runs_count, 5)

            mock_get_flows.return_value = {"uuid-1": {"uuid": "uuid-1", "archived": True, "runs": 0}}

            update_poll_flow_data(self.org)
            poll = Poll.objects.filter(pk=self.poll.pk).first()
            self.assertTrue(poll.flow_archived)
            self.assertEqual(poll.runs_count, 5)

            mock_get_flows.return_value = {"uuid-1": {"uuid": "uuid-1", "archived": False, "runs": 0}}

            update_poll_flow_data(self.org)
            poll = Poll.objects.filter(pk=self.poll.pk).first()
            self.assertFalse(poll.flow_archived)
            self.assertEqual(poll.runs_count, 5)

            mock_get_flows.return_value = {"uuid-1": {"uuid": "uuid-1", "archived": False, "runs": 3}}

            update_poll_flow_data(self.org)
            poll = Poll.objects.filter(pk=self.poll.pk).first()
            self.assertFalse(poll.flow_archived)
            self.assertEqual(poll.runs_count, 3)

            mock_get_flows.return_value = {"uuid-1": {"uuid": "uuid-1", "archived": True, "runs": 2}}

            update_poll_flow_data(self.org)
            poll = Poll.objects.filter(pk=self.poll.pk).first()
            self.assertTrue(poll.flow_archived)
            self.assertEqual(poll.runs_count, 2)

            mock_get_flows.return_value = {"uuid-1": {"uuid": "uuid-1"}}

            update_poll_flow_data(self.org)
            poll = Poll.objects.filter(pk=self.poll.pk).first()
            self.assertFalse(poll.flow_archived)
            self.assertEqual(poll.runs_count, 2)