Ejemplo n.º 1
0
 def test_geo_profile_route(self, client):
     db = next(override_get_db())
     country: Country = (db.query(Country).join(Country.institutions).join(
         Institution.rankings).filter(
             Ranking.metric == "Overall Score",
             Ranking.ranking_system == "the",
             Ranking.year == 2020,
             Ranking.value.isnot(None),
         ).first())
     rankings: List[Ranking] = (db.query(Ranking).join(
         Ranking.institution).join(Institution.country).filter(
             Country.country_code == country.country_code,
             Ranking.metric == "Overall Score",
             Ranking.ranking_system == "the",
             Ranking.year == 2020,
         ).all())
     # testing for aggregation
     values = [r.value for r in rankings if r.value]
     mean_score = Decimal(sum(values) / len(values))
     response = client.get(f"/geo/{country.country_code}")
     assert response.status_code == 200
     assert response.json()["entity"] == country.country_code
     assert response.json()["name"] == country.country
     assert response.json()["ranks"]
     assert response.json()["scores"]
     assert response.json()["stats"]
     for score_ranking in response.json()["scores"]:
         if not score_ranking["year"] == 2020:
             continue
         if not score_ranking["ranking_system"] == "the":
             continue
         # if not score_ranking["metric"] == "Overall Score":
         #     continue
         assert round(Decimal(score_ranking["value"]), 3) == mean_score
         break
Ejemplo n.º 2
0
 def test_institution_on_geo_profile(self, client):
     db = next(override_get_db())
     institution: Institution = db.query(Institution).first()
     grid_id = institution.grid_id
     assert re.match(appc.GRID_ID_PATTERN, grid_id)
     response = client.get(f"/geo/{grid_id}")
     assert response.status_code == 404
Ejemplo n.º 3
0
    def test_entity_compare_with_itself_entities_route(self, client):
        db = next(override_get_db())
        institution: Institution = db.query(Institution).first()
        grid_id = institution.grid_id

        response = client.get(f"/i/{grid_id}/compare",
                              params={"entities": [grid_id]})
        assert response.status_code == 400
        assert (response.json()["detail"] ==
                "Cannot compare an entity with itself!")
Ejemplo n.º 4
0
    def test_entity_compare_institution_on_geo_route(self, client):
        db = next(override_get_db())
        institution: Institution = db.query(Institution).first()
        grid_id = institution.grid_id
        country: Country = db.query(Country).join(Country.institutions).first()
        country_code = country.country_code

        response = client.get(
            f"/geo/{grid_id}/compare?entities={country_code}")
        assert response.status_code == 404
Ejemplo n.º 5
0
    def test_entity_compare_with_too_many_entities_route(self, client):
        db = next(override_get_db())
        institution: Institution = db.query(Institution).first()
        grid_id = institution.grid_id
        countries: Country = db.query(Country).join(Country.institutions).all()
        country_codes = [c.country_code for c in countries]
        country_codes = set(country_codes)

        response = client.get(f"/i/{grid_id}/compare",
                              params={"entities": country_codes})
        assert response.status_code == 400
        assert response.json()["detail"] == "Select at most 4 entities!"
Ejemplo n.º 6
0
 def test_institution_profile_route(self, client):
     db = next(override_get_db())
     institution: Institution = db.query(Institution).first()
     grid_id = institution.grid_id
     assert re.match(appc.GRID_ID_PATTERN, grid_id)
     response = client.get(f"/i/{grid_id}")
     assert response.status_code == 200
     assert response.json()["name"] == institution.name
     assert response.json()["entity"] == institution.grid_id
     assert response.json()["ranks"]
     assert response.json()["scores"]
     assert response.json()["stats"]
Ejemplo n.º 7
0
    def test_entity_compare_with_duplicate_entities_route(self, client):
        db = next(override_get_db())
        institution: Institution = db.query(Institution).first()
        grid_id = institution.grid_id
        country: Country = db.query(Country).join(Country.institutions).first()
        country_code = country.country_code

        response = client.get(
            f"/i/{grid_id}/compare",
            params={"entities": [country_code, country_code]},
        )
        assert response.status_code == 400
        assert response.json(
        )["detail"] == "Selected entities have duplicates!"
Ejemplo n.º 8
0
 def test_sub_region_geo_profile_route(self, client):
     db = next(override_get_db())
     country: Country = db.query(Country).join(Country.institutions).first()
     entity = country.sub_region
     response = client.get(f"/geo/{entity}")
     assert response.status_code == 200
Ejemplo n.º 9
0
 def test_geo_on_institution_profile(self, client):
     db = next(override_get_db())
     country: Country = db.query(Country).join(Country.institutions).first()
     response = client.get(f"/i/{country.country}")
     assert response.status_code == 404