Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Commit

Permalink
Start a basic test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
chadwhitacre committed May 11, 2016
1 parent eddad56 commit 6b30b0d
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 6 deletions.
4 changes: 2 additions & 2 deletions gratipay/models/country.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ class Country(Model):
typname = 'countries'

@classmethod
def from_code2(cls, code2):
return cls.db.one("SELECT countries.*::countries FROM countries WHERE code2=%s", (code2,))
def from_code(cls, code):
return cls.db.one("SELECT countries.*::countries FROM countries WHERE code=%s", (code,))
41 changes: 41 additions & 0 deletions tests/py/test_identity_pages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from gratipay.testing import Harness


class Tests(Harness):

def setUp(self):
self.alice = self.make_participant('alice', claimed_time='now', is_admin=True)
self.bob = self.make_participant('bob', claimed_time='now')


# il - identities listing

def test_il_is_403_for_anon(self):
assert self.client.GxT('/~bob/identities/').code == 403

def test_il_is_403_for_non_admin(self):
assert self.client.GxT('/~bob/identities/').code == 403

def test_il_is_200_for_self(self):
assert self.client.GET('/~bob/identities/', auth_as='alice').code == 200

def test_il_is_200_for_admin(self):
assert self.client.GET('/~bob/identities/', auth_as='alice').code == 200


# ip - identity page

def test_ip_is_403_for_anon(self):
assert self.client.GxT('/~bob/identities/TT').code == 403

def test_ip_is_403_for_non_admin(self):
assert self.client.GxT('/~bob/identities/TT').code == 403

def test_ip_is_200_for_self(self):
assert self.client.GET('/~bob/identities/TT', auth_as='alice').code == 200

def test_ip_is_200_for_admin(self):
assert self.client.GET('/~bob/identities/TT', auth_as='alice').code == 200

def test_ip_(self):
pass
8 changes: 4 additions & 4 deletions www/~/%username/identities/%country.spt
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ participant = get_participant(state, restrict=True)
country = request.path['country']
if country not in locale.countries:
raise Response(404)
country = Country.from_code2(country)
title = locale.countries[country.code2]
country = Country.from_code(country)
title = locale.countries[country.code]

# load identity & info
identity = None
info = {}
identities = participant.list_identity_metadata()
nidentities = len(identities)
for _identity in identities:
if _identity.country.code2 == country.code2:
if _identity.country.code == country.code:
identity = _identity
info = participant.retrieve_identity_info(_identity.country.id)
break
Expand Down Expand Up @@ -50,7 +50,7 @@ if request.method == 'POST':
[---] text/html
{% extends "templates/profile.html" %}
{% block content %}
<img class="flag {{ country.code2 }}"
<img class="flag {{ country.code }}"
src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR4nGP6zwAAAgcBApocMXEAAAAASUVORK5CYII=">
<div class="long-form">
<form autocomplete="off" action="" method="POST">
Expand Down

0 comments on commit 6b30b0d

Please sign in to comment.