Пример #1
0
    def test_user_count(self):
        """A basic test to execute the get_users_count Celery task."""
        UserFactory.create_batch(3)

        task_result = get_users_count.delay()

        self.assertIsInstance(task_result, EagerResult)
        self.assertEqual(task_result.result, 3)
Пример #2
0
    def setUpTestData(cls):
        registered_user = UserFactory(is_staff=False)
        cls.registered_user_id = registered_user.id

        staff_user = UserFactory(is_staff=True)
        cls.staff_user_id = staff_user.id

        cls.set_reversed_url()
Пример #3
0
    def setUpTestData(cls):
        user_1 = UserFactory()
        user_2 = UserFactory()

        cls.user_1_id = user_1.id
        cls.user_2_id = user_2.id

        super().setUpTestData()
Пример #4
0
    def setUpTestData(cls):
        user_1 = UserFactory()
        user_2 = UserFactory()

        cls.user_1_id = user_1.id
        cls.user_2_id = user_2.id

        # create a few instances that will never be used
        cls.model_class_factory.create_batch(5)

        super().setUpTestData()
Пример #5
0
    def test_access_permission_for_not_owner(self):
        user = UserFactory()

        diff_user_prompt = WriteUpPromptFactory()
        valid = user_can_read_prompt_instance(user, diff_user_prompt)

        self.assertFalse(valid)
Пример #6
0
    def test_access_permission_for_not_owner_failed(self):
        user = UserFactory()

        diff_user_prompt = WriteUpPromptFactory(
            share_state=PromptShareStates.PUBLISHED,
            staff_verified_share_state=StaffVerifiedShareStates.VERIFIED_FAIL,
        )
        valid = user_can_read_prompt_instance(user, diff_user_prompt)

        self.assertFalse(valid)
Пример #7
0
    def setUp(self):
        self.unregistered_user_client = APIClient()

        self.registered_user = User.objects.get(id=self.registered_user_id)
        self.registered_user_client = APIClient()
        self.registered_user_client.force_login(self.registered_user)

        self.staff_user = UserFactory(is_staff=True)
        self.staff_user_client = APIClient()
        self.staff_user_client.force_login(self.staff_user)
Пример #8
0
    def setUpTestData(cls):
        user_1 = UserFactory()
        user_2 = UserFactory()

        cls.end_period = get_utc_now()
        cls.end_period_date_string = cls.end_period.date().strftime(
            yyyy_mm_dd_format_1)

        cls.start_period = get_time_relative_units_ago(cls.end_period, days=7)
        cls.start_period_date_string = cls.start_period.date().strftime(
            yyyy_mm_dd_format_1)

        supplements = SupplementFactory.create_batch(10, user=user_1)

        for index in range(100):
            # simulate some missing data
            if index % 5 == 0 and index != 0:
                continue

            date_to_use = cls.end_period - relativedelta.relativedelta(
                days=index)
            SleepLogFactory(end_time=date_to_use, user=user_1)

            for supplement in supplements:
                SupplementLogFactory.create_batch(2,
                                                  user=user_1,
                                                  supplement=supplement,
                                                  time=date_to_use)

        cls.user_1_id = user_1.id
        cls.user_2_id = user_2.id

        for index in range(100):
            # simulate some missing data
            if index % 5 == 0 and index != 0:
                continue

            date_to_use = cls.end_period - relativedelta.relativedelta(
                days=index)
            DailyProductivityLogFactory(user=user_1, date=date_to_use)

            # add some random data to user_2 also to make sure no leaking
            DailyProductivityLogFactory(user=user_2, date=date_to_use)
Пример #9
0
    def setUpTestData(cls):
        user_1 = UserFactory()
        user_2 = UserFactory()

        # do 2 days ago, that way you can create data faster when self-testing
        start_period = datetime.datetime(2020, 9, 22, tzinfo=user_1.timezone)

        supplements = SupplementFactory.create_batch(2, user=user_1)

        for index in range(3):
            date_to_use = start_period - relativedelta.relativedelta(
                days=index)
            SleepLogFactory(end_time=date_to_use, user=user_1)

            for supplement in supplements:
                SupplementLogFactory.create_batch(2,
                                                  user=user_1,
                                                  supplement=supplement,
                                                  time=date_to_use)

        cls.user_1_id = user_1.id
        cls.user_2_id = user_2.id
Пример #10
0
    def test_access_permission_for_user_owner(self):
        user = UserFactory()
        user_prompt = WriteUpPromptFactory(user=user)
        valid = user_can_read_prompt_instance(user, user_prompt)

        self.assertTrue(valid)
Пример #11
0
    def setUpTestData(cls):
        user_1 = UserFactory()
        user_1.set_password(DEMO_TESTING_PASSWORD)
        user_1.save()

        user_2 = UserFactory(password="******")
        user_2.set_password(DEMO_TESTING_PASSWORD)
        user_2.save()

        cls.user_1_id = user_1.id
        cls.user_2_id = user_2.id

        super().setUpTestData()
Пример #12
0
 def test_user_factory(self):
     email = "*****@*****.**"
     user = UserFactory(email=email)
     self.assertEqual(user.email, email)
Пример #13
0
    def test_demo_fixture_wont_make_for_valid_user(self):
        user = UserFactory(username="******", email="*****@*****.**")

        with self.assertRaises(ValueError):
            create_demo_fixtures_for_user(user)
Пример #14
0
 def setUpTestData(cls):
     user = UserFactory(username=DEMO_TESTING_ACCOUNT,
                        email=DEMO_TESTING_ACCOUNT)
     create_demo_fixtures_for_user(user)
Пример #15
0
 def setUp(self) -> None:
     self.user = UserFactory(username=DEMO_TESTING_ACCOUNT)