Skip to content
This repository has been archived by the owner on Jul 18, 2023. It is now read-only.

Commit

Permalink
Merge pull request #22 from njzjz/dev
Browse files Browse the repository at this point in the history
test: add test processes
  • Loading branch information
njzjz authored Feb 1, 2019
2 parents 8b91366 + 8760a90 commit ed01c42
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 28 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache

# Translations
*.mo
Expand Down Expand Up @@ -99,3 +100,6 @@ ENV/

# mypy
.mypy_cache/

# test
.testfile
15 changes: 15 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
language: python
matrix:
include:
- python: 2.7
- python: 3.5
- python: 3.6
- python: 3.7
dist: xenial
sudo: true

install:
- pip install tox-travis

script:
- tox
File renamed without changes.
32 changes: 19 additions & 13 deletions ecnunetwork/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,45 @@


class ecnunetwork(object):
def __init__(self, username=None, password=None, configfile=os.path.join(os.path.expanduser('~'), ".ecnunetwork")):
def __init__(
self, username=None, password=None, configfile=os.path.join(
os.path.expanduser('~'),
".ecnunetwork")):
self.username = username
self.password = password
self.configfile = configfile
self.url = "https://login.ecnu.edu.cn/include/auth_action.php"
self.flag = 0

def connect(self):
if self.username == None or self.password == None:
self.readpassword()
r = requests.post(self.url, data={
"action": "login", "ajax": 1, "ac_id": 1, "username": self.username, "password": self.password})
if self.username is None or self.password is None:
self._readpassword()
r = requests.post(
self.url,
data={"action": "login", "ajax": 1, "ac_id": 1,
"username": self.username, "password": self.password})
print(r.text)
if r.text.startswith("login_ok"):
print("Successfully connected to the Internet.")
if self.flag == 1:
yorn = input("Save password? [Y/n] ")
if yorn == "" or yorn == "Y" or yorn == "y" or yorn == "yes":
self.savepassword()
self._savepassword()
else:
yorn = input(
"Fail to login. Maybe your id or password is wrong. Retry? [Y/n] ")
self.flag = 2
if yorn == "" or yorn == "Y" or yorn == "y" or yorn == "yes":
self.username = None
self.password = None
self._username = None
self._password = None
self.connect()

def inputpassword(self):
def _inputpassword(self):
self.username = input("Please input your ECNU id: ")
self.password = input("Please input your password: ")
self.flag = 1

def readpassword(self):
def _readpassword(self):
if not self.flag == 2:
try:
with open(self.configfile, 'r') as f:
Expand All @@ -51,10 +57,10 @@ def readpassword(self):
self.password = config['password']
except:
pass
if self.username == None or self.password == None:
self.inputpassword()
if self.username is None or self.password is None:
self._inputpassword()

def savepassword(self):
def _savepassword(self):
config = {"username": self.username, "password": self.password}
with open(self.configfile, 'w') as f:
json.dump(config, f)
Expand Down
Empty file added ecnunetwork/test/__init__.py
Empty file.
13 changes: 13 additions & 0 deletions ecnunetwork/test/test_ecnunetwork.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import unittest
import ecnunetwork


class Testecnunetwork(unittest.TestCase):
def test_loginok(self):
def answerinput(inp):
print(inp)
return 'y'
ecnunetwork.input = answerinput
n = ecnunetwork.ecnunetwork(configfile='.testfile')
n.url = 'https://php.njzjz.win/login_ok.php'
n.connect()
52 changes: 37 additions & 15 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,37 @@
from setuptools import setup
setup(name='ecnunetwork',
description='A script to connect to Internet at East China Normal University (ECNU).',
keywords="ecnu",
url='https://github.com/njzjz/ecnunetwork',
author='Jinzhe Zeng',
author_email='jzzeng@stu.ecnu.edu.cn',
packages=['ecnunetwork'],
install_requires=['requests'],
entry_points={
'console_scripts': ['ecnunetwork=ecnunetwork.commandline:main', 'network=ecnunetwork.commandline:main']
},
setup_requires=['setuptools_scm'],
use_scm_version=True,
)
import os

from setuptools import find_packages, setup

if __name__ == '__main__':
this_directory = os.path.abspath(os.path.dirname(__file__))
with open(os.path.join(this_directory, 'docs', 'README.md')) as f:
long_description = f.read()
setup(
name='ecnunetwork',
description='A script to connect to Internet at East China Normal University (ECNU).',
keywords="ecnu", url='https://github.com/njzjz/ecnunetwork',
author='Jinzhe Zeng', author_email='jzzeng@stu.ecnu.edu.cn',
packages=find_packages(),
install_requires=['requests'],
entry_points={
'console_scripts':
['ecnunetwork=ecnunetwork.commandline:main',
'network=ecnunetwork.commandline:main']},
setup_requires=['setuptools_scm', 'pytest-runner'],
use_scm_version=True,
classifiers=[
"Natural Language :: English",
"Operating System :: POSIX :: Linux",
"Operating System :: Microsoft :: Windows",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: Software Development :: Version Control :: Git",
],
zip_safe=True,
long_description=long_description,
long_description_content_type='text/markdown',
tests_require=['pytest-sugar'],
)
14 changes: 14 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[tox]
envlist = py{37,36,35,27}

[testenv]
passenv = CI TRAVIS TRAVIS_* CODECOV_* TOXENV
deps =
pytest-sugar
pytest-cov
coveralls
codecov>=1.4.0
commands =
pytest --pyargs ecnunetwork --cov {envsitepackagesdir}/ecnunetwork -s
coveralls
codecov -e TOXENV

0 comments on commit ed01c42

Please sign in to comment.