def test_retrieve_conference(self): query = ''' query { conference { name nameKo nameEn conferenceStartedAt conferenceFinishedAt sprintStartedAt sprintFinishedAt tutorialStartedAt tutorialFinishedAt } } ''' expected = { 'conference': { 'name': '파이콘 한국 2019', 'nameKo': '파이콘 한국 2019', 'nameEn': 'Pycon Korea 2019', 'conferenceStartedAt': '2019-08-17', 'conferenceFinishedAt': '2019-08-18', 'sprintStartedAt': '2019-08-15', 'sprintFinishedAt': '2019-08-16', 'tutorialStartedAt': '2019-08-15', 'tutorialFinishedAt': '2019-08-16' } } result = schema.execute(query) actual = loads(dumps(result.data)) self.assertDictEqual(actual, expected)
def test_me(self): # Given user = UserModel(username='******') user.save() user.profile.name_ko = '파이콘 천사' user.profile.name_en = 'pycon_angel' user.profile.bio_ko = '파이콘 천사입니다.' user.profile.bio_en = "I'm pycon angel." user.profile.email = '*****@*****.**' user.profile.phone = '222-2222-2222' user.profile.organization = '좋은회사' user.profile.nationality = '우리나라' user.save() request = generate_request_authenticated(user) # When result = schema.execute(PROFILE_QUERY, context_value=request) expected = { 'profile': { 'nameKo': '파이콘 천사', 'nameEn': 'pycon_angel', 'bioKo': '파이콘 천사입니다.', 'bioEn': "I'm pycon angel.", 'email': '*****@*****.**', 'phone': '222-2222-2222', 'organization': '좋은회사', 'nationality': '우리나라', } } # Then actual = loads(dumps(result.data)) self.assertIsNotNone(actual) self.assertDictEqual(actual, expected)
def test_get_all_pastes(self): p1 = PasteFactory(visibility='public') p2 = PasteFactory(visibility='public') query = ''' query { pastes { edges { node { name visibility content } } } } ''' result = schema.execute(query) assert not result.errors assert { 'node': { 'name': p1.name, 'visibility': p1.visibility, 'content': p1.content, }, } in result.data['pastes']['edges'] assert { 'node': { 'name': p2.name, 'visibility': p2.visibility, 'content': p2.content, }, } in result.data['pastes']['edges']
def test_pastes_doesnt_expose_unlisted_pastes(self): public = PasteFactory(visibility='public') unlisted = PasteFactory(visibility='unlisted') query = ''' query { pastes { edges { node { name visibility } } } } ''' result = schema.execute(query) assert not result.errors assert len(result.data['pastes']['edges']) == 1 assert { 'node': { 'name': public.name, 'visibility': public.visibility, }, } in result.data['pastes']['edges'] assert { 'node': { 'name': unlisted.name, 'visibility': unlisted.visibility, }, } not in result.data['pastes']['edges']
def test_should_not_retrieve_unaccepted_presentation_to_anonymous(self): request = generate_request_anonymous() # When result = schema.execute(PRESENTATION_QUERY, context_value=request) # Then actual = loads(dumps(result.data)) self.assertEqual(1, len(actual['presentations']))
def test_retrieve_unaccepted_presentation_to_only_owner(self): user = UserModel.objects.create(username='******') user.save() request = generate_request_authenticated(user) # When result = schema.execute(PRESENTATION_QUERY, context_value=request) # Then actual = loads(dumps(result.data)) self.assertEqual(1, len(actual['presentations']))
def test_update_profile(self): # Given mutation = ''' mutation UpdateProfile($profileInput: ProfileInput!) { updateProfile(profileInput: $profileInput) { profile { nameKo nameEn bioKo bioEn phone email organization nationality } } } ''' variables = { 'profileInput': { 'nameKo': '코니', 'nameEn': 'Coni', 'bioKo': '파이콘 한국을 참석하고 있지요', 'bioEn': 'PyCon Korea Good', 'phone': '010-1111-1111', 'email': '*****@*****.**', 'organization': '파이콘!', 'nationality': '미국', } } expected = { 'updateProfile': { 'profile': { **variables['profileInput'] } } } user = UserModel(username='******', email='*****@*****.**') user.save() request = generate_request_authenticated(user) result = schema.execute( mutation, variables=variables, context_value=request) # Then actual = loads(dumps(result.data)) self.assertIsNotNone(actual) self.assertDictEqual(actual, expected)
def test_create_presentation_only_name(self): mutation = ''' mutation CreatePresentation($presentationInput: PresentationInput!, $categoryId: Int, $difficultyId: Int) { createPresentation(presentationInput: $presentationInput, categoryId: $categoryId, difficultyId: $difficultyId) { presentation { id nameKo nameEn } } } ''' variables = { 'presentationInput': { 'nameKo': '흥미로운 GraphQL', 'nameEn': 'Interesting GraphQL', } } expected = { 'createPresentation': { 'presentation': { **variables['presentationInput'], } } } user = UserModel(username='******', email='*****@*****.**') user.save() request = generate_request_authenticated(user) # When result = schema.execute(mutation, variables=variables, context_value=request) # Then actual = loads(dumps(result.data)) self.assertIsNotNone(actual) self.assertIsNotNone( actual['createPresentation']['presentation']['id']) del actual['createPresentation']['presentation']['id'] self.assertDictEqual(actual, expected)
def test_retrieve_sponsor(self): query = ''' query { sponsors { nameKo nameEn descKo descEn url level { name price ticketCount } paidAt } } ''' expected = { 'nameKo': '파이콘한국', 'nameEn': 'Pycon Korea', 'descKo': '파이콘 한국입니다', 'descEn': 'we are pycon korea', 'url': 'http://pythonkr/1', 'level': { 'name': '키스톤', 'price': 20000000, 'ticketCount': 20 }, 'paidAt': datetime(2019, 8, 21, 13, 00).astimezone(tz=TIMEZONE).isoformat(), } result = schema.execute(query) actual = loads(dumps(result.data)) self.assertIn('sponsors', actual) self.assertDictEqual(actual['sponsors'][0], expected)
def test_pastes_are_ordered_by_modified(self): p1 = PasteFactory(visibility='public') p2 = PasteFactory(visibility='public') query = ''' query { pastes { edges { node { name } } } } ''' result = schema.execute(query) assert not result.errors fs = sorted([p1, p2], key=sortByModified) fs.reverse() s = sorted(fs, key=sortByCreated) s.reverse() assert { 'node': { 'name': s[0].name, }, } == result.data['pastes']['edges'][0] assert { 'node': { 'name': s[1].name, }, } == result.data['pastes']['edges'][1]
def test_get_paste_owner_info(self): paste = PasteFactory(visibility='public') query = ''' query { pastes { edges { node { name owner { username } } } } } ''' result = schema.execute(query) assert not result.errors assert ( result.data['pastes']['edges'][0]['node']['owner']['username'] == paste.owner.username )
def test_me_anonymous(self): request = generate_request_anonymous() # When actual = schema.execute(PROFILE_QUERY, context_value=request) self.assertIsNotNone(actual.errors) self.assertIsInstance(actual.errors[0].original_error, PermissionDenied)
def test_create_presentation(self): mutation = ''' mutation CreatePresentation($presentationInput: PresentationInput!, $categoryId: Int, $difficultyId: Int) { createPresentation(presentationInput: $presentationInput, categoryId: $categoryId, difficultyId: $difficultyId) { presentation { id nameKo nameEn descKo descEn language submitted slideUrl pdfUrl videoUrl recordable category { id } difficulty { id } } } } ''' variables = { 'categoryId': 1, 'difficultyId': 1, 'presentationInput': { 'nameKo': '흥미로운 GraphQL', 'nameEn': 'Interesting GraphQL', 'descKo': 'GraphQL은 재미있다는 설명!', 'descEn': 'The description that GraphQL is fun', 'language': 'KOREAN', 'submitted': True, 'slideUrl': 'my.slide.url', 'pdfUrl': 'my.pdf.url', 'videoUrl': 'my.video.url', 'recordable': True } } expected = { 'createPresentation': { 'presentation': { **variables['presentationInput'], 'category': { 'id': '1' }, 'difficulty': { 'id': '1' } } } } user = UserModel(username='******', email='*****@*****.**') user.save() request = generate_request_authenticated(user) # When result = schema.execute(mutation, variables=variables, context_value=request) # Then actual = loads(dumps(result.data)) self.assertIsNotNone(actual) self.assertIsNotNone( actual['createPresentation']['presentation']['id']) del actual['createPresentation']['presentation']['id'] self.assertDictEqual(actual, expected)
def test_retrieve_presentation(self): # Given expected = { 'name': '작성중인 발표', 'nameKo': '작성중인 발표', 'nameEn': 'Before submitting', 'desc': '작성중인 발표입니다.', 'descKo': '작성중인 발표입니다.', 'descEn': 'It is onprogress presentation', 'price': 0, 'visible': False, 'language': 'KOREAN', 'owner': { 'username': '******' }, 'accepted': False, 'place': { 'name': '101' }, 'startedAt': datetime(2019, 8, 21, 13, 00).astimezone(tz=TIMEZONE).isoformat(), 'finishedAt': datetime(2019, 8, 21, 15, 00).astimezone(tz=TIMEZONE).isoformat(), 'category': { 'name': 'Web Service', 'nameKo': 'Web Service', 'nameEn': 'Web Service', 'slug': 'web_service', 'visible': True }, 'slideUrl': 'https://slide/1', 'pdfUrl': 'https://pdf/1', 'videoUrl': 'https://video/1', 'difficulty': { 'name': '초급', 'nameKo': '초급', 'nameEn': 'Beginner' }, 'recordable': True } user = UserModel.objects.get(username='******') request = generate_request_authenticated(user) # When result = schema.execute(PRESENTATION_QUERY, context_value=request) # Then actual = loads(dumps(result.data)) self.assertIn('presentations', actual) self.assertDictEqual(actual['presentations'][0], expected)
def test_retrieve_schedule(self): query = ''' query { schedule { name nameKo nameEn conferenceStartAt conferenceFinishAt tutorialStartAt tutorialFinishAt sprintStartAt sprintFinishAt keynoteRecommendationStartAt keynoteRecommendationFinishAt keynoteRecommendationAnnounceAt presentationProposalStartAt presentationProposalFinishAt presentationReviewStartAt presentationReviewFinishAt presentationAnnounceAt tutorialProposalStartAt tutorialProposalFinishAt tutorialProposalAnnounceAt tutorialTicketStartAt tutorialTicketFinishAt sprintProposalStartAt sprintProposalFinishAt sprintProposalAnnounceAt sprintTicketStartAt sprintTicketFinishAt sponsorProposalStartAt sponsorProposalFinishAt volunteerRecruitingStartAt volunteerRecruitingFinishAt volunteerAnnounceAt lightningTalkProposalStartAt lightningTalkProposalFinishAt lightningTalkAnnounceAt earlybirdTicketStartAt earlybirdTicketFinishAt financialAidStartAt financialAidFinishAt financialAidAnnounceAt patronTicketStartAt patronTicketFinishAt conferenceTicketStartAt conferenceTicketFinishAt childcareTicketStartAt childcareTicketFinishAt youngcoderTicketStartAt youngcoderTicketFinishAt } } ''' result = schema.execute(query) response_schedule = result.data['schedule'] self.assertIsNotNone(response_schedule) self.assertEqual('파이콘 한국 2019', response_schedule['nameKo']) self.assertEqual('PyCon Korea 2019', response_schedule['nameEn'])