This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import mock | |
| import datetime | |
| import time | |
| from random import randint | |
| from dateutil.relativedelta import relativedelta | |
| from django.contrib.auth import get_user_model | |
| from django.core.urlresolvers import reverse | |
| from carrier.tenant_carrier.models import Carrier |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| autofillCityProvince = (defaultValues) => { | |
| this.setCurrentValue( | |
| this.safeKey('financing_city'), | |
| defaultValues.city, | |
| false | |
| ); | |
| this.setCurrentValue( | |
| this.safeKey('financing_province'), | |
| defaultValues.province, | |
| false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def test_post_hand_with_deck(self): | |
| deck1 = Deck(name='deck1', user=self.user) | |
| deck1.save() | |
| post_data = { | |
| 'name': 'hand1', | |
| 'deck': { | |
| 'id': deck1.pk | |
| } | |
| } | |
| request = self.request_factory.post(reverse('goals:hand-list'), post_data, format='json') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def perform_create(self, serializer): | |
| deck = None | |
| try: | |
| from IPython import embed; embed(); | |
| deck = Deck.objects.get(pk=self.request.data.get(‘deck’, {}).get(‘id’, None)) | |
| except Deck.DoesNotExist: | |
| pass | |
| … |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (testing) ktruong:~ ktruong$ python manage.py test tests | |
| In [1]: print(‘hi’) | |
| hi | |
| In [2]: self | |
| Out[2]: <goals.views.HandList at 0x106778470> | |
| In [3]: dir(self) | |
| Out[3]: … | |
| In [4]: exit() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def test_post_hand_with_deck(self): | |
| deck1 = Deck(name=’deck1', user=self.user) | |
| post_data = { | |
| ‘name’: ‘hand1’, | |
| ‘deck’: { | |
| ‘id’: deck1.pk | |
| } | |
| } | |
| request = self.request_factory.post(reverse(‘goals:hand-list’), post_data, format=’json’) | |
| force_authenticate(request, user=self.user) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Hand(models.Model): | |
| created = models.DateTimeField(auto_now_add=True) | |
| name = models.CharField(max_length=100, blank=False, null=False) | |
| user = models.ForeignKey(‘users.User’, related_name=’hands’, on_delete=models.CASCADE, null=False) | |
| deck = models.ForeignKey(‘goals.Deck’, related_name=’hands’, on_delete=models.CASCADE, null=True) | |
| class Meta: | |
| ordering = (‘created’,) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class HandSerializer(serializers.HyperlinkedModelSerializer): | |
| user = serializers.CharField(read_only=True, source=’user.username’) | |
| deck = serializers.CharField(read_only=True, required=False, source=’deck.name’) | |
| cards = CardSerializer(many=True, read_only=True) | |
| class Meta: | |
| model = Hand | |
| fields = (‘url’, ‘id’, ‘created’, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class HandList(generics.ListCreateAPIView): | |
| serializer_class = HandSerializer | |
| def get_queryset(self): | |
| return Hand.objects.all().filter(user__username=self.request.user) | |
| def perform_create(self, serializer): | |
| deck = None | |
| try: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class HandList(generics.ListCreateAPIView): | |
| serializer_class = HandSerializer | |
| def get_queryset(self): | |
| return Hand.objects.all().filter(user__username=self.request.user) | |
| def perform_create(self, serializer): | |
| print (‘hit perform_create’) | |
| deck = None |
OlderNewer