# Path: talks/serializers.py
# class MeetupSerializer(serializers.ModelSerializer):
#     description = serializers.CharField(required=False, max_length=10000)
#     talks = TalkSerializer(many=True, read_only=True)
# 
#     class Meta:
#         model = Meetup
#         fields = ('id', 'date', 'description', 'talks')
# 
# class TalkSerializer(serializers.ModelSerializer):
#     author = UserInfoSerializer(read_only=True)
#     topic = serializers.CharField(required=True, min_length=3, max_length=500)
#     description = serializers.CharField(required=True, min_length=5, max_length=10000)
#     votes_count = serializers.SerializerMethodField()
#     has_voted = serializers.SerializerMethodField()
# 
#     class Meta:
#         model = Talk
#         fields = ('id', 'author', 'topic', 'description', 'video_url', 'votes_count', 'has_voted') 
# 
#     def get_votes_count(self, obj):
#         return obj.votes.count()
# 
#     def get_has_voted(self, obj):
#         return obj.votes.exists(self.context['request'].user.id)
# 
#     def create(self, validated_data):
#         request = self.context['request']
#         author = request.user
# 
#         meetup = self.context['meetup']
# 
#         return Talk.objects.create(meetup=meetup, author=author, **validated_data)
# 
# Path: talks/models.py
# class Meetup(models.Model):
#     date = models.DateTimeField()
#     description = models.CharField(max_length=10000, blank=True, null=True)
# 
#     def __str__(self):
#         return '{} ({})'.format(self.__class__.__name__, self.date)
# 
#     class Meta:
#         ordering = ['date']
# 
# class Talk(VoteModel):
#     meetup = models.ForeignKey(Meetup, related_name='talks', null=True, on_delete=models.CASCADE)
#     author = models.ForeignKey(User, related_name='talks', on_delete=models.CASCADE)
#     topic = models.CharField(max_length=500)
#     description = models.CharField(max_length=10000)
#     video_url = models.URLField(blank=True, null=True)
# 
#     def __str__(self):
#         return '{} - {}'.format(self.__class__.__name__, self.topic)
# 
#     class Meta:
#         ordering = ['-vote_score']


from datetime import timedelta
from django.contrib.auth.models import User
from django.utils import timezone
from rest_framework.test import APITestCase, APIClient
from rest_framework.reverse import reverse
from rest_framework import status
from .serializers import MeetupSerializer, TalkSerializer
from .models import Meetup, Talk





class MeetupsViewSetTestCase(APITestCase):
    def setUp(self):
        self.client = APIClient()
        self.list_view_name = 'talks:meetups-list'
        self.detail_view_name = 'talks:meetups-detail'

# Path: talks/serializers.py
# class MeetupSerializer(serializers.ModelSerializer):
#     description = serializers.CharField(required=False, max_length=10000)
#     talks = TalkSerializer(many=True, read_only=True)
# 
#     class Meta:
#         model = Meetup
#         fields = ('id', 'date', 'description', 'talks')
# 
# class TalkSerializer(serializers.ModelSerializer):
#     author = UserInfoSerializer(read_only=True)
#     topic = serializers.CharField(required=True, min_length=3, max_length=500)
#     description = serializers.CharField(required=True, min_length=5, max_length=10000)
#     votes_count = serializers.SerializerMethodField()
#     has_voted = serializers.SerializerMethodField()
# 
#     class Meta:
#         model = Talk
#         fields = ('id', 'author', 'topic', 'description', 'video_url', 'votes_count', 'has_voted') 
# 
#     def get_votes_count(self, obj):
#         return obj.votes.count()
# 
#     def get_has_voted(self, obj):
#         return obj.votes.exists(self.context['request'].user.id)
# 
#     def create(self, validated_data):
#         request = self.context['request']
#         author = request.user
# 
#         meetup = self.context['meetup']
# 
#         return Talk.objects.create(meetup=meetup, author=author, **validated_data)
# 
# Path: talks/models.py
# class Meetup(models.Model):
#     date = models.DateTimeField()
#     description = models.CharField(max_length=10000, blank=True, null=True)
# 
#     def __str__(self):
#         return '{} ({})'.format(self.__class__.__name__, self.date)
# 
#     class Meta:
#         ordering = ['date']
# 
# class Talk(VoteModel):
#     meetup = models.ForeignKey(Meetup, related_name='talks', null=True, on_delete=models.CASCADE)
#     author = models.ForeignKey(User, related_name='talks', on_delete=models.CASCADE)
#     topic = models.CharField(max_length=500)
#     description = models.CharField(max_length=10000)
#     video_url = models.URLField(blank=True, null=True)
# 
#     def __str__(self):
#         return '{} - {}'.format(self.__class__.__name__, self.topic)
# 
#     class Meta:
#         ordering = ['-vote_score']


# Path: talks/tests.py
from datetime import timedelta
from django.contrib.auth.models import User
from django.utils import timezone
from rest_framework.test import APITestCase, APIClient
from rest_framework.reverse import reverse
from rest_framework import status
from .serializers import MeetupSerializer, TalkSerializer
from .models import Meetup, Talk






class MeetupsViewSetTestCase(APITestCase):
    def setUp(self):
        self.client = APIClient()
        self.list_view_name = 'talks:meetups-list'
        self.detail_view_name = 'talks:meetups-detail'

        self.serializer_class = MeetupSerializer