Skip to content

Instantly share code, notes, and snippets.

Avatar

Kyle KTruong008

View GitHub Profile
View tests.py
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
View gist:24e531afc98b7460294e0684aed3257d
autofillCityProvince = (defaultValues) => {
this.setCurrentValue(
this.safeKey('financing_city'),
defaultValues.city,
false
);
this.setCurrentValue(
this.safeKey('financing_province'),
defaultValues.province,
false
View gist:dc719f655e9d2f01c0a1ba2baf857a55
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')
View gist:9112c2547df9f9efd6d03282cc7260ff
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
View gist:717095196669da6ac309c23bc623ee3c
(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()
View gist:2925c549bc6c137435aa9cf00bf06c1b
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)
View gist:263d8fe6c39e634ba3c5204d3fef19e3
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’,)
View gist:f8ea0809d25d27be14163d489dd0076e
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’,
View gist:c28fdb3c1c12b58ce07b444e35d31060
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:
View gist:f333e57c49b8d4b16adbef513c003efb
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