예제 #1
0
def flush_profile_queue():
    client = EpiDBClient(settings.EPIDB_API_KEY)
    if hasattr(settings, 'EPIDB_SERVER') and settings.EPIDB_SERVER is not None:
        client.server = settings.EPIDB_SERVER

    total = 0
    total_sent = 0
    total_error = 0

    surveys = models.ProfileSendQueue.objects.order_by('date')
    for survey in surveys:
        date = survey.date
        profile_survey_id = survey.survey_id
        user_id = survey.user_id
        answers = pickle.loads(str(survey.answers))

        try:
            res = client.profile_update(user_id, profile_survey_id,
                                        answers, date)
            survey.set_sent(res['id'])
            total_sent += 1
        except InvalidResponseError, e:
            total_error += 1
        except ResponseError, e:
            total_error += 1
예제 #2
0
def flush_profile_queue():
    client = EpiDBClient(settings.EPIDB_API_KEY)
    if hasattr(settings, 'EPIDB_SERVER') and settings.EPIDB_SERVER is not None:
        client.server = settings.EPIDB_SERVER

    total = 0
    total_sent = 0
    total_error = 0

    surveys = models.ProfileSendQueue.objects.order_by('date')
    for survey in surveys:
        date = survey.date
        profile_survey_id = survey.survey_id
        user_id = survey.user_id
        answers = pickle.loads(str(survey.answers))

        try:
            res = client.profile_update(user_id, profile_survey_id, answers,
                                        date)
            survey.set_sent(res['id'])
            total_sent += 1
        except InvalidResponseError, e:
            total_error += 1
        except ResponseError, e:
            total_error += 1
    def setUp(self):
        self.client = EpiDBClient(config.api_key)

        self.data = {'user_id': config.user_id,
                     'p0000': '0',
                     'p0001': '1',
                     'p0002': '2'}
    def setUp(self):
        self.client = EpiDBClient(config.api_key)
        self.client.server = config.server

        self.answers = {'q0000': '0',
                        'q0001': '1',
                        'q0002': '2'}
class LiveResponseSubmitUnauthorizedTestCase(unittest.TestCase):
    def setUp(self):
        self.client = EpiDBClient(config.api_key_invalid)
        self.client.server = config.server

        self.answers = {'q0000': '0',
                        'q0001': '1',
                        'q0002': '2'}

    def testUnauthorized(self):
        try:
            self.client.response_submit(config.user_id,
                                        config.survey_id,
                                        self.answers)
            self.fail()
        except epidb_client.ResponseError, e:
            self.assertEqual(e.code, 401)
    def setUp(self):
        self.client = EpiDBClient(config.api_key_invalid)
        self.client.server = config.server

        self.data = {'user_id': config.user_id,
                     'p0000': '0',
                     'p0001': '1',
                     'p0002': '2'}
class LiveErrorsTestCase(unittest.TestCase):
    def setUp(self):
        self.client = EpiDBClient(config.api_key)

        self.data = {'user_id': config.user_id,
                     'p0000': '0',
                     'p0001': '1',
                     'p0002': '2'}

    def testInvalidHost(self):
        self.client.server = 'http://localhost.example/'
        try:
            self.client.profile_update(config.user_id,
                                       config.profile_survey_id, 
                                       self.data)
            self.fail()
        except urllib2.URLError, e:
            self.assertEqual(e.reason.errno, 8)
class LiveProfileUpdateUnauthorizedTestCase(unittest.TestCase):
    def setUp(self):
        self.client = EpiDBClient(config.api_key_invalid)
        self.client.server = config.server

        self.data = {'user_id': config.user_id,
                     'p0000': '0',
                     'p0001': '1',
                     'p0002': '2'}

    def testUnauthorized(self):
        try:
            self.client.profile_update(config.user_id, 
                                       config.profile_survey_id, 
                                       self.data)
            self.fail()
        except epidb_client.ResponseError, e:
            self.assertEqual(e.code, 401)
class GGMResponseTestCase(unittest.TestCase):
    def setUp(self):
        self.client = EpiDBClient(config.api_key)
        self.client.server = config.server

        self.answers = {'a20000': '0',
                        'a21000': '2009-12-15',}

    def testSuccess(self):
        result = self.client.response_submit(config.user_id,
                                             'dev-response-nl-0.0',
                                             self.answers)
        self.assertEqual(result['stat'], 'ok')
class LiveResponseSubmitTestCase(unittest.TestCase):
    def setUp(self):
        self.client = EpiDBClient(config.api_key)
        self.client.server = config.server

        self.answers = {'q0000': '0',
                        'q0001': '1',
                        'q0002': '2'}

    def testSuccess(self):
        result = self.client.response_submit(config.user_id,
                                             config.survey_id,
                                             self.answers)
        self.assertEqual(result['stat'], 'ok')
class LiveProfileUpdateTestCase(unittest.TestCase):
    def setUp(self):
        self.client = EpiDBClient(config.api_key)
        self.client.server = config.server

        self.data = {'user_id': config.user_id,
                     'p0000': '0',
                     'p0001': '1',
                     'p0002': '2'}

    def testSuccess(self):
        result = self.client.profile_update(config.user_id, 
                                            config.profile_survey_id, 
                                            self.data)
        self.assertEqual(result['stat'], 'ok')
import config

api_key = config.api_key
user_id = config.user_id
profile_survey_id = config.profile_survey_id
answers = {'birth-place': 'Jakarta',
           'birth-day': '2009-09-09',
           'has-pets': False}

# if you set date to none, the current date and time 
# will be used
#   date = none
date = datetime(2009, 12, 15, 1, 2, 3)

client = EpiDBClient(api_key)
client.server = config.server # Use this if you want to override
                              # the server location
result = client.profile_update(user_id, profile_survey_id, answers, date)

status = result['stat']

print "status:", status

if status == 'ok':
    print "id:", result['id']
else:
    print "error code:", result['code']
    print "       msg:", result['msg']

user_id = config.user_id
survey_id = config.survey_id
answers = {'q1': 1,
           'q2': True,
           'q3': [ 1, 2, 3 ],
           'q4': 'Jakarta',
           'q5': date(2011, 01, 01),
           'q6': datetime(2011, 01, 01, 12, 34, 31),
           }

# If you set date to None, the current date and time 
# will be used
#   date = None
date = datetime(2009, 12, 15, 1, 2, 3)

client = EpiDBClient(api_key)
client.server = config.server # Use this if you want to override
                              # the server location
result = client.response_submit(user_id, survey_id, answers, date)

status = result['stat']

print "status:", status

if status == 'ok':
    print "id:", result['id']
else:
    print "error code:", result['code']
    print "       msg:", result['msg']

    def setUp(self):
        self.client = EpiDBClient(config.api_key)
        self.client.server = config.server

        self.answers = {'a20000': '0',
                        'a21000': '2009-12-15',}