def test_sync_now_endpoint_returns_correct_json(self): responses.add( responses.GET, "https://www.wanikani.com/api/user/{}/user-information".format( self.user.profile.api_key), json=sample_api_responses. user_information_response_with_higher_level, status=200, content_type="application/json") responses.add(responses.GET, build_API_sync_string_for_user_for_levels( self.user, [5, 17]), json=sample_api_responses.single_vocab_response, status=200, content_type='application/json') test = build_API_sync_string_for_user_for_levels(self.user, [5, 17]) response = self.client.post(reverse("api:user-sync"), data={"full_sync": "true"}) correct_response = { "new_review_count": 0, "profile_sync_succeeded": True, "new_synonym_count": 0 } self.assertJSONEqual(str(response.content, encoding='utf8'), correct_response)
def mock_vocab_list_response_with_single_vocabulary(user): responses.add(responses.GET, build_API_sync_string_for_user_for_levels( user, user.profile.level), json=sample_api_responses.single_vocab_response, status=200, content_type='application/json')
def mock_vocab_list_response_with_single_vocabulary_with_changed_meaning(user): responses.add( responses.GET, build_API_sync_string_for_user_for_levels(user, [user.profile.level]), json=sample_api_responses.single_vocab_response_with_changed_meaning, status=200, content_type="application/json", )
def test_building_unlock_all_string_works(self): sample_level = constants.LEVEL_MAX api_string = build_API_sync_string_for_user_for_levels(self.user, [level for level in range(1, sample_level + 1)]) expected = ",".join([str(level) for level in range(1, sample_level + 1)]) self.assertTrue(expected in api_string)
def mock_vocab_list_response_with_single_vocabulary(user): responses.add( responses.GET, build_API_sync_string_for_user_for_levels(user, user.profile.level), json=sample_api_responses.single_vocab_response, status=200, content_type="application/json", )
def test_building_unlock_all_string_works(self): sample_level = constants.LEVEL_MAX api_string = build_API_sync_string_for_user_for_levels( self.user, [level for level in range(1, sample_level + 1)] ) expected = ",".join([str(level) for level in range(1, sample_level + 1)]) self.assertTrue(expected in api_string)
def test_when_wanikani_changes_meaning_no_duplicate_is_created(self): resp_body = deepcopy(sample_api_responses.single_vocab_response) resp_body['requested_information'][0]['meaning'] = "NOT radioactive bat" # Mock response so that the level changes on our default vocab. responses.add(responses.GET, build_API_sync_string_for_user_for_levels(self.user, [self.user.profile.level, ]), json=resp_body, status=200, content_type='application/json') sync_unlocked_vocab_with_wk(self.user) # Will fail if 2 vocab exist with same kanji. vocabulary = get_vocab_by_kanji("猫")
def test_unlock_all_unlocks_all(self): self.user.profile.api_valid = True self.user.profile.save() resp_body = sample_api_responses.single_vocab_response level_list = [level for level in range(1, self.user.profile.level + 1)] responses.add(responses.GET, build_API_sync_string_for_user_for_levels(self.user, level_list), json=resp_body, status=200, content_type='application/json') checked_levels, unlocked_count, locked_count = unlock_all_possible_levels_for_user(self.user) self.assertListEqual(level_list, checked_levels) self.assertEqual(unlocked_count, 1)
def test_unlocking_all_levels_unlocks_all_levels(self): resp_body = sample_api_responses.single_vocab_response responses.add(responses.GET, build_API_sync_string_for_user_for_levels( self.user, [1, 2, 3, 4, 5]), json=resp_body, status=200, content_type='application/json') self.user.profile.api_valid = True self.user.profile.save() self.client.post(reverse("kw:unlock_all")) self.assertListEqual(sorted(self.user.profile.unlocked_levels_list()), [1, 2, 3, 4, 5])
def test_when_wanikani_changes_meaning_no_duplicate_is_created(self): resp_body = deepcopy(sample_api_responses.single_vocab_response) resp_body["requested_information"][0]["meaning"] = "NOT radioactive bat" # Mock response so that the level changes on our default vocab. responses.add( responses.GET, build_API_sync_string_for_user_for_levels( self.user, [self.user.profile.level] ), json=resp_body, status=200, content_type="application/json", ) sync_unlocked_vocab_with_wk(self.user) # Will fail if 2 vocab exist with same kanji. vocabulary = get_vocab_by_kanji("猫")
def test_when_wanikani_changes_meaning_no_duplicate_is_created(self): resp_body = deepcopy(sample_api_responses.single_vocab_response) resp_body["requested_information"][0][ "meaning"] = "NOT radioactive bat" # Mock response so that the level changes on our default vocab. mock_user_info_response(self.user.profile.api_key) responses.add( responses.GET, build_API_sync_string_for_user_for_levels( self.user, [self.user.profile.level]), json=resp_body, status=200, content_type="application/json", ) Syncer.factory(self.user.profile).sync_with_wk() # Will fail if 2 vocab exist with same kanji. get_vocab_by_kanji("猫")