예제 #1
0
    def test_with_valid_token(self, mock_controller):
        """Client auth token has required public read scope."""
        document = mocks.document()
        docs = {
            "results": [document],
            "metadata": {
                "start": 0,
                "end": 1,
                "size": 50,
                "total": 1
            },
        }
        r_data = {"results": docs, "query": APIQuery()}
        mock_controller.search.return_value = r_data, HTTPStatus.OK, {}
        token = helpers.generate_token("1234",
                                       "*****@*****.**",
                                       "foouser",
                                       scope=[auth.scopes.READ_PUBLIC])
        response = self.client.get("/", headers={"Authorization": token})
        self.assertEqual(response.status_code, HTTPStatus.OK)

        data = json.loads(response.data)
        res = jsonschema.RefResolver(
            "file://%s/" % os.path.abspath(os.path.dirname(self.SCHEMA_PATH)),
            None,
        )
        self.assertIsNone(
            jsonschema.validate(data, self.schema, resolver=res),
            "Response content is valid per schema",
        )

        for field in get_required_fields():
            self.assertIn(field, data["results"][0])
예제 #2
0
 def test_to_json(self):
     """Just your run-of-the-mill arXiv document generates valid JSON."""
     document = mocks.document()
     srlzd = serialize.as_json(document)
     res = jsonschema.RefResolver(
         "file://%s/" % os.path.abspath(os.path.dirname(self.SCHEMA_PATH)),
         None,
     )
     self.assertIsNone(
         jsonschema.validate(json.loads(srlzd), self.schema, resolver=res))
예제 #3
0
 def test_to_json(self):
     """Just your run-of-the-mill arXiv document generates valid JSON."""
     document = mocks.document()
     meta = {"start": 0, "size": 50, "end": 50, "total": 500202}
     document_set = {"results": [document], "metadata": meta}
     srlzd = serialize.as_json(document_set)
     res = jsonschema.RefResolver(
         "file://%s/" % os.path.abspath(os.path.dirname(self.SCHEMA_PATH)),
         None,
     )
     self.assertIsNone(
         jsonschema.validate(json.loads(srlzd), self.schema, resolver=res))
예제 #4
0
 def mock_classic_controller(controller, method="query", **kwargs):
     docs: domain.DocumentSet = {
         "results": [mocks.document()],
         "metadata": {
             "start": 0,
             "end": 1,
             "size": 50,
             "total": 1
         },
     }
     r_data = domain.ClassicSearchResponseData(
         results=docs,
         query=domain.ClassicAPIQuery(**(kwargs or {
             "search_query": "all:electron"
         })),
     )
     getattr(controller, method).return_value = r_data, HTTPStatus.OK, {}
예제 #5
0
 def test_to_atom(self):
     """Just your run-of-the-mill arXiv document generates valid Atom."""
     document = mocks.document()
     _ = serialize.as_atom(document)