예제 #1
0
    def test_save(self) -> None:
        db.session.add = Mock()
        db.session.commit = Mock()

        invitation = Invitation(id=123)
        invitation.save()

        db.session.add.assert_called_once_with(invitation)
        db.session.commit.assert_called_once_with()
예제 #2
0
    def create(self, validated_data):
        user = self.context['request'].user
        invitation = Invitation(inviter=user)
        invitation.save()
        EmailService().send_email(
            "*****@*****.**", "welcome to shooka",
            "hi\n you invited to " + user.company.name +
            "\nclick this link and complete your registration \n "
            "127.0.0.1:3000/register/agent/" + invitation.key)

        validated_data["username"] = validated_data["email"]
        validated_data["invitation"] = invitation
        validated_data["is_active"] = False
        validated_data["company"] = user.company

        return super(AgentSerializer, self).create(validated_data)