Exemplo n.º 1
0
 def test_firstItemDisplays(self):
   client = FlaskClient(application.app, response_wrapper=FormWrapper)
   page = client.get('/', follow_redirects=True)
   page.form.fields['name'] = 'Asif'
   page.form.fields['age'] = '23'
   page2 = page.form.submit(client, follow_redirects=True)
   assert 'Sound clip #1' in page2.data
Exemplo n.º 2
0
  def test_submittingFirstItemDisplaysSecondItem(self):
    client = FlaskClient(application.app, response_wrapper=FormWrapper)
    page = client.get('/', follow_redirects=True)
    page.form.fields['name'] = 'Asif'
    page.form.fields['age'] = '23'
    page2 = page.form.submit(client, follow_redirects=True)

    page2.form.fields['recog'] = 'yes'
    page2.form.fields['comp'] = 'Tchaikovsky'
    page2.form.fields['comp_conf'] = '5'
    page2.form.fields['piece'] = 'Symphony No. 5'
    page2.form.fields['piece_conf'] = '1'

    page3 = page2.form.submit(client, follow_redirects=True)

    assert 'Sound clip #2' in page3.data
Exemplo n.º 3
0
def test_jurisdictionadmin_start(client: FlaskClient):
    rv = client.get("/auth/jurisdictionadmin/start")
    check_redirect_contains_redirect_uri(rv, "/auth/jurisdictionadmin/callback")
Exemplo n.º 4
0
def test_get_health(client: FlaskClient):
    res = client.get("/health")

    assert 200 == res.status_code
Exemplo n.º 5
0
def test_ballot_manifest_upload(
    client: FlaskClient, election_id: str, jurisdiction_ids: List[str]
):
    set_logged_in_user(client, UserType.JURISDICTION_ADMIN, DEFAULT_JA_EMAIL)
    rv = client.put(
        f"/api/election/{election_id}/jurisdiction/{jurisdiction_ids[0]}/ballot-manifest",
        data={
            "manifest": (
                io.BytesIO(
                    b"Batch Name,Number of Ballots\n" b"1,23\n" b"12,100\n" b"6,0\n"
                ),
                "manifest.csv",
            )
        },
    )
    assert_ok(rv)

    rv = client.get(
        f"/api/election/{election_id}/jurisdiction/{jurisdiction_ids[0]}/ballot-manifest"
    )
    compare_json(
        json.loads(rv.data),
        {
            "file": {"name": "manifest.csv", "uploadedAt": assert_is_date,},
            "processing": {
                "status": ProcessingStatus.READY_TO_PROCESS,
                "startedAt": None,
                "completedAt": None,
                "error": None,
            },
        },
    )

    bgcompute_update_ballot_manifest_file()

    rv = client.get(
        f"/api/election/{election_id}/jurisdiction/{jurisdiction_ids[0]}/ballot-manifest"
    )
    compare_json(
        json.loads(rv.data),
        {
            "file": {"name": "manifest.csv", "uploadedAt": assert_is_date,},
            "processing": {
                "status": ProcessingStatus.PROCESSED,
                "startedAt": assert_is_date,
                "completedAt": assert_is_date,
                "error": None,
            },
        },
    )

    jurisdiction = Jurisdiction.query.get(jurisdiction_ids[0])
    assert jurisdiction.manifest_num_batches == 3
    assert jurisdiction.manifest_num_ballots == 123
    assert len(jurisdiction.batches) == 3
    assert jurisdiction.batches[0].name == "1"
    assert jurisdiction.batches[0].num_ballots == 23
    assert jurisdiction.batches[1].name == "12"
    assert jurisdiction.batches[1].num_ballots == 100
    assert jurisdiction.batches[2].name == "6"
    assert jurisdiction.batches[2].num_ballots == 0
Exemplo n.º 6
0
 def test_get(self, client: FlaskClient):  # noqa
     with client:
         results = client.get("/api/room", follow_redirects=True).get_json()
         expected = RoomSchema(many=True).dump([room(456), room(123)])
         for r in results:
             assert r in expected
Exemplo n.º 7
0
def test_basic(client: FlaskClient):
    """test GET method with no middlewares"""
    resp = client.get('/basic')
    assert resp.status_code == 200
    assert resp.json.get('success')
Exemplo n.º 8
0
def test_get_index(test_app, client: FlaskClient):
    response = client.get('/')
    assert response.status_code == 200
Exemplo n.º 9
0
 def test_homepageDisplays(self):
   client = FlaskClient(application.app, response_wrapper=FormWrapper)
   page = client.get('/')
   assert 'music' in page.data
Exemplo n.º 10
0
def test_create_app(test_client: testing.FlaskClient):
    """ Test app creation
    """
    out: wrappers.Response = test_client.get("/api/")
    assert out.data.decode("utf-8").replace('"', "") == "pong!\n"
Exemplo n.º 11
0
def test_redirects_to_calendar_when_logged_in(client: FlaskClient) -> None:
    client.post('/do_login',
                data=dict(username='******', password='******'))
    response = client.get('/')
    assert response.status_code == 302
    assert response.headers['Location'] == 'http://localhost/sample/'
Exemplo n.º 12
0
def test_audit_boards_list_one(
    client: FlaskClient,
    election_id: str,
    jurisdiction_ids: List[str],
    contest_ids: List[str],
    round_1_id: str,
    snapshot,
):
    set_logged_in_user(client, UserType.JURISDICTION_ADMIN, DEFAULT_JA_EMAIL)
    rv = post_json(
        client,
        f"/api/election/{election_id}/jurisdiction/{jurisdiction_ids[0]}/round/{round_1_id}/audit-board",
        [{"name": "Audit Board #1"}],
    )
    assert_ok(rv)

    rv = client.get(
        f"/api/election/{election_id}/jurisdiction/{jurisdiction_ids[0]}/round/{round_1_id}/audit-board",
    )
    audit_boards = json.loads(rv.data)["auditBoards"]
    snapshot.assert_match(
        [
            {
                "name": audit_board["name"],
                "currentRoundStatus": audit_board["currentRoundStatus"],
            }
            for audit_board in audit_boards
        ]
    )
    assert audit_boards[0]["signedOffAt"] is None

    # Fake auditing some ballots
    audit_board = AuditBoard.query.get(audit_boards[0]["id"])
    for ballot in audit_board.sampled_ballots[:10]:
        audit_ballot(ballot, contest_ids[0], Interpretation.BLANK)
    db_session.commit()

    rv = client.get(
        f"/api/election/{election_id}/jurisdiction/{jurisdiction_ids[0]}/round/{round_1_id}/audit-board",
    )
    audit_boards = json.loads(rv.data)["auditBoards"]
    snapshot.assert_match(
        [
            {
                "name": audit_board["name"],
                "currentRoundStatus": audit_board["currentRoundStatus"],
            }
            for audit_board in audit_boards
        ]
    )
    assert audit_boards[0]["signedOffAt"] is None

    # Finish auditing ballots and sign off
    audit_board = AuditBoard.query.get(audit_boards[0]["id"])
    for ballot in audit_board.sampled_ballots[10:]:
        audit_ballot(ballot, contest_ids[0], Interpretation.BLANK)
    audit_board.signed_off_at = datetime.now(timezone.utc)
    db_session.commit()

    rv = client.get(
        f"/api/election/{election_id}/jurisdiction/{jurisdiction_ids[0]}/round/{round_1_id}/audit-board",
    )
    audit_boards = json.loads(rv.data)["auditBoards"]

    snapshot.assert_match(
        [
            {
                "name": audit_board["name"],
                "currentRoundStatus": audit_board["currentRoundStatus"],
            }
            for audit_board in audit_boards
        ]
    )
    assert_is_date(audit_boards[0]["signedOffAt"])
Exemplo n.º 13
0
def test_audit_boards_sign_off_happy_path(
    client: FlaskClient,
    election_id: str,
    jurisdiction_ids: List[str],
    contest_ids: List[str],
    round_1_id: str,
    audit_board_round_1_ids: List[str],
):
    def run_audit_board_flow(jurisdiction_id: str, audit_board_id: str):
        member_1, member_2 = set_up_audit_board(
            client,
            election_id,
            jurisdiction_id,
            round_1_id,
            contest_ids[0],
            audit_board_id,
        )
        set_logged_in_user(client, UserType.AUDIT_BOARD, audit_board_id)
        rv = post_json(
            client,
            f"/api/election/{election_id}/jurisdiction/{jurisdiction_id}/round/{round_1_id}/audit-board/{audit_board_id}/sign-off",
            {"memberName1": member_1, "memberName2": member_2},
        )
        assert_ok(rv)

    run_audit_board_flow(jurisdiction_ids[0], audit_board_round_1_ids[0])

    # After one audit board signs off, shouldn't end the round yet
    round = Round.query.get(round_1_id)
    assert round.ended_at is None

    run_audit_board_flow(jurisdiction_ids[0], audit_board_round_1_ids[1])

    # After second audit board signs off, shouldn't end the round yet because
    # the other jurisdictions still didn't set up audit boards
    round = Round.query.get(round_1_id)
    assert round.ended_at is None

    # Create an audit board for the other jurisdiction that had some ballots sampled
    email = "*****@*****.**"
    create_jurisdiction_admin(jurisdiction_ids[1], email)
    set_logged_in_user(client, UserType.JURISDICTION_ADMIN, email)
    rv = post_json(
        client,
        f"/api/election/{election_id}/jurisdiction/{jurisdiction_ids[1]}/round/{round_1_id}/audit-board",
        [{"name": "Audit Board #1"}],
    )
    assert_ok(rv)

    rv = client.get(
        f"/api/election/{election_id}/jurisdiction/{jurisdiction_ids[1]}/round/{round_1_id}/audit-board"
    )
    audit_board = json.loads(rv.data)["auditBoards"][0]

    # Create another audit board that doesn't have any ballots assigned. Even
    # though this audit board doesn't sign off, it shouldn't stop the round
    # from being completed.
    audit_board_without_ballots = AuditBoard(
        id=str(uuid.uuid4()),
        jurisdiction_id=jurisdiction_ids[1],
        round_id=round_1_id,
        name="Audit Board Without Ballots",
    )
    db_session.add(audit_board_without_ballots)
    db_session.commit()

    run_audit_board_flow(jurisdiction_ids[1], audit_board["id"])

    # Now the round should be over
    round = Round.query.get(round_1_id)
    assert round.ended_at is not None
    results = (
        RoundContestResult.query.filter_by(round_id=round_1_id)
        .order_by(RoundContestResult.result)
        .all()
    )
    assert len(results) == 5

    contest_1_results = [r for r in results if r.contest_id == contest_ids[0]]
    assert len(contest_1_results) == 2
    assert contest_1_results[0].result == CHOICE_1_VOTES * 3
    assert contest_1_results[1].result == CHOICE_2_VOTES * 3

    contest_2_results = [r for r in results if r.contest_id == contest_ids[1]]
    assert len(contest_2_results) == 3
    # Note: we didn't record any audited ballots for contest 2, so we expect 0s
    # here. But contest 2 has overlapping candidate names as contest 1, so this
    # makes ensures we don't accidentally count votes for a choice for the
    # wrong contest.
    assert contest_2_results[0].result == 0
    assert contest_2_results[1].result == 0
    assert contest_2_results[2].result == 0

    # Check that the risk measurements got calculated
    round_contests = (
        RoundContest.query.filter_by(round_id=round_1_id)
        .join(Contest)
        .filter_by(election_id=election_id)
        .all()
    )
    for round_contest in round_contests:
        assert round_contest.end_p_value is not None
        assert round_contest.is_complete is not None
Exemplo n.º 14
0
def get_runs(client: FlaskClient) -> Response:  # type: ignore
    response: Response = client.get(f"/runs")

    return response
Exemplo n.º 15
0
def test_restrict_access_audit_admin(client: FlaskClient, election_id: str, aa_email):
    set_logged_in_user(client, UserType.AUDIT_ADMIN, aa_email)
    rv = client.get(f"/api/election/{election_id}/test_auth")
    assert rv.status_code == 200
    assert json.loads(rv.data) == election_id
Exemplo n.º 16
0
def test_visiting_nonexistent_dir_fails(test_app, client: FlaskClient):
    resp = client.get("/?path=nonexistent_dir", follow_redirects=True)
    assert b"Directory does not exist." in resp.data
Exemplo n.º 17
0
class fillinTest(unittest.TestCase):

    def setUp(self):
        self.app = app
        self.app.testing = True
        self.client = FlaskClient(self.app, response_wrapper=FormWrapper)

    def tearDown(self):
        pass

    def test_login_form(self):
        response = self.client.get('/login-form')
        response.form.fields['username'] = "******"
        assert 'Missing password' in response.form.submit(self.client).data

        response = self.client.get('/login-form')
        response.form.fields['password'] = "******"
        assert 'Missing username' in response.form.submit(self.client).data

        response = self.client.get('/login-form')
        response.form.fields['username'] = "******"
        response.form.fields['password'] = "******"
        assert 'Welcome test' in response.form.submit(self.client).data

    def test_data_injection(self):
        response = self.client.get('/login-form')
        response.form.fields['password'] = "******"

        inject_data = {'username': '******'}
        response = response.form.submit(self.client, data=inject_data)
        assert 'Welcome test' in response.data

    def test_hidden_field_form(self):
        response = self.client.get('/hidden-field-form')

        response = response.form.submit(self.client)
        assert 'Hidden field received' in response.data

        response = self.client.post('/hidden-field-form')
        assert 'Missing the hidden field' in response.data

    def test_checkbox_form(self):
        response = self.client.get('/checkbox-field-form')

        response = response.form.submit(self.client)
        assert "Checkbox did not check" in response.data

        response.form.fields['checkbox_field'] = True
        response = response.form.submit(self.client)
        assert "Checkbox checked" in response.data

    def test_select_form(self):
        response = self.client.get('/select-field-form')

        response = response.form.submit(self.client)
        assert "select1" in response.data

        response.form.fields['select_field'] = "select2"
        response = response.form.submit(self.client)
        assert "select2" in response.data

    def test_radio_form(self):
        response = self.client.get('/radio-field-form')

        response = response.form.submit(self.client)
        assert "No Radio Value Selected" in response.data

        response.form.fields['radio_field'] = "1"
        response = response.form.submit(self.client)
        assert "Selected 1" in response.data

        response.form.fields['radio_field'] = "0"
        response = response.form.submit(self.client)
        assert "Selected 0" in response.data

    def test_empty_field_form(self):
        response = self.client.get('/empty-field-form')
        response.form.fields['text1'] = 'hi'
        # response.form.fields['text2'] = ''
        response = response.form.submit(self.client)
        assert "No None" in response.data

        response = self.client.get('/empty-field-form')
        response = response.form.submit(self.client)
        assert "No None" in response.data

    def test_links_get(self):
        response = self.client.get('/link')

        self.assertEquals(2, len(response.links()), '2 links are parsed from the source')
        self.assertEquals('link1', response.link('#link1').text)
        self.assertEquals('link2', response.link('.link').text)

    def test_link_click(self):
        response = self.client.get('/link')

        response = response.link("#link1").click(self.client)
        self.assertEquals(200, response.status_code)

    def test_file_form(self):
        response = self.client.get('file-form')
        response.form.fields['text'] = 'text'
        with open("README.rst") as fh:
            response.form.files['file'] = fh
            response = response.form.submit(self.client)
        assert "File submitted" in response.data

    def test_no_file_form(self):
        response = self.client.get('file-form')
        response.form.fields['text'] = 'text'
        response = response.form.submit(self.client)
        assert "File not submitted" in response.data

    def test_bad_file_form(self):
        response = self.client.get('file-form')
        response.form.fields['text'] = 'text'
        response.form.files['file'] = 'not a file type'
        with self.assertRaises(TypeError):
            self.response = response.form.submit(self.client)

    def test_bad_input_form(self):
        response = self.client.get('file-form')
        response.form.fields['text'] = 'text'
        with open("README.rst") as fh, self.assertRaises(ValueError):
            response.form.files['not_file_name'] = fh
            response = response.form.submit(self.client)
Exemplo n.º 18
0
def test_bookmarklet(test_app, client: FlaskClient):
    resp = client.get("/bookmarklet")
    assert resp.status_code == 200
Exemplo n.º 19
0
def test_get_delete_dataobj(test_app, client: FlaskClient, note_fixture):
    response = client.get('/dataobj/delete/1')
    assert response.status_code == 302
Exemplo n.º 20
0
def test_get_dataobj_not_found(test_app, client: FlaskClient):
    response = client.get("/dataobj/1")
    assert response.status_code == 302
def test_error_pages(client: FlaskClient):
    response = client.get("/dasd")
    assert response.status_code == 404
Exemplo n.º 22
0
def test_get_dataobj(test_app, client: FlaskClient, note_fixture):
    response = client.get("/dataobj/1")
    assert response.status_code == 200
Exemplo n.º 23
0
def test_multi_mws_failing(client: FlaskClient):
    """test GET method with multiple middlewares"""
    resp = client.get('/get-with-auth')
    assert resp.status_code == 403
    assert not resp.json.get('success')
Exemplo n.º 24
0
def test_hello_enki_returns_404(client: FlaskClient):
    response = client.get('/api/enki/v1')
    assert response.status_code == 404
Exemplo n.º 25
0
 def test_get(self, client: FlaskClient):  # noqa
     with client:
         result: dict = client.get("/api/room/123").get_json()
         expected = Room(room_id=123)
         assert result["roomId"] == expected.room_id
Exemplo n.º 26
0
def test_hello_enki_root_returns_200_and_expected_message(client: FlaskClient):
    response = client.get('/')
    body = json.loads(response.data)
    print("response data : ", json.loads(response.data))
    assert response.status_code == 200
    assert body['message'] == "Hello, Enki!"
Exemplo n.º 27
0
def test_get_hello_world(client: FlaskClient):
    res = client.get("/hello")

    assert 200 == res.status_code
    assert b'hello world' == res.data
Exemplo n.º 28
0
 def test_get(self, client: FlaskClient):  # noqa
     with client:
         result = client.get(f"/api/{BASE_ROUTE}/123").get_json()
         expected = make_location(id=123)
         print(f"result = ", result)
         assert result["LocationId"] == expected.LocationId
Exemplo n.º 29
0
def test_get(client: FlaskClient):
    result: Response = client.get('/health-check')

    assert result.status_code == 200
Exemplo n.º 30
0
def test_get_new_bookmark(test_app, client: FlaskClient):
    response = client.get('/bookmarks/new')
    assert response.status_code == 200
Exemplo n.º 31
0
def test_auth_me_not_logged_in(client: FlaskClient):
    clear_logged_in_user(client)
    rv = client.get("/api/me")
    assert rv.status_code == 200
    assert json.loads(rv.data) is None
Exemplo n.º 32
0
def test_get_new_note(test_app, client: FlaskClient):
    response = client.get('/notes/new')
    assert response.status_code == 200
Exemplo n.º 33
0
def test_restrict_access_jurisdiction_admin_jurisdiction_not_found(
    client: FlaskClient, election_id: str, ja_email: str
):
    set_logged_in_user(client, UserType.JURISDICTION_ADMIN, ja_email)
    rv = client.get(f"/api/election/{election_id}/jurisdiction/not-a-real-id/test_auth")
    assert rv.status_code == 404
Exemplo n.º 34
0
def test_get_delete_dataobj_not_found(test_app, client: FlaskClient):
    response = client.get('/dataobj/delete/1')
    assert response.status_code == 302
Exemplo n.º 35
0
class fillinTest(unittest.TestCase):

    def setUp(self):
        self.app = app
        self.app.testing = True
        self.client = FlaskClient(self.app, response_wrapper=FormWrapper)

    def tearDown(self):
        pass
    
    def test_login_form(self):
        response = self.client.get('/login-form')
        response.form.fields['username'] = "******"
        assert 'Missing password' in response.form.submit(self.client).data
        
        response = self.client.get('/login-form')
        response.form.fields['password'] = "******"
        assert 'Missing username' in response.form.submit(self.client).data
        
        response = self.client.get('/login-form')
        response.form.fields['username'] = "******"
        response.form.fields['password'] = "******"
        assert 'Welcome test' in response.form.submit(self.client).data
        
    def test_data_injection(self):
        response = self.client.get('/login-form')
        response.form.fields['password'] = "******"
        
        inject_data = {'username': '******'}
        response = response.form.submit(self.client, data=inject_data)
        assert 'Welcome test' in response.data
    
    def test_hidden_field_form(self):
        response = self.client.get('/hidden-field-form')
        
        response = response.form.submit(self.client)
        assert 'Hidden field received' in response.data
        
        response = self.client.post('/hidden-field-form')
        assert 'Missing the hidden field' in response.data

    def test_checkbox_form(self):
        response = self.client.get('/checkbox-field-form')
        
        response = response.form.submit(self.client)
        assert "Checkbox did not check" in response.data
        
        response.form.fields['checkbox_field'] = True
        response = response.form.submit(self.client)
        assert "Checkbox checked" in response.data
        
    def test_links_get(self):
        response = self.client.get('/link')
        
        self.assertEquals(2, len(response.links()), '2 links are parsed from the source')
        self.assertEquals('link1', response.link('#link1').text)
        self.assertEquals('link2', response.link('.link').text)
        
    def test_link_click(self):
        response = self.client.get('/link')
        
        response = response.link("#link1").click(self.client)
        self.assertEquals(200, response.status_code)
Exemplo n.º 36
0
class AuDTestCase(unittest.TestCase):
    def setUp(self):
        prepare_db_for_tests()
        self.app = FlaskClient(app, response_wrapper=FormWrapper)
        self.app.application.config["CSRF_ENABLED"] = False
        self.depute = Depute(test_depute).save()
        self.user = create_user("test", "test")
        self.ctx = app.test_request_context()
        self.ctx.push()

    def login(self):
        return self.app.post(url_for("login"),
                             data={"username": "******", "password": "******"},
                             follow_redirects=True)

    def tearDown(self):
        self.ctx.pop()

    def test_empty_home(self):
        Depute.collection.remove()
        rv = self.app.get(url_for("home"))
        self.assertTrue("Éric Ciotti" not in rv.data)

    def test_deputy_on_home(self):
        rv = self.app.get(url_for("home"))
        self.assertTrue("Éric Ciotti" in rv.data)

    def test_deputy_personnal_page(self):
        rv = self.app.get(url_for("depute", depute=self.depute.slug))
        self.assertTrue("Éric Ciotti" in rv.data)

    def test_link_to_nosdeputes_fr(self):
        rv = self.app.get(url_for("depute", depute=self.depute.slug))
        self.assertTrue("http://www.nosdeputes.fr/eric-ciotti" in rv.data)

    def test_link_to_memopol(self):
        rv = self.app.get(url_for("depute", depute=self.depute.slug))
        self.assertTrue('https://memopol.lqdn.fr/france/assemblee/depute/EricCiotti/' in rv.data)

    def test_link_to_an(self):
        rv = self.app.get(url_for("depute", depute=self.depute.slug))
        self.assertTrue("http://www.assembleenationale.fr/13/tribun/fiches_id/330240.asp" in rv.data)

    def test_display_group(self):
        rv = self.app.get(url_for("depute", depute=self.depute.slug))
        self.assertTrue(self.depute.groupe_sigle.encode("Utf-8") in rv.data)

    def test_login_on_home(self):
        rv = self.app.get(url_for("home"))
        self.assertTrue(url_for("login") in rv.data)

    def test_login_page(self):
        rv = self.app.get(url_for("login"))
        self.assertTrue("Se connecter" in rv.data)
        self.assertTrue("Login" in rv.data)
        self.assertTrue("Mot de passe" in rv.data)

    def test_login_form(self):
        rv = self.app.get(url_for("login"))
        rv.form.fields["username"] = "******"
        rv.form.fields["password"] = "******"
        rv = rv.form.submit(self.app)
        self.assertEqual(rv.status_code, 302)

    def test_login_success(self):
        rv = self.login()
        self.assertTrue("Login success!" in rv.data)
        self.assertTrue("Se déconnecter" in rv.data)


    def test_logout(self):
        rv = self.app.post(url_for("login"),
                           data={"username": "******", "password": "******"},
                           follow_redirects=True)
        self.app.get(url_for("logout"))
        self.assertTrue("Login" in rv.data)

    def test_login_bad_login(self):
        rv = self.app.post(url_for("login"),
                           data={"username": "******", "password": "******"},
                           follow_redirects=True)
        self.assertTrue("This user doesn't exist or the password is wrong" in rv.data)

    def test_login_bad_password(self):
        rv = self.app.post(url_for("login"),
                           data={"username": "******", "password": "******"},
                           follow_redirects=True)
        self.assertTrue("This user doesn't exist or the password is wrong" in rv.data)

    def test_register_on_home(self):
        rv = self.app.get(url_for("home"))
        self.assertTrue(url_for("register") in rv.data)

    def test_register_page(self):
        rv = self.app.get(url_for("register"))
        self.assertTrue("Login" in rv.data)
        self.assertTrue("Mot de passe" in rv.data)
        self.assertTrue("Confirmer le mot de " in rv.data)

    def test_register_form(self):
        rv = self.app.get(url_for("register"))
        rv.form.fields["username"] = "******"
        rv.form.fields["password"] = "******"
        rv.form.fields["confirm_password"] = "******"
        rv = rv.form.submit(self.app)
        self.assertEqual(rv.status_code, 302)

    def test_register_create_user(self):
        before = User.collection.count()
        self.app.post(url_for('register'),
                      data={"username": "******", "password": "******", "confirm_password": "******"},
                      follow_redirects=True)
        self.assertEqual(before + 1, User.collection.count())
        user = User.collection.find_one({"username": "******"})
        self.assertFalse(user is None)
        self.assertTrue(user.test_password("pouet"))

    def test_empty_fields(self):
        rv = self.app.post(url_for('register'),
                      data={"username": "", "password": "", "confirm_password": ""},
                      follow_redirects=True)
        self.assertTrue("This field is required" in rv.data)

    def test_duplicated_user(self):
        rv = self.app.post(url_for('register'),
                      data={"username": "******", "password": "******", "confirm_password": "******"},
                      follow_redirects=True)
        self.assertTrue("Ce pseudonyme est déjà pris." in rv.data)

    def test_password_doesnt_match(self):
        rv = self.app.post(url_for('register'),
                      data={"username": "******", "password": "******", "confirm_password": "******"},
                      follow_redirects=True)
        self.assertTrue("Les mots de passe ne correspondent pas." in rv.data)

    def test_register_login(self):
        rv = self.app.post(url_for('register'),
                      data={"username": "******", "password": "******", "confirm_password": "******"},
                      follow_redirects=True)
        self.assertTrue("Votre compte a correctement été créé." in rv.data)
        self.assertTrue(url_for("logout") in rv.data)

    def test_register_on_login(self):
        rv = self.app.post(url_for('login'))
        self.assertEqual(rv.data.count(url_for('register')), 2)

    def test_follow_show_on_deputy_page(self):
        rv = self.app.get(url_for("depute", depute=self.depute.slug))
        self.assertTrue("Adopter ce député" in rv.data)
        self.assertTrue(url_for("adopter", depute=self.depute.slug) in rv.data)

    def test_follow_not_logged_in(self):
        rv = self.app.get(url_for("adopter", depute=self.depute.slug))
        self.assertEqual(rv.status_code, 302)

    def test_adopt_logged(self):
        self.login()
        rv = self.app.get(url_for("adopter", depute=self.depute.slug))
        self.assertEqual(rv.status_code, 302)

    def test_adopt_is_marked(self):
        self.login()
        rv = self.app.get(url_for("adopter", depute=self.depute.slug), follow_redirects=True)
        self.assertTrue("Se déconnecter" in rv.data)
        self.assertTrue("Adopté" in rv.data)

    def test_no_adopters_on_deputy_page(self):
        rv = self.app.get(url_for("depute", depute=self.depute.slug))
        self.assertTrue("Personne n'a adopté ce député" in rv.data)

    def test_show_deputy_adopters(self):
        self.login()
        self.app.get(url_for("adopter", depute=self.depute.slug), follow_redirects=True)
        rv = self.app.get(url_for("depute", depute=self.depute.slug))
        self.assertTrue("%s" % self.user.username in rv.data)