浏览代码

Update readme and unit tests

JoostSijm 3 年之前
父节点
当前提交
a2a416c617
共有 4 个文件被更改,包括 157 次插入68 次删除
  1. 70 46
      README.md
  2. 13 0
      example.env
  3. 59 0
      tests/conftest.py
  4. 15 22
      tests/test_rival_regions_wrapper.py

+ 70 - 46
README.md

@@ -1,63 +1,42 @@
 # Rival-Regions-Wrapper
 # Rival-Regions-Wrapper
-This library will functions as an authenticator an API wrapper for interaction with Rival Regions.
+This library functions as an authenticator and API wrapper for interaction with Rival Regions.
 Use at your own risk.
 Use at your own risk.
 
 
 ## Install
 ## Install
-The following steps can be used to install the package with pip:
+This package is available on the Python Package Index (PyPi) under the name [rival-regions-wrapper](https://pypi.org/project/rival-regions-wrapper/).
+Use the following command to install the package globaly using pip:
 
 
 ```
 ```
 pip install rival_regions_wrapper
 pip install rival_regions_wrapper
 ```
 ```
 
 
-The package should be available globally.
+When running on local authentication it is also required to have [ChromeDriver](https://sites.google.com/chromium.org/driver/) installed.
+This to automate browser actions to account login, private-, conference-, and language chat messages.
 
 
-## Testing
-This appplication supports unit tests, these are located in `rival_regions_wrapper/tests/`.
-Intall required dependancies using `pipenv install --dev`.
-After installing you should be able to test the python package with pytest.
-Requests are cached for quick testing using VCR.py located at `rival_regions_wrapper/tests/cassettes/`.
-If you run in problems with testing you are advised to them run again after removing the cassettes directory.
-
-The tests read login credentials from the following environment variables:
-`LOGIN_METHOD`, `USERNAME`, `PASSWORD`.
-You can set those by creating an file named `.env` with te following:
-
-```
-LOGIN_METHOD=PLACEHOLDER
-USERNAME=PLACEHOLDER
-PASSWORD=PLACEHOLDER
-```
-
-Replace `PLACEHOLDER` with your credentials.
-
-Also must have the chromedriver which can be found here https://sites.google.com/a/chromium.org/chromedriver/home 
-
-Add this to the system `PATH` environmental variable.
-
-## Login methods
-Currently the only working login method is Google.
-If you can help me out and make the other login methods working it would be appreciated. 
-
-login methods:
-
-- google
-- vk
-- facebook
-
-## Middleware
-The API wrapper uses middleware to decide where how to send the request.
-Middlewares can also be used to write direct requests to Rival Regions.
+Alternative when you want to use the development version you can clone the repository localy.
+Check out the dev branch, then run `pip install -e .` inside the directory to install the package globaly.
+It is then possible to edit the source code for development and testing. 
 
 
-Current middleware
+## Usage 
+Authentication is done through a middleware module that determines how to send the request.
+The middleware can also be used to write direct requests to Rival Regions in case the wrapper classes dont suffice.
+If you are unsure middleware to use, then it is advised to implement LocalAuthentication.
 
 
-### LocalAuthentication
+LocalAuthentication is used to login in directly into Rival Regions using supported login methods.
+When running into issues with login then I would appreciate if you could help me resolve the issue. 
+Available login methods: google (supported), vk (may work, never tested), facebook (may work, never tested)
 Use username, password, and login method to log in local instance of the authenticator.
 Use username, password, and login method to log in local instance of the authenticator.
 
 
-### RemoteAuthentication
-Connect through a remote API using URL and authentication key.
+RemoteAuthentication connects through a remote API using URL and authentication key.
+This is expermental and isn't documentend but I have plans to improve on this in the future.
+
+There is a wrapper available for the following entities:
+article, conference, craft, language\_chat, market, overview, perks, profile, resource_state, storage, war, work
+For now there is limited documentation how to use the wrapper classes.
+Read the files [here](https://github.com/joostsijm/rival_regions_wrapper/tree/dev/src/rival_regions_wrapper/wrapper) to see how they work.
 
 
 ## Examples
 ## Examples
-Create local authentication middleware and log in with environ variables
+Create LocalAuthentication middleware and log in with using environ variables.
 ```python
 ```python
 import os
 import os
 from rival_regions_wrapper.middleware import LocalAuthentication
 from rival_regions_wrapper.middleware import LocalAuthentication
@@ -69,12 +48,12 @@ authentication = LocalAuthentication(
 )
 )
 ```
 ```
 
 
-request region page from Rival Regions
+request region page from Rival Regions.
 ```python
 ```python
 region = authentication.get('listed/upgrades/{}'.format(region_id))
 region = authentication.get('listed/upgrades/{}'.format(region_id))
 ```
 ```
 
 
-Example of API wrapper to get oil current available resources from a state
+Example of API wrapper to get oil current available resources from a state.
 ```python
 ```python
 from rival_regions_wrapper.wrapper import ResourceState
 from rival_regions_wrapper.wrapper import ResourceState
 
 
@@ -85,5 +64,50 @@ response = ResourceState(authentication, state).info(resource)
 
 
 For more examples look at the unit tests.
 For more examples look at the unit tests.
 
 
+## Testing
+This libary supports unit tests, these can be found in `rival_regions_wrapper/tests/`.
+To run them besides, Pip it is also required to install [Pipenv](https://pypi.org/project/pipenv/).
+Clone the repository localy, then intall required development dependencies using `pipenv install --dev`.
+After installing these packages, you are able to run the tests with the `pytest` command.
+
+Requests are cached for quick testing using VCR.py located at `rival_regions_wrapper/tests/cassettes/`.
+If you run in problems with testing you are advised to them run again after removing the cassettes directory.
+Use the parameter `--disable-vcr` to disable VCR temporaly when running Pytest.
+
+The tests read login credentials and other information from the following environment variables:
+`USERNAME`, `PASSWORD`, and `LOGIN_METHOD`.
+You can set those variables by copying `example.env` to .env`.
+Replace `PLACEHOLDER` with your credentials.
+
+Required environ variables:
+```
+USERNAME=PLACEHOLDER
+PASSWORD=PLACEHOLDER
+LOGIN_METHOD=PLACEHOLDER
+```
+
+There are several optional environ variables, as you can see here with some example value. 
+```
+CAPTCHA_KEY=59f34d451658f55a517eb1395df52331f
+CONFERENCE_ID=439289
+CONFERENCE_TITLE=test
+LANGUAGE_CHAT=da
+PERK=strenght
+PERK_UPGRADE_TYPE=gold
+CRAFT_ITEM=energy_drink
+CRAFT_AMOUNT=10
+PROFILE_ID=2000340574
+MESSAGE=test
+```
+
+In case you want to use the anti-caption service you can fill in the key in `CAPTCHA_KEY`.
+Other variables are required to run test that are skipped by default.
+These test are skipped because the test sends out a request that makes change to Rival Regions, like sending messages, or crafting items.
+You can run those these test by changing the appropiate environ variable and adding the `--no-skip` parameter.
+When using this parameter it is advised to specify which test to run.
+This can be done with the `-k` parameter, for example `pytest -k profile_message --disable-vcr --no-skips`.
+To get a more verbose output from Pytest, use the `-v` parameter.
+To see log output of library use the `-s` parameter.
+
 ## Contact
 ## Contact
 * [Discord](https://discord.gg/6fzHtJM)
 * [Discord](https://discord.gg/6fzHtJM)

+ 13 - 0
example.env

@@ -0,0 +1,13 @@
+USERNAME=PLACEHOLDER
+PASSWORD=PLACEHOLDER
+LOGIN_METHOD=PLACEHOLDER
+CAPTCHA_KEY=PLACEHOLDER
+CONFERENCE_ID=PLACEHOLDER
+CONFERENCE_TITLE=PLACEHOLDER
+LANGUAGE_CHAT=PLACEHOLDER
+PERK=PLACEHOLDER
+PERK_UPGRADE_TYPE=PLACEHOLDER
+CRAFT_ITEM=PLACEHOLDER
+CRAFT_AMOUNT=PLACEHOLDER
+PROFILE_ID=PLACEHOLDER
+MESSAGE=PLACEHOLDER

+ 59 - 0
tests/conftest.py

@@ -44,6 +44,65 @@ def vcr(vcr):
     return vcr
     return vcr
 
 
 
 
+@pytest.fixture(scope="module")
+def conference_id():
+    """Get conference id from environ variable"""
+    return os.environ.get('CONFERENCE_ID', None)
+
+
+@pytest.fixture(scope="module")
+def message():
+    """Get message from environ variable"""
+    return os.environ.get('MESSAGE', None)
+
+
+@pytest.fixture(scope="module")
+def conference_title():
+    """Get conference title from environ variable"""
+    return os.environ.get('CONFERENCE_TITLE', None)
+
+
+@pytest.fixture(scope="module")
+def language_chat():
+    """Get language chat from environ varriable"""
+    return os.environ.get('LANGUAGE_CHAT', None)
+
+
+@pytest.fixture(scope="module")
+def perk():
+    """Get perk from environ varriable"""
+    return os.environ.get('PERK', None)
+
+
+@pytest.fixture(scope="module")
+def perk_upgrade_type():
+    """Get perk upgrade type from environ varriable"""
+    return os.environ.get('PERK_UPGRADE_TYPE', None)
+
+
+def perk_upgrade_type():
+    """Get perk upgrade type from environ varriable"""
+    return os.environ.get('PERK_UPGRADE_TYPE', None)
+
+
+@pytest.fixture(scope="module")
+def craft_item():
+    """Get craft item from environ varriable"""
+    return os.environ.get('CRAFT_ITEM', None)
+
+
+@pytest.fixture(scope="module")
+def craft_amount():
+    """Get craft amount from environ varriable"""
+    return os.environ.get('CRAFT_AMOUNT', None)
+
+
+@pytest.fixture(scope="module")
+def profile_id():
+    """Get profile id from environ varriable"""
+    return os.environ.get('PROFILE_ID', None)
+
+
 @pytest.fixture(scope="module")
 @pytest.fixture(scope="module")
 def middleware():
 def middleware():
     """Set up wrapper before test"""
     """Set up wrapper before test"""

+ 15 - 22
tests/test_rival_regions_wrapper.py

@@ -41,9 +41,9 @@ def test_profile_info(middleware, profile_keys):
 
 
 
 
 @pytest.mark.skip(reason="message request")
 @pytest.mark.skip(reason="message request")
-def test_profile_message(middleware):
+def test_profile_message(middleware, profile_id, message):
     """Test an API to send message to profile"""
     """Test an API to send message to profile"""
-    Profile(middleware, 2000340574).message('hi')
+    Profile(middleware, profile_id).message(message)
 
 
 
 
 @pytest.fixture
 @pytest.fixture
@@ -172,11 +172,9 @@ def test_perks_info(middleware, perks_keys):
 
 
 
 
 @pytest.mark.skip(reason="Update request")
 @pytest.mark.skip(reason="Update request")
-def test_perks_upgrade(middleware):
+def test_perks_upgrade(middleware, perk, perk_upgrade_type):
     """Test an API call to upgrade perk"""
     """Test an API call to upgrade perk"""
-    perk = 'strenght'
-    upgrade_type = 'gold'
-    Perks(middleware).upgrade(perk, upgrade_type)
+    Perks(middleware).upgrade(perk, perk_upgrade_type)
 
 
 
 
 @pytest.fixture
 @pytest.fixture
@@ -186,11 +184,9 @@ def craft_keys():
 
 
 
 
 @pytest.mark.skip(reason="Update request")
 @pytest.mark.skip(reason="Update request")
-def test_craft_produce(middleware):
-    """Test an API call to produce new item"""
-    item = 'energy_drink'
-    Craft(middleware).produce(item, 10)
-
+def test_craft_produce(middleware, craft_item, craft_amount):
+    """Test an API call to craft a new item"""
+    Craft(middleware).produce(craft_item, craft_amount)
     assert True
     assert True
 
 
 
 
@@ -449,27 +445,24 @@ def test_article_info_two(middleware, article_keys):
 
 
 
 
 @pytest.mark.skip(reason="conference message request")
 @pytest.mark.skip(reason="conference message request")
-def test_conference_message(middleware):
+def test_conference_message(middleware, conference_id, message):
     """Test conference message"""
     """Test conference message"""
-    conference_id = 439289
-    Conference(middleware, conference_id).message('hi')
+    Conference(middleware, conference_id).message(message)
 
 
 
 
 @pytest.mark.skip(reason="conference notification request")
 @pytest.mark.skip(reason="conference notification request")
-def test_conference_notification(middleware):
+def test_conference_notification(middleware, conference_id, message):
     """Test conference notification"""
     """Test conference notification"""
-    conference_id = 439289
-    Conference(middleware, conference_id).notification('hi', True)
+    Conference(middleware, conference_id).notification(message, True)
 
 
 
 
 @pytest.mark.skip(reason="conference title change request")
 @pytest.mark.skip(reason="conference title change request")
-def test_conference_change_title(middleware):
+def test_conference_change_title(middleware, conference_id, conference_title):
     """Test conference change title"""
     """Test conference change title"""
-    conference_id = 439289
-    Conference(middleware, conference_id).change_title('new title')
+    Conference(middleware, conference_id).change_title(conference_title)
 
 
 
 
 @pytest.mark.skip(reason="language chat message request")
 @pytest.mark.skip(reason="language chat message request")
-def test_language_chat_message(middleware):
+def test_language_chat_message(middleware, language_chat, message):
     """Test sending message to language chat"""
     """Test sending message to language chat"""
-    LanguageChat(middleware, 'da').message('hi')
+    LanguageChat(middleware, language_chat).message(message)