Skip to content

Commit

Permalink
Add 'fake' interface to generate data
Browse files Browse the repository at this point in the history
  • Loading branch information
jacebrowning committed Jun 29, 2020
1 parent 84136b4 commit 7ae11db
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 7 deletions.
38 changes: 33 additions & 5 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pomace/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pkg_resources import DistributionNotFound, get_distribution

from .api import prompt, visit
from .api import *


try:
Expand Down
6 changes: 6 additions & 0 deletions pomace/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
from .config import settings


__all__ = ['fake', 'prompt', 'visit']


fake = utils.Fake()


def visit(
url: str = '',
*,
Expand Down
16 changes: 16 additions & 0 deletions pomace/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# pylint: disable=expression-not-assigned,unused-variable,redefined-outer-name,unused-argument

import pytest

from .. import utils


def describe_fake():
@pytest.fixture(scope='session')
def fake():
return utils.Fake()

def describe_person():
def it_includes_name_in_email(expect, fake):
person = fake.person
expect(person.email).icontains(person.last_name)
17 changes: 17 additions & 0 deletions pomace/types.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from dataclasses import dataclass
from typing import Optional
from urllib.parse import urlparse

Expand Down Expand Up @@ -51,3 +52,19 @@ def path(self) -> str:
@property
def fragment(self) -> str:
return urlparse(self.value).fragment.replace('/', '_').strip('_')


@dataclass
class Person:
first_name: str
last_name: str
email_address: str
zip_code: str

@property
def email(self) -> str:
return self.email_address

@property
def zip(self) -> str:
return self.zip_code
17 changes: 17 additions & 0 deletions pomace/utils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
import time

import faker
import log

from . import browser, shared
from .config import settings
from .types import Person


class Fake:
def __init__(self):
self.generator = faker.Faker()

def __getattr__(self, name):
method = getattr(self.generator, name)
return method()

@property
def person(self) -> Person:
first, last = self.first_name, self.last_name
email = f'{first}{last}@{self.free_email_domain}'.lower()
return Person(first, last, email, self.postcode)


def launch_browser(delay: float = 0.0) -> bool:
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool.poetry]

name = "pomace"
version = "0.0.16"
version = "0.0.17"
description = "Dynamic page objects for browser automation."

license = "MIT"
Expand Down Expand Up @@ -53,6 +53,7 @@ datafiles = "0.10b4"
parse = "^1.14.0"

# Utilities
faker = "^4.1.1"
inflection = "~0.4.0"
minilog = "^1.6"

Expand Down

0 comments on commit 7ae11db

Please sign in to comment.