Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Question: How correctly test app? #44

Open
nurzhannogerbek opened this issue May 21, 2018 · 8 comments
Open

Question: How correctly test app? #44

nurzhannogerbek opened this issue May 21, 2018 · 8 comments

Comments

@nurzhannogerbek
Copy link

Hello! :)

I am trying to create referral system in my Django project. I found your very interesting app and want to test it for this task.

From documentation its not clear how correctly to use it and there is no example. As I understand we need make next steps:

  1. Create Profile models with such code:
from django.contrib.auth.models import User
from django.dispatch import receiver
from account.signals import user_signed_up  # django-user-account app
from pinax.referrals.models import Referral

class Profile(models.Model):
    user = models.OneToOneField(User,on_delete=models.CASCADE)
    referral = models.OneToOneField(Referral, null=True, on_delete=models.CASCADE)

@receiver(user_signed_up)
def handle_user_signed_up(sender, user, form, **kwargs):
    Referral.create(redirect_to=user.profile.get_absolute_url())
  1. Сreate custom # view:
from account.views import #View
from pinax.referrals.models import Referral


class RegistrationView(#View):

    def after_#(self, form):
        super(RegistrationView, self).after_#(form)
        Referral.record_response(self.request, "USER_#")

How correct are my steps? Could you give a simple example for the understanding please?

@KatherineMichel
Copy link
Member

Probably the best way to test initially is to run your project locally and see if it works. If you look within the repos of apps that have been updated recently (including this one), you can see the Circle CI and tox configurations. We use these to find errors by running tox or detox. Some apps have smoke tests, but unfortunately, the coverage is not 100% at this time.

@nurzhannogerbek
Copy link
Author

@KatherineMichel hello! Thank you for your answer. I want to run my project locally but I don't see the whole thing. How Profile model should looks like? Lets say when user signs up successfully triggered handle_user_signed_up function which create Referral. Then I need to save this entry like profile.referral = referral and profile.save(). I am little bit confused. Do you know any simple project which use pinax-referrals app?

@KatherineMichel
Copy link
Member

@NogerbekNurzhan I do not think we have a demo like that atm. In addition to the docs in the README, there could be some project on GitHub that has used pinax referrals. https://github.com/search?q=pinax-referrals&type=Code

@KatherineMichel
Copy link
Member

Hi @NogerbekNurzhan, did you make any progress on this?

@KatherineMichel KatherineMichel mentioned this issue Aug 2, 2018
@vmisiko
Copy link

vmisiko commented Nov 24, 2019

Hellow guyz, am working on pinax-referrals intergrating it with my Django app. SO far i have managed to generate referral code for every user that has signed up. my problem is that, when i output those refferal link generated for a user, it brings a domain name that is http://example.com/referrals/iqtK4SBNWcE59TN2E2oCbRZcS4ui1sadtO8iHyB3/. How can i remove that domain name and replace it with the domain name of my local host domain?

@vmisiko
Copy link

vmisiko commented Nov 24, 2019

Also from the above, i have created a view which welcomes a user who has joined using a referral link. i want the view to display the name of the referrer, something like, "welcome, you have been invited by {{ the username of the referrer }} ". But am having a challenge to connect that referral link to my welcome view for the referred users. i have tried to search the pinax-referral documentation but it is not bringing it out clearly for a newbee like me to understand well. any help so please

@KatherineMichel
Copy link
Member

Hi, for your first question, are you using pinax-referrals with a pinax-starter-project? If so, I believe you can change this domain name through settings.py SITE_ID, or sites.json file, for example: https://github.com/pinax/pinax-starter-projects/blob/account/fixtures/sites.json. I believe I've also seen it in admin because it's a site-level variable. It looks like in pinax-referrals, the current site domain is fetched through the sites framework in a model. https://docs.djangoproject.com/en/3.0/ref/contrib/sites/#hooking-into-the-current-site-from-views

@KatherineMichel
Copy link
Member

For second answer, not sure the answer atm, but I'm looking at the process_referral() function. The request and code are passed into the function and the referral is fetching using the code. View redirects to the URL that is specified in the settings.py. User is fetched using request.user. Perhaps instead could render a template that uses request.user name as variable.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants