From 2938de5ce2c41f12da95890c0a36d7861b018723 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Kociszewski?= Date: Wed, 10 Jul 2024 14:01:52 +0200 Subject: [PATCH] exclude all the tests by default, update readme file --- README.md | 4 ++++ test/get_current_weather_test.exs | 18 +++++++++++++++--- test/get_five_day_forecast_test.exs | 11 +++++++++++ test/get_historical_weather_test.exs | 3 +++ test/get_hourly_forecast_test.exs | 11 +++++++++++ test/get_one_call_weather_test.exs | 3 +++ test/get_sixteen_day_forecast_test.exs | 11 +++++++++++ test/test_helper.exs | 2 +- 8 files changed, 59 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 5a35f0c..7f43831 100644 --- a/README.md +++ b/README.md @@ -75,6 +75,10 @@ ExOwm utilizes some cool features such as: Each location entry in the list spawns a separate task (Elixir worker process) to check whether the request has been made within a specified time interval. If it has, the result is fetched from the cache. Otherwise, an API query is sent, the result is cached, and the data is returned. +## Running local tests + +Since all the tests are based on OWM API calls, they are disabled by default. To enable them, please remove `:api_based_test` from the `test/test_helper.exs file`. + ## To do * Add remaining OWM APIs (including One Call API 3.0) diff --git a/test/get_current_weather_test.exs b/test/get_current_weather_test.exs index 9c346cb..4a35b7d 100644 --- a/test/get_current_weather_test.exs +++ b/test/get_current_weather_test.exs @@ -7,7 +7,8 @@ defmodule GetCurrentWeatherTest do :ok end - test ":get_current_weather/1 with a city name" do + @tag :api_based_test + test "get_current_weather/1 with a city name" do result = ExOwm.get_current_weather(%{city: "Bengaluru"}) assert result != [] @@ -17,7 +18,8 @@ defmodule GetCurrentWeatherTest do assert Map.get(map, "name") == "Bengaluru" end - test ":get_current_weather/1 with a list of cities" do + @tag :api_based_test + test "get_current_weather/1 with a list of cities" do result = ExOwm.get_current_weather([%{city: "Lucerne"}]) assert is_list(result) @@ -29,6 +31,7 @@ defmodule GetCurrentWeatherTest do assert Map.get(map, "name") == "Lucerne" end + @tag :api_based_test test "get_current_weather/1 with a city name and a country code" do result = ExOwm.get_current_weather([%{city: "Munich", countr_code: "de"}]) @@ -41,7 +44,8 @@ defmodule GetCurrentWeatherTest do assert Map.get(map, "name") == "Munich" end - test ":get_current_weather/1 with a city id" do + @tag :api_based_test + test "get_current_weather/1 with a city id" do result = ExOwm.get_current_weather([%{id: 2_759_794}]) assert is_list(result) @@ -52,6 +56,7 @@ defmodule GetCurrentWeatherTest do assert Map.get(map, "name") == "Amsterdam" or "Gemeente Amsterdam" end + @tag :api_based_test test "get_current_weather/1 with a latitude and a longitude" do result = ExOwm.get_current_weather([%{lat: 52.374031, lon: 4.88969}]) @@ -64,6 +69,7 @@ defmodule GetCurrentWeatherTest do assert Map.get(map, "name") == "Amsterdam" or "Gemeente Amsterdam" end + @tag :api_based_test test "get_current_weather/1 with a zip and a country code" do result = ExOwm.get_current_weather([%{zip: "94040", country_code: "us"}]) @@ -76,6 +82,7 @@ defmodule GetCurrentWeatherTest do assert Map.get(map, "name") == "Mountain View" end + @tag :api_based_test test "get_current_weather/1 with a city name and options" do city = %{city: "Warsaw"} options = [units: :metric, lang: :pl] @@ -91,6 +98,7 @@ defmodule GetCurrentWeatherTest do assert Map.get(map, "name") == "Warszawa" end + @tag :api_based_test test "get_current_weather/1 with a city name and a country code and options" do city = %{city: "Warsaw", countr_code: "pl"} options = [units: :metric, lang: :pl] @@ -106,6 +114,7 @@ defmodule GetCurrentWeatherTest do assert Map.get(map, "name") == "Warszawa" end + @tag :api_based_test test "get_current_weather/1 with a city id and options" do city = %{id: 2_759_794} options = [units: :metric, lang: :pl] @@ -121,6 +130,7 @@ defmodule GetCurrentWeatherTest do assert Map.get(map, "name") == "Amsterdam" or "Gemeente Amsterdam" end + @tag :api_based_test test "get_current_weather/1 with a latitude and a longitude and options" do city = %{lat: 52.374031, lon: 4.88969} options = [units: :metric, lang: :pl] @@ -136,6 +146,7 @@ defmodule GetCurrentWeatherTest do assert Map.get(map, "name") == "Amsterdam" or "Gemeente Amsterdam" end + @tag :api_based_test test "get_current_weather/1 with a zip code, a country code and options" do city = %{zip: "94040", country_code: "us"} options = [units: :metric, lang: :pl] @@ -151,6 +162,7 @@ defmodule GetCurrentWeatherTest do assert Map.get(map, "name") == "Mountain View" end + @tag :api_based_test test "get_current_weather/1 with non-existing city" do result = ExOwm.get_current_weather(%{city: "Bonkersville"}) diff --git a/test/get_five_day_forecast_test.exs b/test/get_five_day_forecast_test.exs index 9a0490a..39712a8 100644 --- a/test/get_five_day_forecast_test.exs +++ b/test/get_five_day_forecast_test.exs @@ -7,6 +7,7 @@ defmodule GetFiveDayForecastTest do :ok end + @tag :api_based_test test "get_five_day_forecast/1 with a single city" do result = ExOwm.get_five_day_forecast(%{city: "Sochi"}) @@ -25,6 +26,7 @@ defmodule GetFiveDayForecastTest do assert city_name == "Sochi" end + @tag :api_based_test test "get_five_day_forecast/1 with city a list of cities" do result = ExOwm.get_five_day_forecast([%{city: "Sochi"}]) @@ -43,6 +45,7 @@ defmodule GetFiveDayForecastTest do assert city_name == "Sochi" end + @tag :api_based_test test "get_five_day_forecast/1 with a list of cities and country codes" do result = ExOwm.get_five_day_forecast([%{city: "Warsaw", countr_code: "pl"}]) @@ -61,6 +64,7 @@ defmodule GetFiveDayForecastTest do assert city_name == "Warsaw" end + @tag :api_based_test test "get_five_day_forecast/1 with a list of city ids" do result = ExOwm.get_five_day_forecast([%{id: 2_759_794}]) @@ -79,6 +83,7 @@ defmodule GetFiveDayForecastTest do assert city_name == "Amsterdam" end + @tag :api_based_test test "get_five_day_forecast/1 with a list of latitudes and longitudes" do result = ExOwm.get_five_day_forecast([%{lat: 4.3942822222, lon: 18.558442503}]) @@ -97,6 +102,7 @@ defmodule GetFiveDayForecastTest do assert city_name == "Kolongo" end + @tag :api_based_test test "get_five_day_forecast/1 with a list of zip codes and country codes" do result = ExOwm.get_five_day_forecast([%{zip: "94040", country_code: "us"}]) @@ -115,6 +121,7 @@ defmodule GetFiveDayForecastTest do assert city_name == "Mountain View" end + @tag :api_based_test test "get_five_day_forecast/1 with a list of city names and options" do result = ExOwm.get_five_day_forecast([%{city: "Zurich"}], units: :metric, lang: :ch) @@ -134,6 +141,7 @@ defmodule GetFiveDayForecastTest do end # Fribourg or Freiburg is a city which exists in multiple countries + @tag :api_based_test test "get_five_day_forecast/1 with a list of city names, country codes and options" do result = ExOwm.get_five_day_forecast([%{city: "Freiburg", countr_code: "ch"}], @@ -157,6 +165,7 @@ defmodule GetFiveDayForecastTest do assert %{"city" => %{"country" => "CH"}} = map end + @tag :api_based_test test "get_five_day_forecast/1 with a list of city ids and options" do result = ExOwm.get_five_day_forecast([%{id: 2_759_794}], units: :metric, lang: :pl) @@ -175,6 +184,7 @@ defmodule GetFiveDayForecastTest do assert city_name == "Amsterdam" end + @tag :api_based_test test "get_five_day_forecast/1 with a list of latitudes, longitudes and options" do result = ExOwm.get_five_day_forecast([%{lat: 52.374031, lon: 4.88969}], units: :metric, lang: :pl) @@ -194,6 +204,7 @@ defmodule GetFiveDayForecastTest do assert city_name == "Amsterdam" end + @tag :api_based_test test "get_five_day_forecast/1 with a list of zip codes, country codes and options" do result = ExOwm.get_five_day_forecast([%{zip: "94040", country_code: "us"}], diff --git a/test/get_historical_weather_test.exs b/test/get_historical_weather_test.exs index 0b5369b..1b155c3 100644 --- a/test/get_historical_weather_test.exs +++ b/test/get_historical_weather_test.exs @@ -7,6 +7,7 @@ defmodule GetHistoricalWeatherTest do :ok end + @tag :api_based_test test "get_historical_weather/1 with a list of latitudes and longitudes" do yesterday = DateTime.utc_now() |> DateTime.add(24 * 60 * 60 * -1, :second) |> DateTime.to_unix() @@ -24,6 +25,7 @@ defmodule GetHistoricalWeatherTest do assert Map.get(map, "hourly") |> Enum.count() == 24 end + @tag :api_based_test test "get_historical_weather/2 with a list of latitudes and longitudes and options" do yesterday = DateTime.utc_now() |> DateTime.add(24 * 60 * 60 * -1, :second) |> DateTime.to_unix() @@ -46,6 +48,7 @@ defmodule GetHistoricalWeatherTest do assert Map.get(map, "hourly") |> List.first() |> Map.get("dt") < yesterday end + @tag :api_based_test test "get_historical_weather/2 with an incorrect coordinates" do city = %{lat: "15", lon: "-2", dt: -200} diff --git a/test/get_hourly_forecast_test.exs b/test/get_hourly_forecast_test.exs index 0f3cc16..1b9ca23 100644 --- a/test/get_hourly_forecast_test.exs +++ b/test/get_hourly_forecast_test.exs @@ -7,6 +7,7 @@ defmodule GetHourlyForecastTest do :ok end + @tag :api_based_test test "get_hourly_forecast/1 with a city name" do result = ExOwm.get_hourly_forecast(%{city: "Sochi"}) @@ -25,6 +26,7 @@ defmodule GetHourlyForecastTest do assert city_name == "Sochi" end + @tag :api_based_test test "get_hourly_forecast/1 with a list of cities" do result = ExOwm.get_hourly_forecast([%{city: "Sochi"}]) @@ -43,6 +45,7 @@ defmodule GetHourlyForecastTest do assert city_name == "Sochi" end + @tag :api_based_test test "get_hourly_forecast/1 with a list of cities and country codes" do city = %{city: "Warsaw", countr_code: "pl"} @@ -63,6 +66,7 @@ defmodule GetHourlyForecastTest do assert city_name == "Warsaw" end + @tag :api_based_test test "get_hourly_forecast/1 with a list of city ids" do result = ExOwm.get_hourly_forecast([%{id: 2_759_794}]) @@ -81,6 +85,7 @@ defmodule GetHourlyForecastTest do assert city_name == "Amsterdam" end + @tag :api_based_test test "get_hourly_forecast/1 with a list of coordinates" do result = ExOwm.get_hourly_forecast([%{lat: 4.3942822222, lon: 18.558442503}]) @@ -100,6 +105,7 @@ defmodule GetHourlyForecastTest do assert map |> Map.get("list") |> Enum.count() == 96 end + @tag :api_based_test test "get_hourly_forecast/1 with a list of zip codes and country codes" do result = ExOwm.get_hourly_forecast([%{zip: "94040", country_code: "us"}]) @@ -118,6 +124,7 @@ defmodule GetHourlyForecastTest do assert city_name == "Mountain View" end + @tag :api_based_test test "get_hourly_forecast/1 with a list of cities and options" do result = ExOwm.get_hourly_forecast([%{city: "Zurich"}], units: :metric, lang: :ch) @@ -136,6 +143,7 @@ defmodule GetHourlyForecastTest do assert city_name == "Zurich" end + @tag :api_based_test test "get_hourly_forecast/1 with a list of cities, country codes and options" do result = ExOwm.get_hourly_forecast([%{city: "Freiburg", countr_code: "ch"}], @@ -160,6 +168,7 @@ defmodule GetHourlyForecastTest do assert %{"city" => %{"country" => "CH"}} = map end + @tag :api_based_test test "get_hourly_forecast/1 with a list of city ids and options" do result = ExOwm.get_hourly_forecast([%{id: 2_759_794}], units: :metric, lang: :pl) @@ -178,6 +187,7 @@ defmodule GetHourlyForecastTest do assert city_name == "Amsterdam" end + @tag :api_based_test test "get_hourly_forecast/1 with a list of coordinates and options" do result = ExOwm.get_hourly_forecast([%{lat: 52.374031, lon: 4.88969}], units: :metric, lang: :pl) @@ -197,6 +207,7 @@ defmodule GetHourlyForecastTest do assert city_name == "Amsterdam" end + @tag :api_based_test test "get_hourly_forecast/1 with a list of zip codes, country codes and options" do result = ExOwm.get_hourly_forecast([%{zip: "94040", country_code: "us"}], units: :metric, lang: :pl) diff --git a/test/get_one_call_weather_test.exs b/test/get_one_call_weather_test.exs index 2011026..4cef331 100644 --- a/test/get_one_call_weather_test.exs +++ b/test/get_one_call_weather_test.exs @@ -7,6 +7,7 @@ defmodule GetOneCallWeatherTest do :ok end + @tag :api_based_test test "get_weather/1 with a list of coordinates" do result = ExOwm.get_weather([%{lat: 52.374031, lon: 4.88969}]) @@ -20,6 +21,7 @@ defmodule GetOneCallWeatherTest do assert Map.get(map, "current") |> Map.get("temp") > 200 end + @tag :api_based_test test "get_weather/1 with a list of coordinates and options" do city = %{lat: 46.514098, lon: 8.326755} options = [units: :metric, lang: :ru] @@ -36,6 +38,7 @@ defmodule GetOneCallWeatherTest do assert Map.get(map, "current") |> Map.get("temp") < 100 end + @tag :api_based_test test "get_weather/1 with an incorrect coordinates" do city = %{lat: "800", lon: "-2"} diff --git a/test/get_sixteen_day_forecast_test.exs b/test/get_sixteen_day_forecast_test.exs index d272763..f427e77 100644 --- a/test/get_sixteen_day_forecast_test.exs +++ b/test/get_sixteen_day_forecast_test.exs @@ -7,6 +7,7 @@ defmodule GetSixteenDayForecastTest do :ok end + @tag :api_based_test test "get_sixteen_day_forecast/1 with a city name" do result = ExOwm.get_sixteen_day_forecast(%{city: "Warsaw"}) @@ -25,6 +26,7 @@ defmodule GetSixteenDayForecastTest do assert city_name == "Warsaw" end + @tag :api_based_test test "get_sixteen_day_forecast/1 with a list of cities" do result = ExOwm.get_sixteen_day_forecast([%{city: "Warsaw"}]) @@ -43,6 +45,7 @@ defmodule GetSixteenDayForecastTest do assert city_name == "Warsaw" end + @tag :api_based_test test "get_sixteen_day_forecast/1 with a list of city names and country codes" do result = ExOwm.get_sixteen_day_forecast([%{city: "Warsaw", countr_code: "pl"}]) @@ -61,6 +64,7 @@ defmodule GetSixteenDayForecastTest do assert city_name == "Warsaw" end + @tag :api_based_test test "get_sixteen_day_forecast/1 with a list of city ids" do result = ExOwm.get_sixteen_day_forecast([%{id: 2_759_794}]) @@ -79,6 +83,7 @@ defmodule GetSixteenDayForecastTest do assert city_name == "Amsterdam" end + @tag :api_based_test test "get_sixteen_day_forecast/1 with a list of coordinates" do result = ExOwm.get_sixteen_day_forecast([%{lat: 52.374031, lon: 4.88969}]) @@ -97,6 +102,7 @@ defmodule GetSixteenDayForecastTest do assert city_name == "Amsterdam" end + @tag :api_based_test test "get_sixteen_day_forecast/1 with a list of zip does and country codes" do result = ExOwm.get_sixteen_day_forecast([%{zip: "94040", country_code: "us"}]) @@ -115,6 +121,7 @@ defmodule GetSixteenDayForecastTest do assert city_name == "Mountain View" end + @tag :api_based_test test "get_sixteen_day_forecast/1 with a list of city names and options" do result = ExOwm.get_sixteen_day_forecast([%{city: "Warsaw"}], units: :metric, lang: :pl) @@ -133,6 +140,7 @@ defmodule GetSixteenDayForecastTest do assert city_name == "Warsaw" end + @tag :api_based_test test "get_sixteen_day_forecast/1 with a list of city names, country codes and options" do result = ExOwm.get_sixteen_day_forecast([%{city: "Warsaw", countr_code: "pl"}], @@ -155,6 +163,7 @@ defmodule GetSixteenDayForecastTest do assert city_name == "Warsaw" end + @tag :api_based_test test "get_sixteen_day_forecast/1 with a list of city ids and options" do result = ExOwm.get_sixteen_day_forecast([%{id: 2_759_794}], units: :metric, lang: :pl) @@ -173,6 +182,7 @@ defmodule GetSixteenDayForecastTest do assert city_name == "Amsterdam" end + @tag :api_based_test test "get_sixteen_day_forecast/1 with a list of coordinates and options" do result = ExOwm.get_sixteen_day_forecast([%{lat: 52.374031, lon: 4.88969}], units: :metric, lang: :pl) @@ -192,6 +202,7 @@ defmodule GetSixteenDayForecastTest do assert city_name == "Amsterdam" end + @tag :api_based_test test "get_sixteen_day_forecast/1 with a list of zip codes, country codes and options" do result = ExOwm.get_sixteen_day_forecast([%{zip: "94040", country_code: "us"}], diff --git a/test/test_helper.exs b/test/test_helper.exs index d13e5fc..4a1c48d 100644 --- a/test/test_helper.exs +++ b/test/test_helper.exs @@ -1 +1 @@ -ExUnit.start(exclude: [:skip]) +ExUnit.start(exclude: [:api_based_test])