Exemple #1
0
    def test_no_need_for_sync(self, fetch, tq):
        (fetch.expects_call().returns_fake().has_attr(status_code=200,
                                                      content=XML))
        sync = UserSync()
        sync.last_sync = datetime(2012, 12, 2, 0, 55, 16)  # last sync exact
        sync.put()

        self.client.post(self.url, HTTP_X_APPENGINE_CRON='true')
    def test_no_need_for_sync(self, fetch, tq):
        (fetch.expects_call().returns_fake()
                             .has_attr(status_code=200,
                                       content=XML))
        sync = UserSync()
        sync.last_sync = datetime(2012, 12, 2, 0, 55, 16)  # last sync exact
        sync.put()

        self.client.post(self.url, HTTP_X_APPENGINE_CRON='true')
    def test_sync(self, fetch, tq):
        (fetch.expects_call().returns_fake()
                             .has_attr(status_code=200,
                                       content=XML))

        def user_data(data):
            user = json.loads(data['user'])
            eq_(user['name_first'], 'Ivan')
            eq_(user['name_last'], u'Krsti\u0107')
            eq_(user['member_id'], 1)
            eq_(user['nick'], u'DJ Krsti\u0107')
            eq_(user['email'], '*****@*****.**')
            return True

        (tq.expects('add')
           .with_args(
               url=reverse('auth.tasks.sync_user'),
               params=arg.passes_test(user_data),
           ))

        res = self.client.post(self.url,
                               HTTP_X_APPENGINE_CRON='true')
        eq_(res.status_code, 200)
        eq_(UserSync.all()[0].last_sync.timetuple()[0:3],
            date(2012, 12, 2).timetuple()[0:3])
Exemple #4
0
def sync_users(request):
    authstr = 'Basic %s' % base64.b64encode('%s:%s' %
        (dbconfig['chirpradio.member_api.user'],
         dbconfig['chirpradio.member_api.password']))
    resp = urlfetch.fetch(dbconfig['chirpradio.member_api.url'],
                          headers={'Authorization': authstr})
    if resp.status_code != 200:
        log.error(resp.content)
        raise ValueError('live site XML returned %s' % resp.status_code)
    root = ET.fromstring(resp.content)

    ts_parts = ts.match(root.find('last_updated').text)
    ts_parts = [int(x) for x in ts_parts.groups()]
    last_update = datetime(*ts_parts)
    log.info('chirpradio data last updated: %s' % last_update)

    try:
        sync = UserSync.all()[0]
        last_sync = sync.last_sync
    except IndexError:
        sync = UserSync()
        # Set to a random date in the past to force a new sync.
        last_sync = datetime(2012, 1, 1)
    if last_sync >= last_update:
        log.info('No need for sync')
        return

    stats = {'synced': 0, 'deactivated': 0}

    for vol in root.findall('current_volunteers/volunteer'):
        user = {'name_first': vol.find('name/first').text,
                'name_last': vol.find('name/last').text,
                'nick': vol.find('name/nick').text,
                'member_id': int(vol.find('member_id').text),
                # The email must be lower case otherwise reset-password
                # and other features won't work.
                'email': vol.find('email').text.lower()}
        taskqueue.add(url=reverse('auth.tasks.sync_user'),
                      params={'user': json.dumps(user)})
        stats['synced'] += 1

    for vol in root.findall('suspended_volunteers/volunteer'):
        taskqueue.add(url=reverse('auth.tasks.deactivate_user'),
                      params={'external_id': vol.find('member_id').text})
        stats['deactivated'] += 1

    sync.last_sync = last_update
    sync.put()
    log.info('Sync finished. Sychronized: %(synced)s; '
             'deactivated: %(deactivated)s' % stats)
Exemple #5
0
    def test_sync(self, fetch, tq):
        (fetch.expects_call().returns_fake().has_attr(status_code=200,
                                                      content=XML))

        def user_data(data):
            user = json.loads(data['user'])
            eq_(user['name_first'], 'Ivan')
            eq_(user['name_last'], u'Krsti\u0107')
            eq_(user['member_id'], 1)
            eq_(user['nick'], u'DJ Krsti\u0107')
            eq_(user['email'], '*****@*****.**')
            return True

        (tq.expects('add').with_args(
            url=reverse('auth.tasks.sync_user'),
            params=arg.passes_test(user_data),
        ))

        res = self.client.post(self.url, HTTP_X_APPENGINE_CRON='true')
        eq_(res.status_code, 200)
        eq_(UserSync.all()[0].last_sync.timetuple()[0:3],
            date(2012, 12, 2).timetuple()[0:3])
 def tearDown(self):
     for ob in UserSync.all():
         ob.delete()
Exemple #7
0
 def tearDown(self):
     for ob in UserSync.all():
         ob.delete()