Example #1
0
 def test_post_request_fails_without_authentication(self, venue, client):
     venue = VenueFactory.build()
     data = venue_schema.dump(venue)
     response = client.post("/venues",
                            data=json.dumps(data),
                            content_type="application/json")
     assert response.status == "401 UNAUTHORIZED"
Example #2
0
    def test_post_request_creates_venue(self, client, user):
        venue = VenueFactory.build()
        sent = venue_schema.dump(venue)
        del sent["id"]
        response = client.post(
            "/venues",
            data=json.dumps(sent),
            content_type="application/json",
            headers=create_token_auth_header(user.get_token()),
        )

        assert response.status == "201 CREATED"

        recv = response.get_json()

        assert recv is not None
        assert "id" in recv

        venue = Venue.query.get(recv["id"])

        assert venue is not None
        assert venue.id == recv["id"]
        assert venue.name == recv["name"]
        assert venue.name == sent["name"]
        assert venue.user.id == user.id
Example #3
0
    def test_get_request_returns_venue(self, venue, client):
        response = client.get(
            "/venues/{id}".format(id=venue.id),
            headers=create_token_auth_header(venue.user.get_token()),
        )

        assert response.status == "200 OK"
        assert response.get_json() == venue_schema.dump(venue)
Example #4
0
    def test_get_request_succeeds_for_venue_of_another_user_if_admin(
            self, client, venue, admin):
        response = client.get(
            "/venues/{id}".format(id=venue.id),
            headers=create_token_auth_header(admin.get_token()),
        )

        assert response.status == "200 OK"
        assert response.get_json() == venue_schema.dump(venue)
Example #5
0
 def test_post_request_fails_if_name_is_invalid(self, user, client):
     venue = VenueFactory.build(name="")
     data = venue_schema.dump(venue)
     response = client.post(
         "/venues",
         data=json.dumps(data),
         content_type="application/json",
         headers=create_token_auth_header(user.get_token()),
     )
     assert response.status == "422 UNPROCESSABLE ENTITY"
     assert "name" in response.get_json()["details"]
Example #6
0
    def test_put_request_succeeds_for_venue_of_another_user_if_admin(
            self, client, venue, admin):
        data = {"name": "john"}
        response = client.put(
            "/venues/{id}".format(id=venue.id),
            data=json.dumps(data),
            content_type="application/json",
            headers=create_token_auth_header(admin.get_token()),
        )

        assert response.status == "200 OK"
        assert response.get_json() == venue_schema.dump(venue)
Example #7
0
    def test_put_request_modifies_name(self, client, venue):
        original = venue_schema.dump(venue)
        data = {"name": "john"}
        response = client.put(
            "/venues/{id}".format(id=venue.id),
            data=json.dumps(data),
            content_type="application/json",
            headers=create_token_auth_header(venue.user.get_token()),
        )

        assert response.status == "200 OK"
        assert venue.id == original["id"]
        assert venue.name == data["name"]
Example #8
0
 def test_post_request_fails_if_name_exists(self, venue, client):
     name, user = venue.name, venue.user
     venue = VenueFactory.build(name=name)
     data = venue_schema.dump(venue)
     del data["id"]
     response = client.post(
         "/venues",
         data=json.dumps(data),
         content_type="application/json",
         headers=create_token_auth_header(user.get_token()),
     )
     assert response.status == "400 BAD REQUEST"
     assert "name" in response.get_json()["details"]