๐Ÿ—ป James Van Dyne

โœˆ๏ธTrips ๐Ÿ—บ๏ธMaps โœ๏ธ๏ธBlog ๐Ÿ”—๏ธ๏ธLinks ๐ŸƒRuns ๐Ÿ‘‰Now
  • ๐ŸกHome
  • โœˆ๏ธTrips
  • ๐Ÿ—บ๏ธMaps
  • โœ๏ธBlog
  • ๐Ÿ”—๏ธLinks
  • ๐ŸƒRuns
  • ๐Ÿ‘‰Now
  • โœ๏ธArticles
  • ๐Ÿ“ค๏ธReplies
  • ๐Ÿ’ฌStatus
  • ๐Ÿ”–๏ธ๏ธBookmarks
  • ๐Ÿ—บCheckins
  • ๐Ÿ“…The Week
  • ๐Ÿ–ฅTech
  • ๐ŸŒฒSustainability
  • ๐ŸƒRunning
  • ๐Ÿง Thoughts
  • ๐Ÿ‡ฏ๐Ÿ‡ตJapan
  • ๐Ÿ’กTIL
  • โ›ฐTanzawa
  • ๐ŸกHome
  • โœ๏ธArticles
  • ๐Ÿ“ค๏ธReplies
  • ๐Ÿ’ฌStatus
  • ๐Ÿ”–๏ธ๏ธBookmarks
  • ๐Ÿ—บCheckins
  • ๐Ÿ“…The Week
  • ๐Ÿ–ฅTech
  • ๐ŸŒฒSustainability
  • ๐ŸƒRunning
  • ๐Ÿง Thoughts
  • ๐Ÿ‡ฏ๐Ÿ‡ตJapan
  • ๐Ÿ’กTIL
  • โ›ฐTanzawa
  • Checkin to Starbucks

    Starbucks 35.40118652886334 139.5348873662265
    Nov 16, 2019
    by James
    in Yokohama, Kanagawa, Japan
    Used to come to this Starbucks almost everyday when I was an exchange student. Old haunts.
    ๐Ÿ”—permalink
  • Unit Testing django-graphene GraphQL endpoints with pytest

    Nov 13, 2019
    by James

    On a project at work I've been learning GraphQL. I'm in charge of both developing the backend ( using the wonderful graphene-django package) and the frontend ( using Typescript / Vue.js / axios ) for this specific feature.

    After wrapping my head around GraphQL and getting a basic endpoint working I wanted to write some tests to ensure that filtering and other requirements are working as expected.

    For a proper End-to-end test I'd usually setup a client and post a json dictionary or such. With End-to-end GraphQL tests you need to send actual GraphQL queries, which makes sense but it feels a bit like SQL Injection.

    Below is how I've settled organizing and writing my GraphQL tests.

    tests/
    โ”œโ”€โ”€ __init__.py
    โ”œโ”€โ”€ conftest.py
    โ”œโ”€โ”€ test_myapp/
    โ”‚ย ย  โ””โ”€โ”€ test_schema.py

    Because the graphql client will be reused across the django site, I added a global fixture that will automatically load mty project's schema.

    # tests/conftest.py
    @pytest.fixture
    def graphql_client():
    from myproject.schema import schema
    from graphene.test import Client
    return Client(schema)

    In this example I'm testing that I'm filtering data as expected when passing a search parameter.

    For setup, first I write a query as its own fixture so I can re-use it throughout the test and it's clear exactly what is going to be run. Second, I make sure the query uses variables instead of hard-coded values when querying so I can change the input depending on the test. Third, setup a model_bakery fixture for data that I expect to find.

    import pytest
    from model_bakery import baker

    @pytest.mark.django_db
    class TestMyModelData:
    @pytest.fixture
    def query(self):
    return """
    query testGetMyModel($searchParam: String!){
    myModelData(searchParam: $searchParam) {
    totalCount
    }
    }"""

    @pytest.fixture
    def my_model(self):
    baker.make(
    "myapp.MyModel",
    total_count="20", # Decimal field
    )

    def test_none_response(self, graphql_client, query, my_model):
    executed = graphql_client.execute(query, variables={"searchParam": "skittles"})
    assert executed == {"data": {"myModelData": None}}

    def test_filters_usage(self, graphql_client, query, my_model):
    params = {"searchParam": "skittles"}
    executed = graphql_client.execute(query, variables=params)
    assert executed == {
    "data": {
    "myModelData": {
    "totalCount": 20
    }
    }
    }

    Executing each test I simply pass my query and required variables for the test/query. In this I'm testing the same query twice: once with and one without a searchParameter. My expectation is that I get no results without a search term and data when to my graphql_client fixture.

    As the return value from our client is a dictionary, I can simply assert my expecte results with the actual results. If something changes I'll know immediately.

    Using the techniques above I can easily add new tests for my GraphQL endpoint as the available changes or bugs are found.

    ๐Ÿ”—permalink
  • Nov 12, 2019
    by James

    Fuji looking grand tonight. Autumn Fuji is the best.

    ๐Ÿ”—permalink
  • Checkin to KUA`AINA

    KUA`AINA 35.4525303291549 139.643101809736
    Nov 10, 2019
    by James
    in Yokohama, Kanagawa, Japan
    Avocado Cheddar burger!
    ๐Ÿ”—permalink
  • Nov 10, 2019
    by James

    Checked in at Kua 'Aina (KUA`AINA). Avocado Cheddar burger!

    ๐Ÿ”—permalink
  • Nov 07, 2019
    by James

    Did a presentation at work today about editing PDFs with Python. Mixing and matching libraries is fast, but youโ€™ll run into a bunch of inefficiencies that result in slow processing and huge files. I should write a book. For serious.

    ๐Ÿ”—permalink
  • Nov 04, 2019
    by James

    Checked in at COPEN LOCAL BASE KAMAKURA. Burritos!

    ๐Ÿ”—permalink
  • Checkin to COPEN LOCAL BASE KAMAKURA

    COPEN LOCAL BASE KAMAKURA 35.31605084574534 139.5499748699059
    Nov 04, 2019
    by James
    in Kamakura, Kanagawa, Japan
    Burritos!
    ๐Ÿ”—permalink
  • Nov 04, 2019
    by James

    Checked in at Tsurugaoka Hachimangu (้ถดๅฒกๅ…ซๅนกๅฎฎ)

    ๐Ÿ”—permalink
  • Checkin to Tsurugaoka Hachimangu (้ถดๅฒกๅ…ซๅนกๅฎฎ)

    Tsurugaoka Hachimangu (้ถดๅฒกๅ…ซๅนกๅฎฎ) 35.32494983672849 139.5557226240635
    Nov 04, 2019
    by James
    in Kamakura, Kanagawa, Japan
    ๐Ÿ”—permalink
Previous 202 of 369 Next
Reply by email
Powered by
๐Ÿ”Tanzawa

โ† An IndieWeb Webring ๐Ÿ•ธ๐Ÿ’โ†’
Photo of James Van Dyne James Van Dyne Japan

Web developer living in Japan.