pinax-referrals icon indicating copy to clipboard operation
pinax-referrals copied to clipboard

Question: How correctly test app?

Open nurzhannogerbek opened this issue 6 years ago • 8 comments

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 signup view:
from account.views import SignupView
from pinax.referrals.models import Referral


class RegistrationView(SignupView):

    def after_signup(self, form):
        super(RegistrationView, self).after_signup(form)
        Referral.record_response(self.request, "USER_SIGNUP")

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

nurzhannogerbek avatar May 21 '18 18:05 nurzhannogerbek

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.

KatherineMichel avatar May 21 '18 23:05 KatherineMichel

@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?

nurzhannogerbek avatar May 22 '18 06:05 nurzhannogerbek

@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 avatar May 22 '18 20:05 KatherineMichel

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

KatherineMichel avatar Jun 28 '18 20:06 KatherineMichel

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 avatar Nov 24 '19 10:11 vmisiko

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

vmisiko avatar Nov 24 '19 10:11 vmisiko

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 avatar Jan 05 '20 01:01 KatherineMichel

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.

KatherineMichel avatar Jan 05 '20 01:01 KatherineMichel