コード例 #1
0
ファイル: views.py プロジェクト: slok/dwarf
def index(request):

    if request.method == 'POST':
        form = URLForm(request.POST)
        if form.is_valid():
            try:
                result = create_token.delay(form.cleaned_data['url'])
                token = result.get()
                messages.success(request, 'New token {0} created'.format(token))
            except:
                raise Http404

    form = URLForm()

    # Get links
    try:
        links = ShortLink.findall()
        total_links = ShortLink.get_counter()
    except ShortLinkNotFoundError:
        total_links = 0
        links = ()

    data = {
        'my_form': form,
        'total_links': total_links,
        'links': links
    }

    return render_to_response('simple/index.html',
                            data,
                            context_instance=RequestContext(request))
コード例 #2
0
ファイル: tests.py プロジェクト: slok/dwarf
    def test_getall_shortlink(self):
        times = random.randrange(1, 20)

        for i in range(times):
            url = "xlarrakoetxea{0}.org".format(i)
            sl = ShortLink(url=url)
            sl.save()

        sls = ShortLink.findall()
        self.assertEquals(times, len(sls))
コード例 #3
0
ファイル: tests.py プロジェクト: slok/dwarf
    def test_shortlink_notification_store(self):
        #with three we have enought to test
        sls = ShortLink.findall()[:3]
        user = User.objects.get(id=1)

        a_len = len(sls)

        for i in sls:
            notif = ShortLinkNotification(short_link=i, user=user)
            time.sleep(1)  # We need notification order
            notif.save()

        r = get_redis_connection()
        res = r.zrange(
            Notification.STORE_KEY_UNREAD_FORMAT.format(user.id), 0, -1)

        self.assertEquals(a_len, len(res))

        for i in range(len(res)):
            before = sls[i]
            after = json.loads(res[i])

            self.assertEquals(before.token, after['token'])