예제 #1
0
    def test_lookup_id_with_url(self):
        """
        lookup_id should return correct id for correct url or None for wrong url.

        :return: id or None
        """
        codingeverybody_url = "https://www.facebook.com/groups/codingeverybody/"
        codingeverybody_id = "174499879257223"
        self.assertEqual(lookup_id(codingeverybody_url), codingeverybody_id)

        wrong_url = "https://www.google.com"
        self.assertEqual(lookup_id(wrong_url), None)
예제 #2
0
파일: views.py 프로젝트: nerogit/ward
def groups(request):
    """
    Get a group list by HTTP GET Method and enter a group by HTTP POST METHOD

    :param request: request
    :return: render
    """
    if request.method == "GET":
        return render(request, 'archive/group/list.html', {})
    elif request.method == "POST":
        # Get a url and validate the url
        fb_url = request.POST.get("fb_url", None)
        if fb_url is None:
            error = 'Did not exist a url.'
            return JsonResponse({'error': error})

        # Get a group id from the url and validate the group id
        group_id = lookup_id(fb_url)
        if group_id is None:
            error = 'Did not exist the group or enroll the wrong url.'
            return JsonResponse({'error': error})

        # Get group data from graph api and validate the group data
        group_data = fb_request.group(group_id)
        if group_data is None:
            error = 'Did not exist group or privacy group.'
            return JsonResponse({'error': error})

        # Check the group exist
        if Group.objects.filter(id=group_data.get('id')).exists():
            error = 'This group is already exist.'
            return JsonResponse({'error': error})

        # Store the group
        _group = tasks.store_group(group_data)

        if settings.ARCHIVE_GROUP_AUTO_SAVE:
            tasks.store_group_feed.delay(_group.id, get_feed_query(), settings.ARCHIVE_USE_CELERY, True)

        return JsonResponse({'success': 'Success to enroll ' + _group.id})