예제 #1
0
def _make_user(email, with_project=True):
    username = str(uuid.uuid4())[:30]
    user = User(username=username, email=email)
    user.set_unusable_password()
    user.save()

    project = None
    if with_project:
        project = Project(owner=user)
        project.badge_key = user.username
        project.save()

        check = Check(project=project)
        check.name = "My First Check"
        check.save()

        channel = Channel(project=project)
        channel.kind = "email"
        channel.value = email
        channel.email_verified = True
        channel.save()

        channel.checks.add(check)

    # Ensure a profile gets created
    profile = Profile.objects.for_user(user)
    profile.current_project = project
    profile.save()

    return user
예제 #2
0
def _make_user(email, with_project=True):
    # Generate username from email in a deterministic way.
    # Since the database has an uniqueness constraint on username,
    # this makes sure that emails also are unique.
    username = str(uuid.uuid3(NAMESPACE_HC, email))
    user = User(username=username, email=email)
    user.set_unusable_password()
    user.save()

    project = None
    if with_project:
        project = Project(owner=user)
        project.badge_key = user.username
        project.save()

        check = Check(project=project)
        check.name = "My First Check"
        check.save()

        channel = Channel(project=project)
        channel.kind = "email"
        channel.value = email
        channel.email_verified = True
        channel.save()

        channel.checks.add(check)

    # Ensure a profile gets created
    profile = Profile.objects.for_user(user)
    profile.current_project = project
    profile.save()

    return user
예제 #3
0
def add_project(request):
    form = ProjectNameForm(request.POST)
    if not form.is_valid():
        return HttpResponseBadRequest()

    project = Project(owner=request.user)
    project.code = project.badge_key = str(uuid.uuid4())
    project.name = form.cleaned_data["name"]
    project.save()

    return redirect("hc-checks", project.code)
예제 #4
0
class BaseTestCase(TestCase):
    def setUp(self):
        super(BaseTestCase, self).setUp()

        # Alice is a normal user for tests. Alice has team access enabled.
        self.alice = User(username="******", email="*****@*****.**")
        self.alice.set_password("password")
        self.alice.save()

        self.project = Project(owner=self.alice, api_key="X" * 32)
        self.project.badge_key = self.alice.username
        self.project.save()

        self.profile = Profile(user=self.alice)
        self.profile.sms_limit = 50
        self.profile.current_project = self.project
        self.profile.save()

        # Bob is on Alice's team and should have access to her stuff
        self.bob = User(username="******", email="*****@*****.**")
        self.bob.set_password("password")
        self.bob.save()

        self.bobs_project = Project(owner=self.bob)
        self.bobs_project.badge_key = self.bob.username
        self.bobs_project.save()

        self.bobs_profile = Profile(user=self.bob)
        self.bobs_profile.current_project = self.project
        self.bobs_profile.save()

        Member.objects.create(user=self.bob, project=self.project)

        # Charlie should have no access to Alice's stuff
        self.charlie = User(username="******", email="*****@*****.**")
        self.charlie.set_password("password")
        self.charlie.save()

        Profile.objects.create(user=self.charlie)
예제 #5
0
class BaseTestCase(TestCase):
    def setUp(self):
        super().setUp()

        self.csrf_client = Client(enforce_csrf_checks=True)

        # Alice is a normal user for tests. Alice has team access enabled.
        self.alice = User(username="******", email="*****@*****.**")
        self.alice.set_password("password")
        self.alice.save()

        self.project = Project(owner=self.alice, api_key="X" * 32)
        self.project.name = "Alices Project"
        self.project.badge_key = self.alice.username
        self.project.ping_key = "p" * 22
        self.project.save()

        self.profile = Profile(user=self.alice)
        self.profile.sms_limit = 50
        self.profile.save()

        # Bob is on Alice's team and should have access to her stuff
        self.bob = User(username="******", email="*****@*****.**")
        self.bob.set_password("password")
        self.bob.save()

        self.bobs_project = Project(owner=self.bob)
        self.bobs_project.badge_key = self.bob.username
        self.bobs_project.save()

        self.bobs_profile = Profile(user=self.bob)
        self.bobs_profile.save()

        self.bobs_membership = Member.objects.create(user=self.bob,
                                                     project=self.project,
                                                     role=Member.Role.REGULAR)

        # Charlie should have no access to Alice's stuff
        self.charlie = User(username="******", email="*****@*****.**")
        self.charlie.set_password("password")
        self.charlie.save()

        self.charlies_project = Project(owner=self.charlie)
        self.charlies_project.badge_key = self.charlie.username
        self.charlies_project.save()

        self.charlies_profile = Profile(user=self.charlie)
        self.charlies_profile.save()

        self.channels_url = "/projects/%s/integrations/" % self.project.code

    def set_sudo_flag(self):
        session = self.client.session
        session["sudo"] = TimestampSigner().sign("active")
        session.save()
예제 #6
0
    def setUp(self):
        super().setUp()

        # Alice is a normal user for tests. Alice has team access enabled.
        self.alice = User(username="******", email="*****@*****.**")
        self.alice.set_password("password")
        self.alice.save()

        self.project = Project(owner=self.alice, api_key="X" * 32)
        self.project.name = "Alices Project"
        self.project.badge_key = self.alice.username
        self.project.save()

        self.profile = Profile(user=self.alice)
        self.profile.sms_limit = 50
        self.profile.save()

        # Bob is on Alice's team and should have access to her stuff
        self.bob = User(username="******", email="*****@*****.**")
        self.bob.set_password("password")
        self.bob.save()

        self.bobs_project = Project(owner=self.bob)
        self.bobs_project.badge_key = self.bob.username
        self.bobs_project.save()

        self.bobs_profile = Profile(user=self.bob)
        self.bobs_profile.save()

        self.bobs_membership = Member.objects.create(user=self.bob,
                                                     project=self.project)

        # Charlie should have no access to Alice's stuff
        self.charlie = User(username="******", email="*****@*****.**")
        self.charlie.set_password("password")
        self.charlie.save()

        self.charlies_project = Project(owner=self.charlie)
        self.charlies_project.badge_key = self.charlie.username
        self.charlies_project.save()

        self.charlies_profile = Profile(user=self.charlie)
        self.charlies_profile.save()

        self.channels_url = "/projects/%s/integrations/" % self.project.code