Example #1
0
    def test_authenticated_post_current_states(self):
        """
        Test if a Case has correct open state after a post
        """
        case = baker.make(Case)
        current_states = list(case.get_current_states())
        self.assertListEqual(current_states, [])

        url = reverse("camunda-workers-state")
        client = get_authenticated_with_token_client(
            settings.CAMUNDA_SECRET_KEY)
        STATE_NAME = "FOO STATE NAME"

        client.post(
            url,
            data={
                "case_identification": case.id,
                "state": STATE_NAME,
                "case_process_id": 1,
            },
            format="json",
        )

        current_states = list(case.get_current_states())
        state = current_states[0]
        self.assertEquals(state.status.name, STATE_NAME)
Example #2
0
    def test_authenticated_user_create(self):
        # Should create users using the given email if they don't exist yet
        self.assertEquals(User.objects.count(), 0)

        case = baker.make(Case)

        url = reverse("visits-list")
        client = get_authenticated_with_token_client(
            settings.SECRET_KEY_TOP_ZAKEN)

        data = {
            "authors": [{
                "email": "*****@*****.**"
            }, {
                "email": "*****@*****.**"
            }],
            "start_time":
            "2021-03-31T17:17:52.126Z",
            "case":
            case.id,
        }
        response = client.post(url, data=data, format="json")

        visit = Visit.objects.all()[0]
        self.assertEqual(len(visit.authors.all()), 2)
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        self.assertEquals(User.objects.count(), 2)
Example #3
0
 def test_authenticated_post_bad_request_no_state(self):
     """ Should fail if the state doesn't exist """
     url = reverse("camunda-workers-end-state")
     client = get_authenticated_with_token_client(settings.CAMUNDA_SECRET_KEY)
     response = client.post(
         url, data={"state_identification": "non_existent_state_id"}, format="json"
     )
     self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
Example #4
0
    def test_authenticated_post_201(self):
        url = reverse("camunda-workers-state")
        client = get_authenticated_with_token_client(settings.CAMUNDA_SECRET_KEY)
        case = baker.make(Case)

        response = client.post(
            url,
            data={"case_identification": case.identification, "state": "FOO"},
            format="json",
        )

        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
Example #5
0
    def test_authenticated_post_success(self):
        """ Should succeed and the given state should have an end_date """
        state = baker.make(CaseState)
        self.assertIsNone(state.end_date)

        url = reverse("camunda-workers-end-state")
        client = get_authenticated_with_token_client(settings.CAMUNDA_SECRET_KEY)

        response = client.post(
            url, data={"state_identification": state.id}, format="json"
        )

        # Get the state again, which should be updated now
        state = CaseState.objects.get(id=state.id)

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertIsNotNone(state.end_date)
Example #6
0
class VisitApiTest(APITestCase):
    def setUp(self):
        management.call_command("flush", verbosity=0, interactive=False)

    def test_unauthenticated_get(self):
        url = reverse("visits-list")
        client = get_unauthenticated_client()
        response = client.get(url)
        self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)

    def test_authenticated_get(self):
        url = reverse("visits-list")
        client = get_authenticated_client()
        response = client.get(url)
        self.assertEqual(response.status_code, status.HTTP_200_OK)

    def test_authenticated_get_empty(self):
        url = reverse("visits-list")
        client = get_authenticated_client()

        response = client.get(url)
        data = response.json()

        self.assertEquals(data["results"], [])

    def test_authenticated_get_filled(self):
        baker.make(Visit, _quantity=2)

        url = reverse("visits-list")
        client = get_authenticated_client()

        response = client.get(url)
        data = response.json()

        self.assertEquals(len(data["results"]), 2)

    def test_unauthenticated_post(self):
        url = reverse("visits-list")
        client = get_unauthenticated_client()
        response = client.post(url, data={}, format="json")
        self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)

    def test_authenticated_post_bad_request(self):
        url = reverse("visits-list")
        client = get_authenticated_client()
        response = client.post(url, data={}, format="json")
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)

    def test_authenticated_post_201(self):
        self.assertEquals(Visit.objects.count(), 0)

        case = baker.make(Case)

        url = reverse("visits-list")
        client = get_authenticated_client()

        data = {
            "authors": [{
                "email": "*****@*****.**"
            }],
            "start_time": "2021-03-31T17:17:52.126Z",
            "case": case.id,
        }
        response = client.post(url, data=data, format="json")
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        self.assertEquals(Visit.objects.count(), 1)

    def test_authenticated_user_create(self):
        # Should create users using the given email if they don't exist yet
        self.assertEquals(User.objects.count(), 0)

        case = baker.make(Case)

        url = reverse("visits-list")
        client = get_authenticated_with_token_client(
            settings.SECRET_KEY_TOP_ZAKEN)

        data = {
            "authors": [{
                "email": "*****@*****.**"
            }, {
                "email": "*****@*****.**"
            }],
            "start_time":
            "2021-03-31T17:17:52.126Z",
            "case":
            case.id,
        }
        response = client.post(url, data=data, format="json")

        visit = Visit.objects.all()[0]
        self.assertEqual(len(visit.authors.all()), 2)
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        self.assertEquals(User.objects.count(), 2)

    def test_authenticated_visit_create_existing_users(self):
        # Should be able to process a visit using existing Users and their ids
        case = baker.make(Case)
        user_a = baker.make(User, email="*****@*****.**")
        user_b = baker.make(User, email="*****@*****.**")

        url = reverse("visits-list")
        client = get_authenticated_with_token_client(
            settings.SECRET_KEY_TOP_ZAKEN)

        data = {
            "author_ids": [user_a.id, user_b.id],
            "start_time": "2021-03-31T17:17:52.126Z",
            "case": case.id,
        }
        response = client.post(url, data=data, format="json")

        visit = Visit.objects.all()[0]
        self.assertEqual(len(visit.authors.all()), 2)
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
Example #7
0
 def test_authenticated_post_bad_request(self):
     url = reverse("camunda-workers-end-state")
     client = get_authenticated_with_token_client(
         settings.CAMUNDA_SECRET_KEY)
     response = client.post(url, data={}, format="json")
     self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)