Esempio n. 1
0
    def test_create(self):
        request = create_user_request(APIRequestFactory().post)
        category_name = 'CatName'

        s = CategoryFlatSerializer(data={
            'name': category_name,
        }, context={
            'request': request
        })
        s.is_valid(raise_exception=True)
        cat = Category.objects.get(id=s.save().id)

        assert cat.name == category_name
Esempio n. 2
0
    def test_update(self):
        cat = CategoryFactory(is_base_category=False)
        request = create_user_request(APIRequestFactory().put)

        s = CategoryFlatSerializer(instance=cat, data={
            'name': 'NewName',
        }, context={
            'request': request
        })

        s.is_valid(raise_exception=True)
        cat = Category.objects.get(id=s.save().id)

        assert cat.name == 'NewName'
Esempio n. 3
0
    def test_create(self):
        with pytest.raises(serializers.ValidationError):
            request = create_user_request(APIRequestFactory().post)
            fake_cat = CategoryFactory()

            s = SkillDeepSerializer(data={
                'name': 'SkillName',
                'categories': [fake_cat.id]
            }, context={
                'request': request
            })

            s.is_valid(raise_exception=True)
            s.save()
Esempio n. 4
0
    def test_update(self):
        request = create_user_request(APIRequestFactory().put)
        skill = SkillFactory(name='OldName')

        s = SkillFlatSerializer(instance=skill, data={
            'name': 'NewName'
        }, context={
            'request': request
        })

        s.is_valid(raise_exception=True)
        skill = Skill.objects.get(id=s.save().id)

        assert skill.name == 'NewName'
        assert skill.owner == request.user
Esempio n. 5
0
    def test_update(self):
        with pytest.raises(serializers.ValidationError):
            request = create_user_request(APIRequestFactory().post)
            skill = SkillFactory(name='OldName')
            fake_cat = CategoryFactory()

            s = SkillDeepSerializer(instance=skill, data={
                'name': 'NewName',
                'categories': [fake_cat.id]
            }, context={
                'request': request
            })

            s.is_valid()
            s.save()
Esempio n. 6
0
    def test_update(self):
        with pytest.raises(serializers.ValidationError):
            request = create_user_request(APIRequestFactory().post)
            fake_cat = CategoryFactory().id

            s = SkillListSerializer(data={
                'skills': [],
                'categories': [fake_cat]
            }, context={
                'request': request
            }, instance={
                'skills': [],
                'categories': [],
            })

            s.is_valid(raise_exception=True)
            s.save()
Esempio n. 7
0
    def test_create(self, mocker):
        mocker.patch('django.utils.timezone.now', mock_now)
        request = create_user_request(APIRequestFactory().post)
        _required_category = CategoryFactory(is_base_category=True,
                                             owner=request.user)

        s = SkillFlatSerializer(data={
            'name': 'TestSkill'
        }, context={
            'request': request
        })

        s.is_valid(raise_exception=True)
        skill = Skill.objects.get(id=s.save().id)

        assert len(skill.categories.get_queryset()) == 1
        assert skill.name == 'TestSkill'
        assert skill.add_date == mock_now()
        assert skill.owner == request.user
Esempio n. 8
0
    def test_create(self, mocker):
        mocker.patch('django.utils.timezone.now', mock_now)
        request = create_user_request(APIRequestFactory().post)
        skill = SkillFactory()
        categories = skill.categories.all()

        s = ActivityFlatSerializer(data=dict(
            title='NewAct',
            skill=skill.id,
            category=categories[0].id,
            description='desc',
        ), context={
            'request': request
        })

        s.is_valid(raise_exception=True)
        act = Activity.objects.get(id=s.save().id)

        assert act.title == 'NewAct'
        assert act.skill.id == skill.id
        assert act.category.id == categories[0].id
        assert act.description == 'desc'
Esempio n. 9
0
    def test_serialization(self):
        skill = SkillFactory(name='TestSkill')
        categories = skill.categories.all()
        request = create_user_request(APIRequestFactory().post)

        s = SkillListSerializer({
            'skills': [skill],
            'categories': categories,
        })

        skills = s.data['skills']
        res_cat = s.data['categories']

        assert len(res_cat) == 2
        assert len(skills) == 1

        for i in (0, 1):
            cat_id = categories[i].id

            assert res_cat[cat_id]['id'] == categories[i].id
            assert res_cat[cat_id]['name'] == categories[i].name
            assert res_cat[cat_id]['is_base_category'] == categories[i].is_base_category