Skip to content

Commit

Permalink
Restructuring so tests are with application code pytests default impo…
Browse files Browse the repository at this point in the history
…rt mode going forward isn't certain so avoiding relative imports with pytest seems more extensible pytest docs on this:https://docs.pytest.org/en/stable/goodpractices.html#tests-outside-application-code. Pytest dev branch discussion around this: pytest-dev/pytest#7245 AND pytest-dev/pytest#7870
  • Loading branch information
supercerealized committed Apr 18, 2021
1 parent 8819e47 commit a7ee224
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 0 deletions.
30 changes: 30 additions & 0 deletions cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env python
import uuid
import sys

import click

from jobcoin import jobcoin


@click.command()
def main(args=None):
print('Welcome to the Jobcoin mixer!\n')
while True:
addresses = click.prompt(
'Please enter a comma-separated list of new, unused Jobcoin '
'addresses where your mixed Jobcoins will be sent.',
prompt_suffix='\n[blank to quit] > ',
default='',
show_default=False)
if addresses.strip() == '':
sys.exit(0)
deposit_address = uuid.uuid4().hex
click.echo(
'\nYou may now send Jobcoins to address {deposit_address}. They '
'will be mixed and sent to your destination addresses.\n'
.format(deposit_address=deposit_address))


if __name__ == '__main__':
sys.exit(main())
Empty file added jobcoin/README.md
Empty file.
Empty file added jobcoin/__init__.py
Empty file.
4 changes: 4 additions & 0 deletions jobcoin/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Replace the URL below
API_BASE_URL = 'http://jobcoin.gemini.com/undaunted-gossip/api'
API_ADDRESS_URL = '{}/addresses'.format(API_BASE_URL)
API_TRANSACTIONS_URL = '{}/transactions'.format(API_BASE_URL)
3 changes: 3 additions & 0 deletions jobcoin/jobcoin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import config

# Write your Jobcoin API client here.
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
click==7.0
pytest==6.2.2
requests==2.20.0
35 changes: 35 additions & 0 deletions test_jobcoin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env python
import pytest
import re
from click.testing import CliRunner


from jobcoin import config
import cli


@pytest.fixture
def response():
import requests
return requests.get('https://jobcoin.gemini.com/')


def test_content(response):
assert 'Hello!' in response.text


def test_cli_basic():
runner = CliRunner()
result = runner.invoke(cli.main)
assert result.exit_code == 0
assert 'Welcome to the Jobcoin mixer' in result.output


def test_cli_creates_address():
runner = CliRunner()
address_create_output = runner.invoke(cli.main, input='1234,4321').output
output_re = re.compile(
r'You may now send Jobcoins to address [0-9a-zA-Z]{32}. '
'They will be mixed and sent to your destination addresses.'
)
assert output_re.search(address_create_output) is not None

0 comments on commit a7ee224

Please sign in to comment.