Exemplo n.º 1
0
    def test_by_event(self):
        u = UserFactory()

        e1 = Subscriber.objects.create_subscription(
            event="user.*",
            user=u,
            url="https://example.com/api/"
        )
        e2 = Subscriber.objects.create_subscription(
            event="user.*",
            user=u,
            url="https://example2.com/api/v2/"
        )
        e3 = Subscriber.objects.create_subscription(
            event="blackjack.*",
            user=u,
            url="https://example.com/api/"
        )

        qs1 = Subscriber.objects.by_event("user.changed")
        qs2 = Subscriber.objects.by_event("blackjack.world.created")

        self.assertEqual(len(qs1), 2)
        self.assertTrue(e1 in qs1)
        self.assertTrue(e2 in qs1)
        self.assertFalse(e3 in qs1)


        self.assertEqual(len(qs2), 1)
        self.assertEqual(qs2[0], e3)
Exemplo n.º 2
0
 def test_create(self):
     u = UserFactory()
     Subscriber.objects.create_subscription(
         event="foo.bar",
         user=u,
         url="https://example.com/api/"
     )
Exemplo n.º 3
0
    def test_simpl_model(self):
        user = UserFactory()
        game = GameFactory(slug="blackjack")
        log_entry = LogEntry()

        self.assertTrue(events.simpl_model(user))
        self.assertTrue(events.simpl_model(game))
        self.assertFalse(events.simpl_model(log_entry))
Exemplo n.º 4
0
    def test_bad_urls(self):
        u = UserFactory()

        # Don't allow localhost by default
        with self.assertRaises(ValueError):
            Subscriber.objects.create_subscription(
                event="foo.bar",
                user=u,
                url="https://localhost/api/"
            )

        # Don't allow non-SSL URLs by default
        with self.assertRaises(ValueError):
            Subscriber.objects.create_subscription(
                event="foo.bar",
                user=u,
                url="http://example.com/api/"
            )
Exemplo n.º 5
0
class AuthAPITestCase(BaseAPITestCase):
    password = "******"

    def setUp(self):
        self.user = UserFactory()

    def test_authid_case(self):

        self.user.set_password(self.password)
        self.user.save()

        url = reverse("authcheck")
        data = {"authid": self.user.pk, "password": self.password}

        response = self.client.post(url, data)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.data["authid"], self.user.pk)
        self.assertEqual(response.data["email"], self.user.email)

        # Check bad password
        data["password"] = "******"
        response = self.client.post(url, data)
        self.assertEqual(response.status_code, 400)

    def test_email_case(self):

        self.user.set_password(self.password)
        self.user.save()

        url = reverse("authcheck")
        data = {"email": self.user.email, "password": self.password}

        response = self.client.post(url, data)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.data["authid"], self.user.pk)
        self.assertEqual(response.data["email"], self.user.email)

        # Check bad password
        data["password"] = "******"
        response = self.client.post(url, data)
        self.assertEqual(response.status_code, 400)
    def test_create(self):
        url = reverse('simpl_api:runuser-list')

        obj = RunUserFactory.build(
            run=RunFactory(),
            world=WorldFactory(),
            user=UserFactory(),
            role=RoleFactory(),
        )
        payload = serializers.RunUserSerializer(obj).data

        # Does this api work without auth?
        response = self.client.post(url, payload, format='json')
        self.assertEqual(response.status_code, 401)

        # Does this api work with auth?
        with self.login(self.user):
            response = self.client.post(url, payload, format='json')
            self.assertEqual(response.status_code, 201)
            self.assertNotEqual(len(response.data), 0)
Exemplo n.º 7
0
 def setUp(self):
     self.user = UserFactory()