def test_query_events_image(rf, graphql_client, conference_factory, event_factory): now = timezone.now() request = rf.get("/") conference = conference_factory(start=now, end=now + timezone.timedelta(days=3)) event = event_factory(conference=conference, latitude=1, longitude=1) resp = graphql_client.query( """query($code: String!) { conference(code: $code) { events { image } } }""", variables={"code": conference.code}, ) assert not resp.get("errors") assert len(resp["data"]["conference"]["events"]) == 1 events = resp["data"]["conference"]["events"] events[0]["image"] == get_image_url_from_request(request, event.image)
def test_get_conference_keynotes_without_topic( conference_factory, keynote_factory, keynote_speaker_factory, graphql_client, rf, ): conference = conference_factory() keynote = keynote_factory(title=LazyI18nString({ "en": "title", "it": "titolo" }), conference=conference) speaker = keynote_speaker_factory(keynote=keynote) resp = graphql_client.query( """ query($code: String!) { conference(code: $code) { keynotes { title(language: "en") topic { id name } speakers { name photo } } } } """, variables={"code": conference.code}, ) assert "errors" not in resp assert len(resp["data"]["conference"]["keynotes"]) == 1 keynote_data = resp["data"]["conference"]["keynotes"][0] assert keynote_data["title"] == "title" assert keynote_data["topic"] is None assert len(keynote_data["speakers"]) == 1 req = rf.get("/") assert { "name": speaker.name, "photo": get_image_url_from_request(req, speaker.photo), } in keynote_data["speakers"]
def test_query_blog_posts(rf, graphql_client, user_factory, post_factory): past_post = post_factory(published=timezone.now() - timedelta(days=1), image=None) present_post = post_factory() request = rf.get("/") post_factory(published=timezone.now() + timedelta(days=1)) resp = _query_blog_posts(graphql_client) assert len(resp["data"]["blogPosts"]) == 2 assert { "id": str(past_post.id), "title": str(past_post.title), "slug": str(past_post.slug), "excerpt": str(past_post.excerpt), "content": str(past_post.content), "published": past_post.published.isoformat(), "image": get_image_url_from_request(request, past_post.image), "author": { "id": str(past_post.author_id) }, } == resp["data"]["blogPosts"][1] assert { "id": str(present_post.id), "title": str(present_post.title), "slug": str(present_post.slug), "excerpt": str(present_post.excerpt), "content": str(present_post.content), "published": present_post.published.isoformat(), "image": get_image_url_from_request(request, present_post.image), "author": { "id": str(present_post.author_id), }, } == resp["data"]["blogPosts"][0]
def test_get_image(graphql_client, conference_factory, schedule_item_factory, rf): request = rf.get("/") now = timezone.now() conference = conference_factory(start=now, end=now + timezone.timedelta(days=3)) conference_b = conference_factory(start=now, end=now + timezone.timedelta(days=3)) schedule_item = schedule_item_factory(conference=conference) schedule_item_factory(conference=conference_b, image=None) resp = graphql_client.query( """ query($code: String!) { conference(code: $code) { schedule { image } } } """, variables={"code": conference.code}, ) assert not resp.get("errors") assert resp["data"]["conference"]["schedule"] == [{ "image": get_image_url_from_request(request, schedule_item.image) }] resp = graphql_client.query( """ query($code: String!) { conference(code: $code) { schedule { image } } } """, variables={"code": conference_b.code}, ) assert not resp.get("errors") assert resp["data"]["conference"]["schedule"] == [{"image": None}]
def test_query_single_post(rf, graphql_client, user_factory, post_factory): request = rf.get("/") post = post_factory( slug=LazyI18nString({ "en": "demo", "it": "esempio" }), published=timezone.now() - timedelta(days=1), image=None, ) resp = graphql_client.query("""query { blogPost(slug: "demo") { id title slug excerpt content published image author { id } } } """) assert { "id": str(post.id), "title": str(post.title), "slug": str(post.slug), "excerpt": str(post.excerpt), "content": str(post.content), "published": post.published.isoformat(), "image": get_image_url_from_request(request, post.image), "author": { "id": str(post.author_id) }, } == resp["data"]["blogPost"] resp = graphql_client.query("""query { blogPost(slug: "donut") { id } } """) assert resp["data"]["blogPost"] is None
def test_query_job_board(rf, graphql_client, job_listing_factory): listing = job_listing_factory() request = rf.get("/") resp = _query_job_board(graphql_client) assert len(resp["data"]["jobListings"]) == 1 assert { "id": str(listing.id), "title": str(listing.title), "slug": str(listing.slug), "description": str(listing.description), "company": str(listing.company), "companyLogo": get_image_url_from_request(request, listing.company_logo), "applyUrl": str(listing.apply_url), } == resp["data"]["jobListings"][0]