Exemple #1
0
    def test_update_stack_name_no_access(self):
        stack = SupplementStackFactory(user=self.user_1)
        cool_name = "cool name"

        params = {"name": cool_name}
        url = stack.get_update_url()

        # use a different client to make sure no data
        response = self.client_2.post(url, data=params)
        self.assertEqual(404, response.status_code)
Exemple #2
0
    def test_update_stack_name(self):
        stack = SupplementStackFactory(user=self.user_1)
        cool_name = "cool name"

        params = {"name": cool_name}
        url = stack.get_update_url()

        response = self.client_1.post(url, data=params)
        data = response.data

        self.assertEqual(data["name"], cool_name)
Exemple #3
0
    def test_get_view_with_supplement_compositions(self):
        stack = SupplementStackFactory(user=self.user_1)
        compositions_to_create = 3
        created_comps = SupplementStackCompositionFactory.create_batch(
            compositions_to_create, stack=stack, user=self.user_1
        )

        # sometimes the randomness makes it not quite equal to how many we wanted to create
        created_comps_length = len(set(created_comps))

        url = stack.get_update_url()
        response = self.client_1.get(url)

        self.assertIsNotNone(response.data["compositions"])
        self.assertEqual(created_comps_length, len(response.data["compositions"]))
Exemple #4
0
    def test_create_view_with_duplication_data_change_quantity(self):
        """
        dpy test open.core.betterself.tests.views.test_supplement_stack_composition_views.SupplementStackCompositionCreateTestView.test_create_view_with_duplication_data_change_quantity --keepdb
        """

        supplement_1 = SupplementFactory(user=self.user_1)
        stack = SupplementStackFactory(user=self.user_1)

        supplement_1_uuid = str(supplement_1.uuid)
        stack_uuid = str(stack.uuid)
        quantity = 5

        post_data = {
            "supplement_uuid": supplement_1_uuid,
            "stack_uuid": stack_uuid,
            "quantity": quantity,
        }

        response = self.client_1.post(self.url, data=post_data)
        self.assertEqual(response.status_code, 200)

        # now create a composition with supplement 2
        supplement_2 = SupplementFactory(user=self.user_1,
                                         name="Not Supplement 1")
        self.assertNotEqual(supplement_1, supplement_2)

        supplement_2_uuid = str(supplement_2.uuid)
        post_data = {
            "supplement_uuid": supplement_2_uuid,
            "stack_uuid": stack_uuid,
            "quantity": quantity,
        }

        response = self.client_1.post(self.url, data=post_data)
        self.assertEqual(response.status_code, 200)

        stack.refresh_from_db()

        self.assertEqual(stack.compositions.count(), 2)

        # now edit supplement 2 to be supplement 1
        last_composition = SupplementStackComposition.objects.get(
            user=self.user_1, supplement=supplement_2, stack__uuid=stack_uuid)
        update_url = last_composition.get_update_url()

        update_params = {"supplement_uuid": supplement_1_uuid}
        response = self.client_1.post(update_url, data=update_params)
        self.assertEqual(response.status_code, 400)
Exemple #5
0
    def test_edit_supplement_log_with_supplement_stack(self):
        log = SupplementLogFactory.create(user=self.user_1)
        stack = SupplementStackFactory(user=self.user_1)

        update_url = log.get_update_url()

        data = {"supplement_uuid": str(stack.uuid)}

        response = self.client_1.post(update_url, data=data)
        self.assertEqual(response.status_code, 400)
    def test_create_view(self):
        supplement = SupplementFactory(user=self.user_1)
        stack = SupplementStackFactory(user=self.user_1)

        supplement_uuid = str(supplement.uuid)
        stack_uuid = str(stack.uuid)
        quantity = 5

        post_data = {
            "supplement_uuid": supplement_uuid,
            "stack_uuid": stack_uuid,
            "quantity": quantity,
        }

        response = self.client_1.post(self.url, data=post_data)
        self.assertEqual(response.status_code, 200)
    def test_create_view_with_duplication_data(self):
        supplement = SupplementFactory(user=self.user_1)
        stack = SupplementStackFactory(user=self.user_1)

        supplement_uuid = str(supplement.uuid)
        stack_uuid = str(stack.uuid)
        quantity = 5

        post_data = {
            "supplement_uuid": supplement_uuid,
            "stack_uuid": stack_uuid,
            "quantity": quantity,
        }

        response = self.client_1.post(self.url, data=post_data)
        self.assertEqual(response.status_code, 200)

        response = self.client_1.post(self.url, data=post_data)
        self.assertEqual(response.status_code, 400)

        expected_error_found = "non_field_errors" in response.data
        self.assertTrue(expected_error_found)
Exemple #8
0
    def test_create_supplement_log_with_supplement_stack(self):
        """
        dpy test open.core.betterself.tests.views.test_supplement_log_views.TestSupplementLogViews.test_create_supplement_log_with_supplement_stack --keepdb
        """
        # a hidden feature, not really restful, but allow a user to send a supplement_stack_uuid
        # to create a set of supplements taken at the same time

        supplements = SupplementFactory.create_batch(3, user=self.user_1)
        stack = SupplementStackFactory(user=self.user_1)

        compositions = []
        for supplement in supplements:
            composition = SupplementStackCompositionFactory(
                user=self.user_1,
                supplement=supplement,
                stack=stack,
                quantity=2)
            compositions.append(composition)

        stack_uuid = stack.uuid

        utc_now = get_utc_now()
        post_data = {
            "supplement_uuid": str(stack_uuid),
            "time": utc_now.isoformat(),
            "quantity": 5,
        }

        response = self.client_1.post(self.url, data=post_data)
        self.assertEqual(response.status_code, 200, response.data)

        for supplement in supplements:
            matching_log = SupplementLog.objects.get(supplement=supplement,
                                                     quantity=10,
                                                     user=self.user_1,
                                                     time=utc_now)
            self.assertIsNotNone(matching_log)
    def test_create_view_with_separate_supplements_create_separate_compositions(
            self):
        """
        dpy test open.core.betterself.tests.views.test_supplement_stack_composition_views.SupplementStackCompositionCreateTestView.test_create_view_with_separate_supplements_create_separate_compositions --keepdb
        """
        supplement_1 = SupplementFactory(user=self.user_1)
        stack = SupplementStackFactory(user=self.user_1)

        supplement_1_uuid = str(supplement_1.uuid)
        stack_uuid = str(stack.uuid)
        quantity = 5

        post_data = {
            "supplement_uuid": supplement_1_uuid,
            "stack_uuid": stack_uuid,
            "quantity": quantity,
        }

        response = self.client_1.post(self.url, data=post_data)
        self.assertEqual(response.status_code, 200)

        stack.refresh_from_db()
        self.assertEqual(stack.compositions.count(), 1)

        # now create it with supplement 2
        supplement_2 = SupplementFactory(user=self.user_1)
        self.assertNotEqual(supplement_1, supplement_2)

        supplement_2_uuid = str(supplement_2.uuid)
        post_data = {
            "supplement_uuid": supplement_2_uuid,
            "stack_uuid": stack_uuid,
            "quantity": quantity,
        }

        response = self.client_1.post(self.url, data=post_data)
        self.assertEqual(response.status_code, 200)

        stack.refresh_from_db()
        self.assertEqual(stack.compositions.count(), 2)