Skip to content

Commit

Permalink
Merge 429ef77 into 9f5674f
Browse files Browse the repository at this point in the history
  • Loading branch information
seanh committed Aug 5, 2015
2 parents 9f5674f + 429ef77 commit f25481b
Show file tree
Hide file tree
Showing 9 changed files with 490 additions and 54 deletions.
7 changes: 7 additions & 0 deletions h/groups/logic.py
@@ -0,0 +1,7 @@
from h import hashids


def url_for_group(request, group):
"""Return the URL for the given group's page."""
hashid = hashids.encode(request, "h.groups", number=group.id)
return request.route_url('group_read', hashid=hashid, slug=group.slug)
21 changes: 21 additions & 0 deletions h/groups/templates/join.html.jinja2
@@ -0,0 +1,21 @@
{% extends "h:templates/layouts/base.html.jinja2" %}

{% block page_title %}{{ group.name }}{% endblock page_title %}

{% block styles %}
{% assets "app_css" %}
<link rel="stylesheet" href="{{ ASSET_URL }}">
{% endassets %}
{% endblock %}

{% block content %}
<div class="content paper">
{% include "h:templates/includes/header.html.jinja2" %}
This is group {{ group.name }}.
<form method="POST">
<button type="submit">
Join this group
</button>
</form>
</div>
{% endblock content %}
19 changes: 19 additions & 0 deletions h/groups/templates/login_to_join.html.jinja2
@@ -0,0 +1,19 @@
{% extends "h:templates/layouts/base.html.jinja2" %}

{% block page_title %}{{ group.name }}{% endblock page_title %}

{% block styles %}
{% assets "app_css" %}
<link rel="stylesheet" href="{{ ASSET_URL }}">
{% endassets %}
{% endblock %}

{% block content %}
<div class="content paper">
{% include "h:templates/includes/header.html.jinja2" %}
This is group {{ group.name }}.
<a href="{{ request.route_url('login') }}" target="_blank">
Login to join this group.
</a>
</div>
{% endblock content %}
8 changes: 8 additions & 0 deletions h/groups/templates/read.html.jinja2
Expand Up @@ -10,7 +10,15 @@

{% block content %}
<div class="content paper">
{% for message in request.session.pop_flash('success') %}
{{ message }}
{% endfor %}

{% include "h:templates/includes/header.html.jinja2" %}

This is group {{ group.name }}.
You're a member of this group.
You can invite other people to join this group by sending them the link
to this page: {{ group_url }}
</div>
{% endblock content %}
31 changes: 31 additions & 0 deletions h/groups/test/logic_test.py
@@ -0,0 +1,31 @@
import mock

from h.groups import logic


@mock.patch('h.groups.logic.hashids')
def test_url_for_group_encodes_groupid(hashids):
"""It should encode the groupid to get the hashid.
And then pass the hashid to route_url().
"""
hashids.encode.return_value = mock.sentinel.hashid
request = mock.Mock()
group = mock.Mock()

logic.url_for_group(request, group)

assert hashids.encode.call_args[1]['number'] == group.id
assert request.route_url.call_args[1]['hashid'] == mock.sentinel.hashid


@mock.patch('h.groups.logic.hashids')
def test_url_for_group_returns_url(_):
"""It should return the URL from request.route_url()."""
request = mock.Mock()
request.route_url.return_value = mock.sentinel.group_url

url = logic.url_for_group(request, mock.Mock())

assert url == mock.sentinel.group_url

0 comments on commit f25481b

Please sign in to comment.