Ejemplo n.º 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.
        """

        resp = client.get(self.RESOURCE_URL)
        assert resp.status_code == 200
        body = json.loads(resp.data)
        assert body["id"] == 1
        assert body["book_barcode"] == 200001
        assert body["patron_barcode"] == 100002
        assert body["loandate"] == "2020-04-20"
        assert body["renewaldate"] == None
        assert body["duedate"] == "2020-05-18"
        assert body["renewed"] == 0
        assert body["status"] == "Charged"
        utils._check_namespace(client, body)
        utils._check_control_get_method("self", client, body)
        utils._check_control_get_method("profile", client, body)
        utils._check_control_get_method("author", client, body)
        utils._check_control_get_method("inlibris:loans-by", client, body)
        utils._check_control_get_method("inlibris:target-book", client, body)
        utils._check_control_get_method("inlibris:books-all", client, body)
        utils._check_control_get_method("inlibris:patrons-all", client, body)
        utils._check_control_put_loan_method("edit", client, body)
        utils._check_control_delete_method("inlibris:delete", client, body)
        resp = client.get(self.NO_BOOK_URL)
        assert resp.status_code == 404
        resp = client.get(self.NOT_LOANED_URL)
        assert resp.status_code == 400
Ejemplo n.º 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. Also checks that all of the items from
        the DB popluation are present, and their controls.
        """

        resp = client.get(self.RESOURCE_URL)
        assert resp.status_code == 200
        body = json.loads(resp.data)
        assert body["receiver"] == "user2"
        assert body["sender"] == "user1"
        utils._check_namespace(client, body)
        utils._check_control_get_method("profile", client, body)
        utils._check_control_get_method("bumeta:transactions-all", client,
                                        body)
        client.delete(self.DELETE_USER1_URL)
        resp = client.get(self.RESOURCE_URL)
        assert resp.status_code == 200
        client.delete(self.DELETE_USER2_URL)
        resp = client.get(self.RESOURCE_URL)
        assert resp.status_code == 200
        #_check_transaction_control_put_method("edit", client, body)
        utils._check_control_delete_method("bumeta:delete", client, body)
        resp = client.get(self.INVALID_URL)
        assert resp.status_code == 404
Ejemplo n.º 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.
        """

        resp = client.get(self.RESOURCE_URL)
        assert resp.status_code == 200
        body = json.loads(resp.data)
        assert body["barcode"] == 100001
        assert body["firstname"] == "Hilma"
        assert body["lastname"] == "Kirjastontäti"
        assert body["email"] == "*****@*****.**"
        assert body["group"] == "Staff"
        assert body["status"] == "Active"
        utils._check_namespace(client, body)
        utils._check_control_get_method("profile", client, body)
        utils._check_control_get_method("collection", client, body)
        utils._check_control_put_patron_method("edit", client, body)
        utils._check_control_delete_method("inlibris:delete", client, body)

        # test invalid URL
        resp = client.get(self.INVALID_URL)
        assert resp.status_code == 404
Ejemplo n.º 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.
        '''

        # 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)
Ejemplo n.º 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 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)
Ejemplo n.º 6
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.
        """

        resp = client.get(self.RESOURCE_URL)
        assert resp.status_code == 200
        body = json.loads(resp.data)
        assert body["category_name"] == "cat1"
        utils._check_namespace(client, body)
        utils._check_control_get_method("profile", client, body)
        utils._check_control_get_method("bumeta:categories-all", client, body)
        utils._check_category_control_put_method("edit", client, body)
        utils._check_control_delete_method("bumeta:delete", client, body)
        resp = client.get(self.INVALID_URL)
        assert resp.status_code == 404
Ejemplo n.º 7
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.
        """

        resp = client.get(self.RESOURCE_URL)
        assert resp.status_code == 200
        body = json.loads(resp.data)
        assert body["barcode"] == 200001
        assert body["title"] == "Garpin maailma"
        assert body["pubyear"] == 2011
        utils._check_namespace(client, body)
        utils._check_control_get_method("self", client, body)
        utils._check_control_get_method("profile", client, body)
        utils._check_control_get_method("collection", client, body)
        utils._check_control_get_method("inlibris:holds-on", client, body)
        utils._check_control_get_method("inlibris:loan-of", client, body)
        utils._check_control_put_book_method("edit", client, body)
        utils._check_control_delete_method("inlibris:delete", client, body)
        resp = client.get(self.INVALID_URL)
        assert resp.status_code == 404