Beispiel #1
0
def test_ctx(mixer):

    with mixer.ctx(commit=False):
        hole = mixer.blend(Hole)
        assert hole
        assert not Hole.objects.count()

    with mixer.ctx(commit=True):
        hole = mixer.blend(Hole)
        assert hole
        assert Hole.objects.count()
Beispiel #2
0
    def test_ctx(self):
        from mixer.backend.django import mixer

        with mixer.ctx(commit=False):
            hole = mixer.blend(Hole)
            self.assertTrue(hole)
            self.assertFalse(Hole.objects.count())

        with mixer.ctx(commit=True):
            hole = mixer.blend(Hole)
            self.assertTrue(hole)
            self.assertTrue(Hole.objects.count())
Beispiel #3
0
def test_dict():
    class FakeCriterion(Criterion):
        name = models.CharField(max_length=32, default="fake", editable=False)

        class Meta:
            app_label = "reputation"

        @staticmethod
        def info():
            return {"name": "fake", "full_name": "fake", "description": "fake"}

    with mixer.ctx(commit=False):
        fake_criterion = mixer.blend(FakeCriterion)

        data = dict(fake_criterion)

        assert len(data) == 9
        assert "version" in data
        assert "points_per_threshold" in data
        assert "thresholds" in data
        assert "badge_thresholds" in data
        assert "badge_icon" in data
        assert "badge_colour" in data
        assert "name" in data
        assert "full_name" in data
        assert "description" in data
Beispiel #4
0
def test_generic(mixer):
    obj = mixer.blend(Simple)
    with mixer.ctx(loglevel='DEBUG'):
        rabbit = mixer.blend(Rabbit, content_object=obj)
    assert rabbit.content_object == obj
    assert rabbit.object_id == obj.pk
    assert rabbit.content_type.model_class() == type(obj)

    rabbit = mixer.blend(Rabbit)
    assert rabbit.content_type
Beispiel #5
0
def test_save__missing_name():
    class FakeCriterion(Criterion):
        class Meta:
            app_label = "reputation"

    with mixer.ctx(commit=False):
        fake_criterion = mixer.blend(FakeCriterion)

        with pytest.raises(NotImplementedError):
            fake_criterion.save()
Beispiel #6
0
def test_save():
    class FakeCriterion(Criterion):
        class Meta:
            app_label = "quality"

    with mixer.ctx(commit=False):
        fake_criterion = mixer.blend(FakeCriterion)

        with pytest.raises(NotImplementedError):
            fake_criterion.save()
def test_str():
    class FakeCriterionRules(CriterionRules):
        class Meta:
            app_label = "quality"

    with mixer.ctx(commit=False):
        fake_criterion_rules = mixer.blend(FakeCriterionRules, threshold=0.5)

        with pytest.raises(NotImplementedError):
            str(fake_criterion_rules)
Beispiel #8
0
 def test_user_create(self):
     view = UserViewSet.as_view({'post': 'create'})
     factory = APIRequestFactory()
     path = reverse('user-list')
     with mixer.ctx(commit=False):
         user = mixer.blend('user.User')
         user_data = user.to_dict()
     req = factory.post(path, data=user_data, format='json')
     resp = view(req)
     assert User.objects.count() == 1
     assert resp.status_code == status.HTTP_201_CREATED
Beispiel #9
0
def test_generic(mixer):
    rabbit = mixer.blend(Rabbit)
    assert rabbit.content_type
    assert rabbit.content_type.model_class()

    obj = mixer.blend(Simple)
    with mixer.ctx(loglevel='DEBUG'):
        rabbit = mixer.blend(Rabbit, content_object=obj)
    assert rabbit.content_object == obj
    assert rabbit.object_id == obj.pk
    assert rabbit.content_type.model_class() == Simple
Beispiel #10
0
    def test_generic(self):
        from mixer.backend.django import mixer

        obj = mixer.blend(Simple)
        with mixer.ctx(loglevel='DEBUG'):
            rabbit = mixer.blend(Rabbit, content_object=obj)
        self.assertEqual(rabbit.content_object, obj)
        self.assertEqual(rabbit.object_id, obj.pk)
        self.assertEqual(rabbit.content_type.model_class(), type(obj))

        rabbit = mixer.blend(Rabbit)
        self.assertTrue(rabbit.content_type)
Beispiel #11
0
def test_batch_evaluate():
    class FakeCriterion(Criterion):
        name = models.CharField(max_length=32, default="fake", editable=False)

        class Meta:
            app_label = "quality"

    with mixer.ctx(commit=False):
        fake_criterion = mixer.blend(FakeCriterion)

        with pytest.raises(NotImplementedError):
            fake_criterion.batch_evaluate(None, None)
Beispiel #12
0
def test_save__points_len_more_than_one_than_thresholds_length():
    class FakeCriterion(Criterion):
        name = models.CharField(max_length=32, default="fake", editable=False)

        class Meta:
            app_label = "reputation"

    with mixer.ctx(commit=False):
        fake_criterion = mixer.blend(FakeCriterion,
                                     points_per_threshold="1,2,3",
                                     thresholds="1")

        with pytest.raises(ValidationError):
            fake_criterion.save()
Beispiel #13
0
 def create_job_listing_with_status(self,
                                    status=JobListingState.DRAFT,
                                    date_to_publish=datetime.now(),
                                    date_to_expire=date.today(),
                                    closed_date=datetime.now()):
     with mixer.ctx(commit=False):
         return mixer.blend(JobListing,
                            company=Company.objects.get(id=1),
                            country=LocationCountryCode.objects.get(id=1),
                            state=LocationStateCode.objects.get(id=1),
                            date_to_publish=date_to_publish,
                            date_to_expire=date_to_expire,
                            closed_date=closed_date,
                            status=status)
Beispiel #14
0
def test_save__points_len_one_more_than_thresholds_length():
    class FakeCriterion(Criterion):
        name = models.CharField(max_length=32, default="fake", editable=False)

        class Meta:
            app_label = "reputation"

    with mixer.ctx(commit=False), mock.patch(
            "reputation.models.criteria.criterion.Criterion.save"):
        fake_criterion = mixer.blend(FakeCriterion,
                                     points_per_threshold="1,2,3",
                                     thresholds="1,2")

        fake_criterion.save()
Beispiel #15
0
 def test_user_update(self):
     user = mixer.blend('user.User')
     view = UserViewSet.as_view({'put': 'update'})
     factory = APIRequestFactory()
     path = reverse('user-detail', kwargs={'pk': user.id})
     with mixer.ctx(commit=False):
         fake_user = mixer.blend('user.User')
         fake_user_data = fake_user.to_dict(
             ['password', 'username', 'email'])
     req = factory.put(path, data=fake_user_data, format='json')
     resp = view(req, pk=user.id)
     resp_data = resp.data.copy()
     resp_data.pop('id')
     assert resp.status_code == status.HTTP_200_OK
     assert resp_data == fake_user_data
Beispiel #16
0
def test_rules():
    class FakeCriterion(Criterion):
        name = models.CharField(max_length=32, default="fake", editable=False)

        class Meta:
            app_label = "quality"

    with mixer.ctx(commit=False), mock.patch(
        "quality.models.criterion.criterion.models.Model.save"
    ):
        fake_criterion = mixer.blend(FakeCriterion)

        fake_criterion.uses_rules = ["a", "b", "c", "d"]
        fake_criterion.save()
        assert fake_criterion.rules == ["a", "b", "c", "d"]
    def test_add_task_unit(self, mock_members, mock_statuses, mock_priorities,
                           mock_isvalid, mock_execute):
        with mixer.ctx(commit=False):
            members = mixer.cycle(2).blend(Member, id=(id for id in (1, 2)))
            priorities = mixer.cycle(2).blend(Priority, id=iter((1, 2)))
            statuses = mixer.cycle(2).blend(Status, id=iter((1, 2)))

        mock_members.return_value = members
        mock_statuses.return_value = statuses
        mock_priorities.return_value = priorities

        suuid = uuid.uuid4()
        title = "Task 1"
        start = "09:13"
        end = "10:39"
        member = mock_members()[0].id
        priority = mock_priorities()[0].id
        status = mock_statuses()[0].id

        AddTask.execute(
            {
                "uuid": suuid,
                "member": member,
                "title": title,
                "start": start,
                "end": end,
                "priority": priority,
                "status": status,
            },
            suuid=suuid,
        )

        mock_members.assert_called_once()
        mock_execute.assert_called_with(
            {
                "uuid": suuid,
                "member": member,
                "title": title,
                "start": start,
                "end": end,
                "priority": priority,
                "status": status,
            },
            suuid=suuid,
        )
Beispiel #18
0
def test_info__no_threshold():
    class FakeCriterion(Criterion):
        name = models.CharField(max_length=32, default="fake", editable=False)

        class Meta:
            app_label = "reputation"

        def info(self):
            return super(FakeCriterion, self).info({
                "name": "test",
                "full_name": "test",
                "description": "A test."
            })

    with mixer.ctx(commit=False):
        fake_criterion = mixer.blend(FakeCriterion)
        fake_criterion.points_per_threshold = [1]
        fake_criterion.thresholds = []

        info = fake_criterion.info()
        assert len(info) == 3
        assert info["description"].startswith(
            "A test. The points are awarded as 1 for each of these.")