Example #1
0
    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"))
Example #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)
Example #3
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)
Example #4
0
    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)
Example #5
0
    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"])
Example #6
0
    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"],
        )
Example #7
0
 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})
Example #8
0
    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)
Example #9
0
    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
        })
Example #10
0
File: views.py Project: 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,
            }
        )
Example #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,
        })
Example #12
0
def sync_unlocks_with_wk(sender, **kwargs):
    if kwargs['user']:
        user = kwargs['user']
        sync_with_wk(user.id, full_sync=user.profile.follow_me)
Example #13
0
File: signals.py Project: 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)
Example #14
0
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)