Giter Club home page Giter Club logo

jokes's Issues

Tests and documentation for utils

#22 was resolved, but there are no tests or documentation for the features that were added.

Tests should be created for the new features added by #23 and the README should be updated.

  • Add tests
  • Update documentation

Increase code coverage percentage to 100%

#27 introduced code coverage in the test pipeline, but limited it 85% so the tests would pass and the PR could be merged.

Ideally we would want this percentage to be 100%, so we should improve the tests, cover the areas that aren't covered and increase the expected percentage in pyproject.toml to 100%

Double validation in submit pipeline

There is a performance downgrade introduced in #19 .

Due to the inheritance of JokeSingleSubmit + the workflow of using JokeBase to match the joke type, "type" and "category" are validated twice in the submit pipeline.

Screen Shot 2022-08-07 at 4 10 21 PM

Add safe mode to get request

The Joke API has a "safe-mode" that tries to filter out any unsafe / insulting jokes. It would be nice to have the functionality work with the CLI.

This would require adding another option to the get command. Perhaps another context flag?

@click.option("--safe/--not-safe", "safe", default=False)

ctx.obj["SAFE"] = safe

The biggest problem I see is with httpx; the library doesn't support creating valueless query parameters.

params = {"safe-mode": None}
r = httpx.get("https://v2.jokeapi.dev/joke/ANY", params=params)

# OUTPUT:
# https://v2.jokeapi.dev/joke/ANY?safe-mode=

params = {"safe-mode": ""}
r = httpx.get("https://v2.jokeapi.dev/joke/ANY", params=params)

# OUTPUT:
# https://v2.jokeapi.dev/joke/ANY?safe-mode=

In both cases, the parameter is appended with an =, and this syntax is not valid in the Joke API. Calling the endpoint https://v2.jokeapi.dev/joke/DARK?safe-mode properly filters out the unsafe jokes, but calling https://v2.jokeapi.dev/joke/DARK?safe-mode= with the appended = does not.

On top of this, manually adding safe-mode to the url doesn't work either since httpx will overwrite any existing query parameters.

params = {"type": "SINGLE"}
r = httpx.get("https://v2.jokeapi.dev/joke/ANY?safe-mode", params=params)

# OUTPUT
# https://v2.jokeapi.dev/joke/ANY?type=SINGLE

A possible solution is to create the url ourselves with something like

params = {
    "type": data.type,
    "blacklistFlags": "+".join(data.flags),
    "safe-mode": None
}
formatted_params = "&".join([k if v is None else f"{k}"="{v}" for k, v in params.items()])

with Client() as client:
    response = client.get("https://v2.jokeapi.dev/joke/{data.category}?{formatted_params}")

^ in this case the params can't be added to the client either because it will automatically format them, removing any parameters without an =.

Write Better Tests

The current tests were made with the simple idea "any tests are better than no tests", and they match that description. They're not great. They can and should be improved.

Submit jokes with the CLI

The JokeAPI is not only capable of getting jokes, you can also create new jokes. It would be interesting if the CLI was extended to also add jokes using the submit endpoint.

In order to do this we would have to update the current CLI command, possibly by using the @click.group() decorator like this:

@click.group()
def jokes():
    ...

@jokes.command() # @jokes not @click
def get():
    ...

@jokes.command() # @jokes not @click
def add():
    ...

Steps

  • Split main method into multiple commands (jokes and add), making jokes the group command
  • Add new submit request and corresponding command
  • Add tests for submit command
  • Profit ๐Ÿฅณ

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.