コード例 #1
0
ファイル: test_functional.py プロジェクト: asifrc/musictest
 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
コード例 #2
0
ファイル: test_functional.py プロジェクト: asifrc/musictest
  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
コード例 #3
0
 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()
コード例 #4
0
ファイル: helpers.py プロジェクト: monkey-data/arlo
def post_json(client: FlaskClient, url: str, obj=None) -> Any:
    return client.post(
        url,
        headers={"Content-Type": "application/json"},
        data=json.dumps(obj) if obj else None,
    )
コード例 #5
0
ファイル: test_functional.py プロジェクト: asifrc/musictest
 def test_homepageDisplays(self):
   client = FlaskClient(application.app, response_wrapper=FormWrapper)
   page = client.get('/')
   assert 'music' in page.data
コード例 #6
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)
コード例 #7
0
    def get_tags(self, client: FlaskClient, token: str = None) -> Response:
        if token is None:
            token = self.get_token(client)

        result = client.get("/api/tags", query_string={"token": token})
        return result
コード例 #8
0
 def test_get(self, client: FlaskClient):  # noqa
     with client:
         result = client.get(f"/api/{BASE_ROUTE}/123").get_json()
         expected = make_customer(id=123)
         print(f"result = ", result)
         assert result["CustomerId"] == expected.CustomerId
コード例 #9
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/"
コード例 #10
0
 def test_todo_of_other_user(self, client: FlaskClient) -> None:
     """
     A 403 is returned when a user attempts to retrieve a Todo item that
     they do not own.
     """
     credentials = {
         "email": "*****@*****.**",
         "password": "******",
     }
     credentials_other = {
         "email": "*****@*****.**",
         "password": "******",
     }
     client.post("/auth/signup", json=credentials)
     client.post("/auth/signup", json=credentials_other)
     result_from_login = client.post("/auth/login", json=credentials)
     result_from_login_other = client.post("/auth/login",
                                           json=credentials_other)
     jwt_token = "Bearer " + result_from_login.get_json()["token"]
     jwt_token_other = ("Bearer " +
                        result_from_login_other.get_json()["token"])
     post_res = client.post(
         "/todo",
         json={"text": "test_text"},
         headers={"Authorization": jwt_token},
     )
     post_res_other = client.post(
         "/todo",
         json={"text": "test_text_other"},
         headers={"Authorization": jwt_token_other},
     )
     obj_id = post_res.get_json()["obj_id"]
     obj_id_other = post_res_other.get_json()["obj_id"]
     res = client.get("/todo/" + obj_id,
                      headers={"Authorization": jwt_token})
     res_other = client.get("/todo/" + obj_id_other,
                            headers={"Authorization": jwt_token_other})
     get_data = res.get_json()
     get_data_other = res_other.get_json()
     assert get_data == "test_text"
     assert get_data_other == "test_text_other"
     wrong_auth_token = client.get("/todo/" + obj_id_other,
                                   headers={"Authorization": jwt_token})
     assert wrong_auth_token.status_code == 403
     patch_result = client.patch(
         "/todo/" + obj_id,
         json={"text": "test_text_edited"},
         headers={"Authorization": jwt_token_other},
     )
     assert patch_result.status_code == 403
コード例 #11
0
ファイル: test_api.py プロジェクト: rgiordani/archivy
def test_updating_inexistent_dataobj_returns(test_app, client: FlaskClient):
    resp = client.put("/api/dataobjs/1", json={"content": "test"})

    assert resp.status_code == 404
コード例 #12
0
ファイル: test_events.py プロジェクト: MoAlaaElden/eNMS
def test_netmiko_napalm_config(user_client: FlaskClient) -> None:
    create_from_file(user_client, "europe.xls")
    user_client.post("/update/task", data=instant_task)
    assert len(fetch_all("Task")) == 3
    user_client.post("/update/task", data=scheduled_task)
    assert len(fetch_all("Task")) == 4
コード例 #13
0
 def test_does_not_exist(self, client: FlaskClient, jwt_token: str) -> None:
     """
     A 404 error is returned when getting a Todo item that does not exist
     """
     res = client.get("/todo/1", headers={"Authorization": jwt_token})
     assert res.status_code == 404
コード例 #14
0
    def test_add_word(self, client: FlaskClient):

        rv = client.post("/api/oneword/", json={"content": "测试添加的数据"})
        assert rv.status_code == 200
コード例 #15
0
    def test_get_word_by_id(self, client: FlaskClient):

        rv = client.get("api/oneword/1/")
        assert rv.status_code == 200
        body: str = rv.json["data"]
        assert body != None
コード例 #16
0
 def edit_tag(self, client: FlaskClient, tag_id: int, data: dict,
              token: str) -> Response:
     result = client.put(f"/api/tags/{tag_id}",
                         query_string={"token": token},
                         data=json.dumps(data))
     return result
コード例 #17
0
def post_run_id_cancel(
        client: FlaskClient,  # type: ignore
        run_id: str) -> Response:
    response: Response = client.post(f"/runs/{run_id}/cancel")

    return response
コード例 #18
0
def test_status(test_client: FlaskClient, admin_headers: dict):
    response = test_client.get('/api/admin/v1/users/', headers=admin_headers)
    actual = response.status_code
    expected = 200

    assert actual == expected
コード例 #19
0
ファイル: tests.py プロジェクト: jarus/flask-fillin
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)
コード例 #20
0
def test_get(test_client: FlaskClient, admin_headers: dict, admin: User):
    response = test_client.get('/api/admin/v1/users/', headers=admin_headers)
    actual = response.json['result'][0]
    expected = UserClientSchema().dump(admin)

    assert actual == expected
def get_affairs(client: FlaskClient) -> Response:
    return client.get(BASE_PATH_AFFAIRS)
コード例 #22
0
def test_status_without_auth(test_client: FlaskClient):
    response = test_client.get('/api/admin/v1/users/')
    actual = response.status_code
    expected = 401

    assert actual == expected
コード例 #23
0
def test_upload_standardized_contests(client: FlaskClient, election_id: str,
                                      jurisdiction_ids: List[str]):
    rv = client.put(
        f"/api/election/{election_id}/standardized-contests/file",
        data={
            "standardized-contests": (
                io.BytesIO(b"Contest Name,Jurisdictions\n"
                           b"Contest 1,all\n"
                           b'Contest 2,"J1, J3"\n'
                           b"Contest 3,J2 \n"),
                "standardized-contests.csv",
            )
        },
    )
    assert_ok(rv)

    rv = client.get(f"/api/election/{election_id}/standardized-contests/file")
    compare_json(
        json.loads(rv.data),
        {
            "file": {
                "name": "standardized-contests.csv",
                "uploadedAt": assert_is_date,
            },
            "processing": {
                "status": ProcessingStatus.READY_TO_PROCESS,
                "startedAt": None,
                "completedAt": None,
                "error": None,
            },
        },
    )

    bgcompute_update_standardized_contests_file()

    rv = client.get(f"/api/election/{election_id}/standardized-contests/file")
    compare_json(
        json.loads(rv.data),
        {
            "file": {
                "name": "standardized-contests.csv",
                "uploadedAt": assert_is_date,
            },
            "processing": {
                "status": ProcessingStatus.PROCESSED,
                "startedAt": assert_is_date,
                "completedAt": assert_is_date,
                "error": None,
            },
        },
    )

    rv = client.get(f"/api/election/{election_id}/standardized-contests")
    assert json.loads(rv.data) == [
        {
            "name": "Contest 1",
            "jurisdictionIds": jurisdiction_ids
        },
        {
            "name": "Contest 2",
            "jurisdictionIds": [jurisdiction_ids[0], jurisdiction_ids[2]],
        },
        {
            "name": "Contest 3",
            "jurisdictionIds": [jurisdiction_ids[1]]
        },
    ]
コード例 #24
0
ファイル: client.py プロジェクト: 2doi/freight
 def open(self, *args, **kwargs):
     kwargs.setdefault('headers', {})
     kwargs['headers'].setdefault(
         'Authorization', 'Key {}'.format(current_app.config['API_KEY'])
     )
     return FlaskClient.open(self, *args, **kwargs)
コード例 #25
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"/election/{election_id}/jurisdiction/{jurisdiction_ids[0]}/ballot-manifest",
        data={
            "manifest": (
                io.BytesIO(
                    b"Batch Name,Number of Ballots,Storage Location,Tabulator\n"
                    b"1,23,Bin 2,Tabulator 1\n"
                    b"12,100,Bin 3,Tabulator 2\n"
                    b"6,0,,\n"
                ),
                "manifest.csv",
            )
        },
    )
    assert_ok(rv)

    rv = client.get(
        f"/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"/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[0].storage_location == "Bin 2"
    assert jurisdiction.batches[0].tabulator == "Tabulator 1"
    assert jurisdiction.batches[1].name == "12"
    assert jurisdiction.batches[1].num_ballots == 100
    assert jurisdiction.batches[1].storage_location == "Bin 3"
    assert jurisdiction.batches[1].tabulator == "Tabulator 2"
    assert jurisdiction.batches[2].name == "6"
    assert jurisdiction.batches[2].num_ballots == 0
    assert jurisdiction.batches[2].storage_location is None
    assert jurisdiction.batches[2].tabulator is None
コード例 #26
0
 def test_get(self, client: FlaskClient):  # noqa
     with client:
         result = client.get(f"/api/{BASE_ROUTE}/123").get_json()
         expected = make_personlocation(id=123)
         print(f"result = ", result)
         assert result["PeoplePersonId"] == expected.PeoplePersonId
コード例 #27
0
ファイル: test_api.py プロジェクト: tynen/archivy
def test_put_bookmark(test_app, client: FlaskClient):
    response: Flask.response_class = client.put("/api/bookmarks/1")
    assert response.status_code == 501
コード例 #28
0
 def get_layers(self, client: FlaskClient, token: str):
     return client.get("/api/layers", query_string={"token": token})
コード例 #29
0
 def open(self, *args, **kwargs):
     kwargs.setdefault("headers", {})
     kwargs["headers"].setdefault("Authorization",
                                  f"Key {current_app.config['API_KEY']}")
     return FlaskClient.open(self, *args, **kwargs)
コード例 #30
0
ファイル: test_api.py プロジェクト: tynen/archivy
def test_unlogged_in_api_fails(test_app, client: FlaskClient):
    client.delete("/logout")
    resp = client.get("/api/dataobjs")
    assert resp.status_code == 302
コード例 #31
0
 def test_delete(self, client: FlaskClient):  # noqa
     with client:
         result = client.delete(f"/api/{BASE_ROUTE}/123").get_json()
         expected = dict(status="Success", id=123)
         assert result == expected
コード例 #32
0
ファイル: test_api.py プロジェクト: tynen/archivy
def test_get_dataobj(test_app, client: FlaskClient, bookmark_fixture):
    response: Flask.response_class = client.get("/api/dataobjs/1")
    assert response.status_code == 200
    assert response.json["title"] == "Example"
    assert response.json["dataobj_id"] == 1
    assert response.json["content"].startswith("Lorem ipsum")
コード例 #33
0
ファイル: helpers.py プロジェクト: monkey-data/arlo
def put_json(client: FlaskClient, url: str, obj) -> Any:
    return client.put(url,
                      headers={"Content-Type": "application/json"},
                      data=json.dumps(obj))
コード例 #34
0
ファイル: test_api.py プロジェクト: tynen/archivy
def test_delete_bookmark(test_app, client: FlaskClient, bookmark_fixture):
    response: Flask.response_class = client.delete("/api/dataobjs/1")
    assert response.status_code == 204
コード例 #35
0
ファイル: test_api.py プロジェクト: tynen/archivy
def test_get_bookmarks_with_empty_db(test_app, client: FlaskClient):
    response: Flask.response_class = client.get("/api/dataobjs")
    assert response.status_code == 200
    assert response.json == []
コード例 #36
0
ファイル: test_api.py プロジェクト: tynen/archivy
def test_bookmark_not_found(test_app, client: FlaskClient):
    response: Flask.response_class = client.get("/api/dataobjs/1")
    assert response.status_code == 404
コード例 #37
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)
def post_new_affair(client: FlaskClient, xml_string) -> Response:
    return client.post(BASE_PATH_ECHANGES,
                       data=xml_string,
                       headers={'Content-Type': "text/xml"})
コード例 #39
0
ファイル: tests.py プロジェクト: jarus/flask-fillin
 def setUp(self):
     self.app = app
     self.app.testing = True
     self.client = FlaskClient(self.app, response_wrapper=FormWrapper)
コード例 #40
0
ファイル: fixtures.py プロジェクト: abilian/abilian-core
def login_admin(admin_user: User, client: FlaskClient) -> User:
    with client.session_transaction() as session:
        session["user_id"] = admin_user.id

    return admin_user