コード例 #1
0
ファイル: views.py プロジェクト: jtenclay/kw-backend
    def form_valid(self, form):
        user = form.save()
        logger.info("New User Created: {}, with API key {}.".format(user.username, form.cleaned_data['api_key']))
        Profile.objects.create(
            user=user, api_key=form.cleaned_data['api_key'], level=1)

        sync_with_wk(user.id)
        user = authenticate(username=form.cleaned_data['username'], password=form.cleaned_data['password1'])
        login(self.request, user)
        return HttpResponseRedirect(reverse_lazy("kw:home"))
コード例 #2
0
    def test_users_with_invalid_api_keys_correctly_get_their_flag_changed_in_profile(
            self):
        self.user.profile.api_key = "ABC123"
        self.user.profile.api_valid = True
        self.user.profile.save()

        sync_with_wk(self.user.id)

        self.user.profile.refresh_from_db()
        self.assertFalse(self.user.profile.api_valid)
コード例 #3
0
ファイル: test_profile_api.py プロジェクト: tadgh/KW
    def test_users_with_invalid_api_keys_correctly_get_their_flag_changed_in_profile(
        self
    ):
        self.user.profile.api_key = "ABC123"
        self.user.profile.api_valid = True
        self.user.profile.save()

        sync_with_wk(self.user.id)

        self.user.profile.refresh_from_db()
        self.assertFalse(self.user.profile.api_valid)
コード例 #4
0
ファイル: test_sync.py プロジェクト: amirdib/kw-backend
    def test_creating_new_synonyms_for_users_who_arent_being_followed(self):
        # Mock synonyms response for V2.
        mock_user_response_v2()
        mock_subjects_v2()
        mock_assignments_with_one_assignment()
        mock_study_materials()
        # sync_unlocked_vocab_with_wk(self.user)
        self.user.profile.follow_me = False
        self.user.profile.save()

        sync_with_wk(self.user.id)

        synonyms_list = self.review.synonyms_list()
        self.assertIn("young girl", synonyms_list)
        self.assertIn("young lady", synonyms_list)
        self.assertIn("young miss", synonyms_list)
コード例 #5
0
ファイル: test_tasks.py プロジェクト: ddaws/kw-backend
    def test_creating_new_synonyms_for_users_who_arent_being_followed(self):
        resp_body = deepcopy(sample_api_responses.single_vocab_response)
        resp_body["requested_information"][0]["user_specific"]["user_synonyms"] = ["kitten", "large rat"]

        responses.add(responses.GET, self._vocab_api_regex,
                      json=resp_body,
                      status=200,
                      content_type='application/json')

        #sync_unlocked_vocab_with_wk(self.user)
        self.user.profile.follow_me = False
        self.user.profile.save()

        sync_with_wk(self.user.id)

        self.assertListEqual(self.review.synonyms_list(), ["kitten", "large rat"])
コード例 #6
0
ファイル: test_syncing.py プロジェクト: tadgh/KW
    def test_vocabulary_meaning_changes_reflect_locally(self):
        self.client.force_login(self.user)

        self.assertEqual(self.vocabulary.meaning, "radioactive bat")

        mock_user_info_response(self.user.profile.api_key)
        mock_vocab_list_response_with_single_vocabulary_with_changed_meaning(self.user)

        sync_with_wk(self.user.id)

        self.vocabulary.refresh_from_db()
        self.assertEqual(
            self.vocabulary.meaning,
            sample_api_responses.single_vocab_response_with_changed_meaning[
                "requested_information"
            ][0]["meaning"],
        )
コード例 #7
0
ファイル: views.py プロジェクト: jtenclay/kw-backend
 def get(self, request, *args, **kwargs):
     logger.debug("Entering SyncRequrested for user {}".format(self.request.user))
     should_full_sync = simplejson.loads(request.GET.get("full_sync", "false"))
     profile_sync_succeeded, new_review_count, new_synonym_count = sync_with_wk(self.request.user.id, should_full_sync)
     logger.debug("Exiting SyncRequested for user {}".format(self.request.user))
     return JsonResponse({"profile_sync_succeeded": profile_sync_succeeded,
                          "new_review_count": new_review_count,
                          "new_synonym_count": new_synonym_count})
コード例 #8
0
ファイル: test_tasks.py プロジェクト: tadgh/KW
    def test_creating_new_synonyms_for_users_who_arent_being_followed(self):
        resp_body = deepcopy(sample_api_responses.single_vocab_response)
        resp_body["requested_information"][0]["user_specific"]["user_synonyms"] = ["kitten", "large rat"]

        responses.add(responses.GET, self._vocab_api_regex,
                      json=resp_body,
                      status=200,
                      content_type='application/json')

        #sync_unlocked_vocab_with_wk(self.user)
        self.user.profile.follow_me = False
        self.user.profile.save()

        sync_with_wk(self.user.id)

        synonyms_list = self.review.synonyms_list()
        self.assertIn("kitten", synonyms_list)
        self.assertIn("large rat", synonyms_list)
コード例 #9
0
ファイル: views.py プロジェクト: gavia/kw-backend
    def sync(self, request):
        should_full_sync = False
        if 'full_sync' in request.data:
            should_full_sync = request.data['full_sync'] == 'true'

        profile_sync_succeeded, new_review_count, new_synonym_count = sync_with_wk(
            request.user.id, should_full_sync)
        return Response({
            "profile_sync_succeeded": profile_sync_succeeded,
            "new_review_count": new_review_count,
            "new_synonym_count": new_synonym_count
        })
コード例 #10
0
ファイル: views.py プロジェクト: tadgh/KW
    def sync(self, request):
        should_full_sync = False
        if "full_sync" in request.data:
            should_full_sync = request.data["full_sync"] == "true"

        profile_sync_succeeded, new_review_count, new_synonym_count = sync_with_wk(
            request.user.id, should_full_sync
        )
        return Response(
            {
                "profile_sync_succeeded": profile_sync_succeeded,
                "new_review_count": new_review_count,
                "new_synonym_count": new_synonym_count,
            }
        )
コード例 #11
0
    def sync(self, request):
        should_full_sync = False

        if "full_sync" in request.query_params:
            should_full_sync = request.query_params["full_sync"] == "true"

        if "full_sync" in request.data:
            should_full_sync = request.data["full_sync"] == "true"

        profile_sync_succeeded, new_review_count, new_synonym_count = sync_with_wk(
            request.user.id, should_full_sync)
        return Response({
            "profile_sync_succeeded": profile_sync_succeeded,
            "new_review_count": new_review_count,
            "new_synonym_count": new_synonym_count,
        })
コード例 #12
0
ファイル: signals.py プロジェクト: gavia/kw-backend
def sync_unlocks_with_wk(sender, **kwargs):
    if kwargs['user']:
        user = kwargs['user']
        sync_with_wk(user.id, full_sync=user.profile.follow_me)
コード例 #13
0
ファイル: signals.py プロジェクト: tadgh/KW
def sync_unlocks_with_wk(sender, **kwargs):
    if kwargs["user"]:
        user = kwargs["user"]
        sync_with_wk(user.id, full_sync=user.profile.follow_me)
        if user_still_has_no_lessons(user):
            unlock_previous_level(user)
コード例 #14
0
ファイル: signals.py プロジェクト: zer0nka/kw-backend
def sync_unlocks_with_wk(sender, **kwargs):
    if kwargs["user"]:
        user = kwargs["user"]
        sync_with_wk(user.id, full=user.profile.follow_me)
        if user_still_has_no_lessons(user):
            unlock_previous_level(user)