Selaa lähdekoodia

Breaking change:
- environment variables names changed to be more specific
- login method should now be alright if in capitals instead
- removed some unneccesary checks in login
- confirmed VK method does work - PyTests all passed.

Alexander 4 vuotta sitten
vanhempi
commit
99b7ff8a5d
5 muutettua tiedostoa jossa 48 lisäystä ja 28 poistoa
  1. 1 0
      Pipfile
  2. 25 1
      Pipfile.lock
  3. 8 8
      README.md
  4. 11 16
      src/rival_regions_wrapper/authentication_handler.py
  5. 3 3
      tests/conftest.py

+ 1 - 0
Pipfile

@@ -18,6 +18,7 @@ requests = "*"
 webbot = "*"
 webbot = "*"
 python-dateutil = "*"
 python-dateutil = "*"
 pathlib2 = "*"
 pathlib2 = "*"
+rival-regions-wrapper = "*"
 
 
 [requires]
 [requires]
 python_version = "3"
 python_version = "3"

+ 25 - 1
Pipfile.lock

@@ -1,7 +1,7 @@
 {
 {
     "_meta": {
     "_meta": {
         "hash": {
         "hash": {
-            "sha256": "9caab9704beb8ff3db73bfcde37140d67db8646ced74d49051ed489cc2448663"
+            "sha256": "0dd337cbf37b84a6f33a7a2918dfc66e8cc5eb8448458033b4d3426129ac70c2"
         },
         },
         "pipfile-spec": 6,
         "pipfile-spec": 6,
         "requires": {
         "requires": {
@@ -88,6 +88,14 @@
             "index": "pypi",
             "index": "pypi",
             "version": "==2.25.1"
             "version": "==2.25.1"
         },
         },
+        "rival-regions-wrapper": {
+            "hashes": [
+                "sha256:93765932526f5a1af87f35d414a84cfe6cf232862827b6e2c480d51663093422",
+                "sha256:db73e5851088ae8531a09ddd451a05f437e64f7c8776e645a92d9a9756b3d1db"
+            ],
+            "index": "pypi",
+            "version": "==1.1.3"
+        },
         "selenium": {
         "selenium": {
             "hashes": [
             "hashes": [
                 "sha256:2d7131d7bc5a5b99a2d9b04aaf2612c411b03b8ca1b1ee8d3de5845a9be2cb3c",
                 "sha256:2d7131d7bc5a5b99a2d9b04aaf2612c411b03b8ca1b1ee8d3de5845a9be2cb3c",
@@ -137,6 +145,14 @@
             "index": "pypi",
             "index": "pypi",
             "version": "==1.4.4"
             "version": "==1.4.4"
         },
         },
+        "atomicwrites": {
+            "hashes": [
+                "sha256:6d1784dea7c0c8d4a5172b6c620f40b6e4cbfdf96d783691f2e1302a7b88e197",
+                "sha256:ae70396ad1a434f9c7046fd2dd196fc04b12f9e91ffb859164193be8b6168a7a"
+            ],
+            "markers": "sys_platform == 'win32'",
+            "version": "==1.4.0"
+        },
         "attrs": {
         "attrs": {
             "hashes": [
             "hashes": [
                 "sha256:31b2eced602aa8423c2aea9c76a724617ed67cf9513173fd3a4f03e3a929c7e6",
                 "sha256:31b2eced602aa8423c2aea9c76a724617ed67cf9513173fd3a4f03e3a929c7e6",
@@ -145,6 +161,14 @@
             "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'",
             "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'",
             "version": "==20.3.0"
             "version": "==20.3.0"
         },
         },
+        "colorama": {
+            "hashes": [
+                "sha256:5941b2b48a20143d2267e95b1c2a7603ce057ee39fd88e7329b0c292aa16869b",
+                "sha256:9f47eda37229f68eee03b24b9748937c7dc3868f906e8ba69fbcbdd3bc5dc3e2"
+            ],
+            "markers": "platform_system == 'Windows' and sys_platform == 'win32'",
+            "version": "==0.4.4"
+        },
         "distlib": {
         "distlib": {
             "hashes": [
             "hashes": [
                 "sha256:8c09de2c67b3e7deef7184574fc060ab8a793e7adbb183d942c389c8b13c52fb",
                 "sha256:8c09de2c67b3e7deef7184574fc060ab8a793e7adbb183d942c389c8b13c52fb",

+ 8 - 8
README.md

@@ -12,8 +12,8 @@ pip install rival_regions_wrapper
 The package should be available globaly.
 The package should be available globaly.
 
 
 ## Testing
 ## Testing
-This appplication supports unit tests, these are located in `rival_regions_wrapper/tests/`.
-Intall required dependancies using `pipenv install --dev`.
+This application supports unit tests, these are located in `rival_regions_wrapper/tests/`.
+Install required dependencies using `pipenv install --dev`.
 After installing you should be able to test the python package with pytest.
 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/`.
 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 remvong the cassettes directory.
 If you run in problems with testing you are advised to them run again after remvong the cassettes directory.
@@ -31,13 +31,13 @@ PASSWORD=PLACEHOLDER
 Replace `PLACEHOLDER` with your credentials.
 Replace `PLACEHOLDER` with your credentials.
 
 
 ## Login methods
 ## Login methods
-Currently the only working login method is Google.
+Currently the working login methods are Google and VK.
 If you can help me out and make the other login methods working it would be appreciated. 
 If you can help me out and make the other login methods working it would be appreciated. 
 
 
 login methods:
 login methods:
 
 
-- google
-- vk
+- google [working]
+- vk [working]
 - facebook
 - facebook
 
 
 ## Middleware
 ## Middleware
@@ -59,9 +59,9 @@ import os
 from rival_regions_wrapper import LocalAuthentication
 from rival_regions_wrapper import LocalAuthentication
 
 
 authentication = LocalAuthentication(
 authentication = LocalAuthentication(
-  os.environ["USERNAME"],
-  os.environ["PASSWORD"],
-  os.environ["LOGIN_METHOD"]
+  os.environ["RR_USERNAME"],
+  os.environ["RR_PASSWORD"],
+  os.environ["RR_LOGIN_METHOD"]
 )
 )
 ```
 ```
 
 

+ 11 - 16
src/rival_regions_wrapper/authentication_handler.py

@@ -122,13 +122,6 @@ class AuthenticationHandler:
         if cookie is None:
         if cookie is None:
             LOGGER.info('"%s": no cookie, new login, method "%s"',
             LOGGER.info('"%s": no cookie, new login, method "%s"',
                         self.username, self.login_method)
                         self.username, self.login_method)
-            if self.login_method not in [
-                        "g", "google", "v", "vk", "f", "facebook"
-                    ]:
-                raise RRClientException("Not a valid login method.")
-
-            auth_text = requests.get("https://rivalregions.com").text
-            browser = Browser(showWindow=self.show_window)
 
 
             method_dict = {
             method_dict = {
                 'g': self.login_google,
                 'g': self.login_google,
@@ -139,14 +132,16 @@ class AuthenticationHandler:
                 'facebook': self.login_facebook,
                 'facebook': self.login_facebook,
             }
             }
 
 
-            if self.login_method in method_dict:
-                browser = method_dict[self.login_method](browser, auth_text)
-            else:
-                LOGGER.info(
-                        '"%s": Invallid loggin method "%s"',
-                        self.username, self.login_method
-                    )
-                sys.exit()
+            if type(self.login_method) is not str:
+                raise RRClientException(f"{self.login_method} is not a valid login method.")
+
+            if self.login_method.lower() not in method_dict.keys():
+                raise RRClientException(f"{self.login_method} is not a valid login method.")
+
+            auth_text = requests.get("https://rivalregions.com").text
+            browser = Browser(showWindow=self.show_window)
+
+            browser = method_dict[self.login_method.lower()](browser, auth_text)
 
 
             LOGGER.info('"%s": Get cookie', self.username)
             LOGGER.info('"%s": Get cookie', self.username)
             phpsessid = browser.get_cookie('PHPSESSID')
             phpsessid = browser.get_cookie('PHPSESSID')
@@ -221,7 +216,7 @@ class AuthenticationHandler:
 
 
         return browser
         return browser
 
 
-    # IDK if this is working
+    # This is working
     def login_vk(self, browser, auth_text):
     def login_vk(self, browser, auth_text):
         """login using VK"""
         """login using VK"""
         LOGGER.info('Login method VK')
         LOGGER.info('Login method VK')

+ 3 - 3
tests/conftest.py

@@ -25,9 +25,9 @@ def vcr(vcr):
 @pytest.fixture(scope="module")
 @pytest.fixture(scope="module")
 def api_wrapper():
 def api_wrapper():
     """Set up wrapper before test"""
     """Set up wrapper before test"""
-    username = os.environ.get('USERNAME', None)
-    password = os.environ.get('PASSWORD', None)
-    login_method = os.environ.get('LOGIN_METHOD', None)
+    username = os.environ.get('RR_USERNAME', None)
+    password = os.environ.get('RR_PASSWORD', None)
+    login_method = os.environ.get('RR_LOGIN_METHOD', None)
     if None in (username, password, login_method):
     if None in (username, password, login_method):
         raise MissingAuthenticationError(
         raise MissingAuthenticationError(
             'Load the following variables in your user environment: '
             'Load the following variables in your user environment: '