def test_refine_words(client): testuser_login(client) words = ['apple', 'apple', 'Cup', 'cup', 'shorts', 'Hat'] result_words = WordTranslate.refine_words(words) assert result_words == ['apple', 'cup', 'shorts', 'hat']
def test_basic_study_view(client): testuser_login(client) response = client.get('/study/') assert '다음' in response.content.decode('utf-8') assert '답 확인' in response.content.decode('utf-8') assert '제거' in response.content.decode('utf-8')
def test_study_view_from_only_own_word_list(client): testuser_login(client) another = User.objects.get(username='******') words = Word.alive_objects.filter(user=another) for i in range(20): for word in words: response = client.get('/study/') assert word.question not in response.content.decode('utf-8')
def test_view_words(client): testuser_login(client) response = client.get('/words/') owner = User.objects.get(username='******') words = Word.alive_objects.filter(user=owner) for word in words: assert word.question in response.content.decode('utf-8') assert word.answer in response.content.decode('utf-8')
def test_study_api_from_only_own_word_list(client): testuser_login(client) another = User.objects.get(username='******') words = Word.alive_objects.filter(user=another) for i in range(20): for word in words: response = client.get('/study/next/') response_data = json.loads(response.content) assert word.question != response_data['answer']
def test_study_api(client): testuser_login(client) response = client.get('/study/next/') response_data = json.loads(response.content) assert response.status_code == 200 word = Word.objects.get(question=response_data['question']) assert word.answer == response_data['answer'] assert word.id == response_data['id']
def test_confirm_deleted_word(client): testuser_login(client) word = Word.objects.get(question='사과') response = client.get('/words/deleted/') assert word.question not in response.content.decode('utf-8') client.post('/words/%d/delete/' % word.id) response = client.get('/words/deleted/') assert word.question in response.content.decode('utf-8')
def test_show_only_own_words(client): testuser_login(client) response = client.get('/words/') owner = User.objects.get(username='******') another = User.objects.get(username='******') for word in Word.alive_objects.filter(user=owner): assert word.question in response.content.decode('utf-8') for word in Word.alive_objects.filter(user=another): assert word.question not in response.content.decode('utf-8')
def test_restore_deleted_word(client): testuser_login(client) word = Word.objects.get(question='사과') client.post('/words/%d/delete/' % word.id) word = Word.objects.get(question='사과') assert word.is_deleted is True client.post('/words/%d/restore/' % word.id) word = Word.objects.get(question='사과') assert word.is_deleted is False
def test_delete_word(client): testuser_login(client) word = Word.objects.get(question='사과') word_list_response = client.get('/words/') assert '사과' in word_list_response.content.decode('utf-8') response = client.post('/words/%d/delete/' % word.id) assert json.loads(response.content)['result'] == 'True' delete_word = Word.objects.get(question='사과') assert delete_word.is_deleted is True word_list_response = client.get('/words/') assert '사과' not in word_list_response.content.decode('utf-8')
def test_make_a_test_when_studystatus_are_chosen(client): user = testuser_login(client, 'test2') user.studystatus.question_type = 'W' user.save() response = client.get('/study/test/?num=All') response_data = json.loads(response.content) test_word_list = response_data['testWordList'] words = Word.alive_objects.filter(user__username='******').filter( question_type='W') assert len(test_word_list) == len(words) test_question_list = [] for test_word in test_word_list: test_question_list.append(test_word['question']) for word in words: assert word.question in test_question_list user.studystatus.question_type = 'S' user.save() response = client.get('/study/test/?num=1') response_data = json.loads(response.content) test_word_list = response_data['testWordList'] word = Word.alive_objects.filter(user__username='******').filter( question_type='S').order_by('created_time').last() assert len(test_word_list) == 1 assert word.question == test_word_list[0]['question']
def test_pick_all_of_word_when_making_a_test(client): testuser_login(client, 'test2') response = client.get('/study/test/?num=All') response_data = json.loads(response.content) test_word_list = response_data['testWordList'] words = Word.alive_objects.filter(user__username='******') assert len(test_word_list) == len(words) test_question_list = [] for test_word in test_word_list: test_question_list.append(test_word['question']) for word in words: assert word.question in test_question_list
def test_check_error_when_there_are_only_words(client): user = testuser_login(client) user.studystatus.question_type = 'S' user.save() response = client.get('/study/next/') response_data = json.loads(response.content) assert response_data['errorType'] == 'NotExist' user2 = testuser_login(client, 'test2') user2.studystatus.question_type = 'S' user2.save() response = client.get('/study/next/') response_data = json.loads(response.content) assert 'errorType' not in response_data
def test_study_words_chosen_by_days(client): test_user = testuser_login(client, 'empty_words_test') words = [] words.append( Word.objects.create(question='오늘 단어', answer="today's word", user_id=test_user.id)) words.append( Word.objects.create(question='1일 전 단어', answer='words a day ago', user_id=test_user.id)) words.append( Word.objects.create(question='2일 전 단어', answer='words two days ago', user_id=test_user.id)) words.append( Word.objects.create(question='3일 전 단어', answer='words tree days ago', user_id=test_user.id)) for idx, word in enumerate(words): word.created_time = word.created_time - timedelta(days=idx) word.save() for i in range(4): test_user.studystatus.chosen_days = i test_user.save() response = client.get('/study/next/') response_data = json.loads(response.content) chosen_questions = [word.question for word in words[:(i + 1)]] assert response_data['question'] in chosen_questions
def test_prounce(client): testuser_login(client) question = 'i am a boy' response = client.post('/pronounce/', { 'question': question, }) response_data = json.loads(response.content) assert response.status_code == 200 file_name = 'pronounce_' + question + '.mp3' assert response_data['file_name'] == file_name file_path = os.path.join(settings.MEDIA_ROOT, file_name) assert os.path.isfile(file_path) is True
def test_en_en_dictionary_only_work_with_english_word_question(client): testuser_login(client) response = client.post('/translate/', { 'question': '에이스', }) response_data = json.loads(response.content) assert response_data['oxford_dictionary_result'] is None response = client.post('/translate/', { 'question': 'i am a boy.', }) response_data = json.loads(response.content) assert response_data['oxford_dictionary_result'] is None
def test_show_only_own_deleted_words(client): testuser_login(client) word = Word.objects.get(question='사과') client.post('/words/%d/delete/' % word.id) response = client.get('/words/deleted/') owner = User.objects.get(username='******') another = User.objects.get(username='******') for word in Word.objects.filter(user=owner, is_deleted=True): assert word.question in response.content.decode('utf-8') for word in Word.objects.filter(user=another, is_deleted=True): assert word.question not in response.content.decode('utf-8')
def test_add_word(client): testuser_login(client, 'test2') response = client.get('/words/add/') assert 'Question' in response.content.decode('utf-8') assert 'Answer' in response.content.decode('utf-8') client.post('/words/add/', { 'question': '노트북', 'answer': 'laptop', }) word = Word.objects.get(question='노트북') assert word.answer == 'laptop' assert word.user.username == 'test2'
def test_study_only_sentences(client): user = testuser_login(client, 'test2') user.studystatus.question_type = 'S' user.save() for i in range(20): response = client.get('/study/next/') response_data = json.loads(response.content) assert is_sentence(response_data['question']) is True
def test_make_a_test_according_to_number(client): testuser_login(client, 'test2') for i in range(1, 11): client.post('/words/add/', { 'question': '단어' + str(i), 'answer': 'word' + str(i), }) response = client.get('/study/test/?num=4') response_data = json.loads(response.content) test_word_list = response_data['testWordList'] assert len(test_word_list) == 4 question_list = [] for i in range(7, 11): question_list.append('단어' + str(i)) for word in test_word_list: assert word['question'] in question_list test_question_list = [] for word in test_word_list: test_question_list.append(word['question']) assert len(set(test_question_list)) == len(test_question_list) response = client.get('/study/test/?num=7') response_data = json.loads(response.content) test_word_list = response_data['testWordList'] assert len(test_word_list) == 7 question_list = [] for i in range(4, 11): question_list.append('단어' + str(i)) for word in test_word_list: assert word['question'] in question_list test_question_list = [] for word in test_word_list: test_question_list.append(word['question']) assert len(set(test_question_list)) == len(test_question_list)
def test_distinguish_question_type_when_adding(client): testuser_login(client, 'test2') client.post('/words/add/', { 'question': '단어', 'answer': 'word', }) word = Word.objects.get(question='단어', answer='word') assert word.question_type == 'W' client.post('/words/add/', { 'question': '이것은 문장입니다.', 'answer': 'This is a sentence.', }) word = Word.objects.get(question='이것은 문장입니다.', answer='This is a sentence.') assert word.question_type == 'S'
def test_edit_word(client): testuser_login(client, 'test2') client.post('/words/add/', { 'question': 'sarcastic', 'answer': '비고는', }) word = Word.objects.get(question='sarcastic', answer='비고는') response = client.post('/words/%d/edit/' % word.id, { 'question': 'sarcastic', 'answer': '비꼬는', }) assert response.status_code == 200 edited_word = Word.objects.get(id=word.id) assert edited_word.answer == '비꼬는'
def test_random_order_in_making_a_test(client): testuser_login(client, 'test2') ordered_word_list = [] for i in range(1, 5): client.post('/words/add/', { 'question': '단어' + str(i), 'answer': 'word' + str(i), }) ordered_word_list.append({ 'question': '단어' + str(i), 'answer': 'word' + str(i), }) response = client.get('/study/test/?num=4') response_data = json.loads(response.content) test_word_list = response_data['testWordList'] assert ordered_word_list != test_word_list
def test_get_progress_of_study(client): user = testuser_login(client, 'test2') total_words_num = Word.objects.filter(user=user).count() remained_words_num = Word.alive_objects.filter(user=user).count() response = client.get('/study/progress/') response_data = json.loads(response.content) assert response_data['totalNumberOfWords'] == total_words_num assert response_data[ 'studiedNumberOfWords'] == total_words_num - remained_words_num
def test_translate_api_ko_to_en(client): testuser_login(client) response = client.post('/translate/', { 'question': '번역', }) response_data = json.loads(response.content) assert response.status_code == 200 assert response_data['papago_translation_result'] == 'translation' assert response_data['glosbe_translation_result'][0] == 'translation' assert response_data['glosbe_translation_result'][1] == 'version' response = client.post('/translate/', { 'question': '과일', }) response_data = json.loads(response.content) assert response.status_code == 200 assert response_data['papago_translation_result'] == 'Fruit' assert response_data['glosbe_translation_result'][0] == 'fruit'
def test_translate_api_en_to_ko(client): testuser_login(client) response = client.post('/translate/', { 'question': 'nurse', }) response_data = json.loads(response.content) assert response.status_code == 200 assert response_data['papago_translation_result'] == '간호사.' assert '간호원' in response_data['glosbe_translation_result'] assert '간호사' in response_data['glosbe_translation_result'] response = client.post('/translate/', { 'question': 'i am a boy', }) response_data = json.loads(response.content) assert response.status_code == 200 assert response_data['papago_translation_result'] == '나는 소년 입니다.' assert response_data['glosbe_translation_result'] is None
def test_change_question_type(client): user = testuser_login(client) assert user.studystatus.question_type == 'A' response = client.post('/accounts/studystatus/update-question-type/', { 'question_type': 'S' }) response_data = json.loads(response.content) assert response_data['result'] == 'Success' user = User.objects.get(username='******') assert user.studystatus.question_type == 'S'
def test_en_en_dictionary_api(client): testuser_login(client) response = client.post('/translate/', { 'question': 'ace', }) response_data = json.loads(response.content) assert response_data['oxford_dictionary_result'][0]['definitions'][0] == \ 'a playing card with a single spot on it, ranked as the highest card in its suit in most card games' assert response_data['oxford_dictionary_result'][0]['examples'][0] == \ 'life had started dealing him aces again' assert response_data['oxford_dictionary_result'][0]['examples'][1] == \ 'the ace of diamonds' assert response_data['oxford_dictionary_result'][1]['definitions'][0] == \ 'a person who excels at a particular sport or other activity' assert response_data['oxford_dictionary_result'][1]['examples'][0] == \ 'a motorcycle ace'
def test_if_there_is_no_word_in_chosen_period(client): test_user = testuser_login(client, 'empty_words_test') word = Word.objects.create(question='오늘 단어', answer="today's word", user_id=test_user.id) word.created_time = word.created_time - timedelta(days=3) word.save() test_user.studystatus.chosen_days = 1 test_user.save() response = client.get('/study/next/') assert response.status_code == 200 response_data = json.loads(response.content) assert response_data['errorType'] == 'NotExist'
def test_get_studystatus(client): user = testuser_login(client) response = client.get('/accounts/studystatus/') response_data = json.loads(response.content) assert response_data['question_type'] == 'A' assert response_data['chosen_days'] == -1 user.studystatus.question_type = 'S' user.studystatus.chosen_days = 15 user.save() response = client.get('/accounts/studystatus/') response_data = json.loads(response.content) assert response_data['question_type'] == 'S' assert response_data['chosen_days'] == 15