Beispiel #1
0
    def test_get(self, client):
        '''
        Tests the GET method. Checks that the response status code is 200, and
        then checks that all of the expected attributes and controls are
        present, and the controls work. Also checks that all of the items from
        the DB popluation are present, and their controls.
        '''

        # Invalid route
        resp = client.get(self.resource_URL(user="******"))
        assert resp.status_code == 404
        # Valid route
        resp = client.get(self.resource_URL(user="******"))
        assert resp.status_code == 200
        body = json.loads(resp.data)
        _check_namespace(client, body)
        _check_control_get_method("self", client, body)
        _check_control_get_method("cyequ:owner", client, body)
        _check_control_post_method("cyequ:add-equipment", client, body,
                                   _get_equipment_json())
        assert len(body["items"]) == 2
        assert body["items"][0]["name"] == "Polkuaura"
        assert body["items"][1]["name"] == "Kisarassi"
        assert body["items"][0]["category"] == "Mountain Bike"
        assert body["items"][1]["category"] == "Road Bike"
        assert body["items"][0]["date_added"] == "2019-11-21T11:20:30"
        assert body["items"][1]["date_added"] == "2019-11-21T11:20:30"
        assert body["items"][0]["date_retired"] is None
        assert body["items"][1]["date_retired"] == "2019-12-21T11:20:30"
        for item in body["items"]:
            _check_control_get_method("self", client, item)
            _check_profile("profile", client, item, "equipment-profile")
Beispiel #2
0
    def test_get(self, client):
        '''
        Tests the GET method. Checks that the response status code is 200, and
        then checks that all of the expected attributes and controls are
        present, and the controls work.
        '''

        # Invalid route
        resp = client.get(self.resource_URL(user="******"))
        assert resp.status_code == 404
        body = json.loads(resp.data)
        assert body["@error"]["@message"] == "Not found"
        assert str(body["@error"]["@messages"]) == "[\'No user was " \
                                                   "found with URI {}\']" \
                                                   .format("Jaana1")
        _check_profile("profile", client, body, "error-profile")
        # Valid route ./Joonas/
        resp = client.get(self.resource_URL(user="******"))
        assert resp.status_code == 200
        body = json.loads(resp.data)
        assert body["name"] == "Joonas"
        _check_namespace(client, body)
        _check_control_get_method("self", client, body)
        _check_profile("profile", client, body, "user-profile")
        _check_control_get_method("collection", client, body)
        _check_control_put_method("edit", client, body, _get_user_json())
        _check_control_get_method("cyequ:equipment-owned", client, body)
Beispiel #3
0
    def test_get(self, client):
        '''
        Tests the GET method. Checks that the response status code is 200, and
        then checks that all of the expected attributes and controls are
        present, and the controls work.
        '''

        # Invalid routes
        resp = client.get(self.resource_URL(user="******"))
        assert resp.status_code == 404
        body = json.loads(resp.data)
        assert body["@error"]["@message"] == "Not found"
        assert str(body["@error"]["@messages"]) == "[\'No user was " \
                                                   "found with URI {}\']" \
                                                   .format("Jaana1")
        resp = client.get(self.resource_URL(equipment="Kolmipyörä"))
        body = json.loads(resp.data)
        assert resp.status_code == 404
        assert body["@error"]["@message"] == "Not found"
        assert str(body["@error"]["@messages"]) == "[\'No equipment was " \
                                                   "found with URI {}\']" \
                                                   .format("Kolmipyörä1")
        resp = client.get(self.resource_URL(component="Soittokello"))
        body = json.loads(resp.data)
        assert body["@error"]["@message"] == "Not found"
        assert str(body["@error"]["@messages"]) == "[\'No component was " \
                                                   "found with URI {}\']" \
                                                   .format("Soittokello1")
        assert resp.status_code == 404
        # Test valid route
        resp = client.get(self.resource_URL())
        assert resp.status_code == 200
        # Test valid content
        body = json.loads(resp.data)
        assert body["name"] == "Hissitolppa"
        assert body["category"] == "Seat Post"
        assert body["brand"] == "RockShox"
        assert body["model"] == "Reverb B1"
        assert body["date_added"] == "2019-11-21T11:20:30"
        assert body["date_retired"] == "9999-12-31T23:59:59"
        assert body["equipment"] == "Polkuaura"
        # Test controls
        _check_namespace(client, body)
        _check_control_get_method("cyequ:users-all", client, body)
        _check_control_get_method("self", client, body)
        _check_control_get_method("up", client, body)
        _check_profile("profile", client, body, "component-profile")
        _check_control_put_method("edit", client, body, _get_component_json())
        # Get new body for DELETE control test after PUT
        resp = client.get(
            self.resource_URL(component="Takatalvikiekko", c_id=2))
        body = json.loads(resp.data)
        _check_control_delete_method("cyequ:delete", client, body)
Beispiel #4
0
    def test_get(self, client):
        '''
        Tests the GET method. Checks that the response status code is 200, and
        then checks that all of the expected attributes and controls are
        present, and the controls work. Also checks that all of the items from
        the DB popluation are present, and their controls.
        '''

        # Invalid routes
        resp = client.get(self.resource_URL(user="******"))
        assert resp.status_code == 404
        resp = client.get(self.resource_URL(equipment="Kolmipyörä"))
        assert resp.status_code == 404
        # Test valid route
        resp = client.get(self.resource_URL())
        assert resp.status_code == 200
        # Test valid content
        body = json.loads(resp.data)
        assert body["name"] == "Polkuaura"
        assert body["category"] == "Mountain Bike"
        assert body["brand"] == "Kona"
        assert body["model"] == "Hei Hei"
        assert body["date_added"] == "2019-11-21T11:20:30"
        assert body["date_retired"] is None
        assert body["user"] == "Joonas"
        # Test controls
        _check_namespace(client, body)
        _check_control_get_method("cyequ:owner", client, body)
        _check_control_get_method("cyequ:equipment-owned", client, body)
        _check_control_get_method("cyequ:users-all", client, body)
        _check_control_post_method("cyequ:add-component", client, body,
                                   _get_component_json())
        _check_control_get_method("self", client, body)
        _check_profile("profile", client, body, "equipment-profile")
        _check_control_put_method("edit", client, body, _get_equipment_json())
        # Test valid component items content
        assert len(body["items"]) == 2
        assert body["items"][0]["name"] == "Takatalvikiekko"
        assert body["items"][1]["name"] == "Hissitolppa"
        assert body["items"][0]["category"] == "Rear Wheel"
        assert body["items"][1]["category"] == "Seat Post"
        assert body["items"][0]["date_added"] == "2019-11-21T11:20:30"
        assert body["items"][1]["date_added"] == "2019-11-21T11:20:30"
        assert body["items"][0]["date_retired"] == "2019-12-21T11:20:30"
        for item in body["items"]:
            _check_control_get_method("self", client, item)
            _check_profile("profile", client, item, "component-profile")
        _check_control_delete_method("cyequ:delete", client, body)
Beispiel #5
0
    def test_get(self, client):
        '''
        Tests the GET method. Checks that the response status code is 200, and
        then checks that all of the expected attributes and controls are
        present, and the controls work. Also checks that all of the items from
        the DB population are present, and their controls.
        '''

        resp = client.get(self.RESOURCE_URL)
        assert resp.status_code == 200
        body = json.loads(resp.data)
        _check_namespace(client, body)
        _check_control_get_method("self", client, body)
        _check_control_post_method("cyequ:add-user", client, body,
                                   _get_user_json())
        assert len(body["items"]) == 2
        for item in body["items"]:
            _check_control_get_method("self", client, item)
            _check_profile("profile", client, item, "user-profile")
            assert "name" in item
Beispiel #6
0
    def test_put(self, client):
        '''
        Tests the PUT method. Checks all of the possible error codes, and also
        checks that a valid request receives a 204 response. Also tests that
        when name is changed, the sensor can be found from a its new URI.
        '''

        # Invalid route
        resp = client.get(self.resource_URL(user="******"))
        assert resp.status_code == 404
        body = json.loads(resp.data)
        assert body["@error"]["@message"] == "Not found"
        assert str(body["@error"]["@messages"]) == "[\'No user was " \
                                                   "found with URI {}\']" \
                                                   .format("Jaana1")
        _check_profile("profile", client, body, "error-profile")
        # Valid route ./Joonas/ -> ./Jenni/
        valid = _get_user_json()
        # Test for unsupported media type (content-type header)
        resp = client.put(self.resource_URL(user="******"),
                          data=json.dumps(valid))
        assert resp.status_code == 415
        # Tests for invalid JSON document
        resp = client.put(self.resource_URL(user="******"), json="invalid")
        assert resp.status_code == 400
        # Remove required fields
        valid.pop("name")
        resp = client.put(self.resource_URL(user="******"), json=valid)
        assert resp.status_code == 400
        # Test with valid content
        valid = _get_user_json()
        resp = client.put(self.resource_URL(user="******"), json=valid)
        assert resp.status_code == 204
        # Test changed
        resp = client.get(self.resource_URL(user="******"))
        body = json.loads(resp.data)
        assert body["name"] == valid["name"]
        # Test existing
        valid = _get_user_json(name="Janne")
        resp = client.put(self.resource_URL(user="******"), json=valid)
        assert resp.status_code == 409