Example #1
0
    def test_render_home_1(self):
        """
        Test without any dog
        :return:
        """
        create_account2('secret_toto',
                        datetime(year=2000, month=1, day=1,
                                 tzinfo=UTC)).save()

        request: HttpRequest = RequestFactory().get('home')
        request.COOKIES[COOKIE_ACCOUNT_ID_SECRET] = 'secret_toto'
        home.render_home(request)
Example #2
0
 def setUp(self):
     created_at1: datetime = datetime(year=2000, month=1, day=1, tzinfo=UTC)
     created_at2: datetime = datetime(year=2000, month=1, day=2, tzinfo=UTC)
     account1: Account = create_account2('id_secret', created_at1)
     account2: Account = create_account2('id_secret', created_at1)
     account1.save()
     account2.save()
     dog1: Dog = create_dog(account1, 'id_public_1', created_at1, 'toto',
                            BreedType.GOLDEN_RETRIEVER)
     dog2: Dog = create_dog(account2, 'id_public_2', created_at2, 'tata',
                            BreedType.CORGI)
     dog1.save()
     dog2.save()
Example #3
0
 def test_apply_meet_random_another_dog_1(self):
     """
     With another valid dog
     :return:
     """
     created_at: datetime = datetime(year=2000, month=1, day=1, tzinfo=UTC)
     account: Account = create_account2('id_secret', created_at)
     account.save()
     create_dog(account, "id_public_1", created_at, 'name_1',
                BreedType.GERMAN_SHEPHERD).save()
     create_dog(account, "id_public_2", created_at, 'name_2',
                BreedType.GERMAN_SHEPHERD).save()
     self.assertTrue(
         apply_meet_another_random_dog(fetch_dog('id_public_1'),
                                       fetch_dog('id_public_2'),
                                       DogStatus.WALKING, created_at))
     self.assertEqual(get_last_dog_action_events(
         fetch_dog('id_public_1')), [
             DogActionEvent(id=4,
                            dog_from=fetch_dog('id_public_1'),
                            dog_to=fetch_dog('id_public_2'),
                            context=DogStatus.WALKING,
                            type=DogActionEventType.MEET_ANOTHER_DOG,
                            created_at=created_at)
         ])
Example #4
0
 def test_update_walk(self):
     """
     Check walking state update
     :return:
     """
     created_at: datetime = datetime(year=2000, month=1, day=1, tzinfo=UTC)
     account: Account = create_account2('id_secret', created_at)
     account.save()
     dog1: Dog = create_dog(account, "id_public_1", created_at, 'name',
                            BreedType.GERMAN_SHEPHERD)
     dog2: Dog = create_dog(account, "id_public_2", created_at, 'name',
                            BreedType.GOLDEN_RETRIEVER)
     dog1.fat = 0.5
     dog1.affection = 0.5
     walk_dog(dog1, account, created_at)
     update(dog1, created_at + WALKING_TIME + timedelta(seconds=1))
     dog2.fat = 0.5
     dog2.affection = 0.5
     walk_dog(dog2, account, created_at)
     update(dog2, created_at + WALKING_TIME + timedelta(seconds=1))
     dog1_db: Dog = fetch_dog('id_public_1')
     dog2_db: Dog = fetch_dog('id_public_2')
     self.assertEqual(DogStatus.AVAILABLE, dog1_db.status)
     self.assertEqual(0.4, dog1_db.fat)
     self.assertEqual(0.6981229166666667, dog1_db.affection)
     self.assertEqual(DogStatus.AVAILABLE, dog2_db.status)
     self.assertEqual(0.35, dog2_db.fat)
     self.assertEqual(0.6478100694444444, dog2_db.affection)
Example #5
0
 def test_age(self):
     created_at: datetime = datetime(year=2000, month=1, day=1, tzinfo=UTC)
     account: Account = create_account2('id_secret', created_at)
     dog: Dog = create_dog(account, "id_public", created_at, 'name',
                           BreedType.GERMAN_SHEPHERD)
     self.assertEqual(
         0, dog.age(datetime(year=1999, month=1, day=1, tzinfo=UTC)))
     self.assertEqual(
         0, dog.age(datetime(year=2000, month=1, day=1, hour=1,
                             tzinfo=UTC)))
     self.assertEqual(
         2, dog.age(datetime(year=2000, month=1, day=3, tzinfo=UTC)))
Example #6
0
 def test_create_dog(self):
     """
     Check all fields are setup correctly with create_dog(...)
     :return:
     """
     created_at: datetime = datetime(year=2000, month=1, day=1, tzinfo=UTC)
     account: Account = create_account2('id_secret', created_at)
     dog: Dog = create_dog(account, "id_public", created_at, 'name',
                           BreedType.GOLDEN_RETRIEVER)
     self.assertEqual('id_public', dog.id_public)
     self.assertEqual(created_at, dog.created_at)
     self.assertEqual('name', dog.name)
     self.assertEqual(BreedType.GOLDEN_RETRIEVER, dog.breed)
Example #7
0
 def test_render_home_2(self):
     """
     Test with one dog
     :return:
     """
     created_at: datetime = datetime(year=2000, month=1, day=1, tzinfo=UTC)
     account: Account = create_account2('secret_toto', created_at)
     account.save()
     create_dog(account, 'dog_id', created_at, 'name',
                BreedType.GOLDEN_RETRIEVER).save()
     request: HttpRequest = RequestFactory().get('home')
     request.COOKIES[COOKIE_ACCOUNT_ID_SECRET] = 'secret_toto'
     home.render_home(request)
Example #8
0
 def test_update_available(self):
     created_at: datetime = datetime(year=2000, month=1, day=1, tzinfo=UTC)
     account: Account = create_account2('id_secret', created_at)
     account.save()
     dog: Dog = create_dog(account, "id_public", created_at, 'name',
                           BreedType.GERMAN_SHEPHERD)
     dog.affection = 0.5
     dog.food = 0.5
     dog.status = DogStatus.AVAILABLE
     update(dog, datetime(year=2000, month=1, day=1, hour=1, tzinfo=UTC))
     dog_db: Dog = fetch_dog('id_public')
     self.assertEqual(0.48, dog_db.food)
     self.assertEqual(0.4875, dog_db.affection)
Example #9
0
 def test_update_left_2(self):
     """
     Check that a dog with LEFT status is deleted after some time
     :return:
     """
     created_at: datetime = datetime(year=2000, month=1, day=1, tzinfo=UTC)
     account: Account = create_account2('id_secret', created_at)
     account.save()
     dog: Dog = create_dog(account, "id_public", created_at, 'name',
                           BreedType.GERMAN_SHEPHERD)
     dog.set_status(DogStatus.LEFT, created_at)
     dog.save()
     update(dog, created_at + LEFT_TIME + timedelta(seconds=1))
     self.assertIsNone(Dog.objects.filter(id=dog.id).first())
Example #10
0
 def test_apply_action_meet_another_dog(self):
     """
     With only 1 dog
     :return:
     """
     created_at: datetime = datetime(year=2000, month=1, day=1, tzinfo=UTC)
     account: Account = create_account2('id_secret', created_at)
     account.save()
     dog: Dog = create_dog(account, "id_public", created_at, 'name',
                           BreedType.GERMAN_SHEPHERD)
     dog.save()
     apply_action(dog, DogActionEventType.MEET_ANOTHER_DOG,
                  DogStatus.WALKING, created_at)
     self.assertEqual(get_last_dog_action_events(fetch_dog('id_public')),
                      [])
Example #11
0
 def test_apply_meet_random_another_dog_2(self):
     """
     With the same dog
     :return:
     """
     created_at: datetime = datetime(year=2000, month=1, day=1, tzinfo=UTC)
     account: Account = create_account2('id_secret', created_at)
     account.save()
     create_dog(account, "id_public_1", created_at, 'name_1',
                BreedType.GERMAN_SHEPHERD).save()
     self.assertFalse(
         apply_meet_another_random_dog(fetch_dog('id_public_1'),
                                       fetch_dog('id_public_1'),
                                       DogStatus.WALKING, created_at))
     self.assertEqual(get_last_dog_action_events(fetch_dog('id_public')),
                      [])
Example #12
0
 def test_update_play(self):
     """
     Check playing state update
     :return:
     """
     created_at: datetime = datetime(year=2000, month=1, day=1, tzinfo=UTC)
     account: Account = create_account2('id_secret', created_at)
     account.save()
     dog: Dog = create_dog(account, "id_public", created_at, 'name',
                           BreedType.GERMAN_SHEPHERD)
     dog.fat = 0.5
     dog.affection = 0.5
     play_dog(dog, account, created_at)
     update(dog, created_at + PLAYING_TIME + timedelta(seconds=1))
     dog_db: Dog = fetch_dog('id_public')
     self.assertEqual(DogStatus.AVAILABLE, dog_db.status)
     self.assertEqual(0.45, dog_db.fat)
     self.assertEqual(0.5993305555555556, dog_db.affection)
Example #13
0
 def test_apply_action_find_tennis_ball(self):
     created_at: datetime = datetime(year=2000, month=1, day=1, tzinfo=UTC)
     account: Account = create_account2('id_secret', created_at)
     account.save()
     dog: Dog = create_dog(account, "id_public", created_at, 'name',
                           BreedType.GERMAN_SHEPHERD)
     dog.save()
     apply_action(dog, DogActionEventType.FIND_TENNIS_BALL,
                  DogStatus.EATING, created_at)
     self.assertEqual(2, fetch_account('id_secret').number_tennis_ball)
     self.assertEqual(get_last_dog_action_events(fetch_dog('id_public')), [
         DogActionEvent(id=3,
                        dog_from=dog,
                        dog_to=None,
                        context=DogStatus.EATING,
                        type=DogActionEventType.FIND_TENNIS_BALL,
                        created_at=created_at)
     ])
Example #14
0
 def test_create_account(self):
     created_at: datetime = datetime(year=2000, month=1, day=1, tzinfo=UTC)
     account: Account = create_account2('id_secret', created_at)
     account.save()
     dog: Dog = create_dog(account, 'id_public', created_at, 'toto',
                           BreedType.CHICKEN)
     dog.save()
     indexes: List[int] = list(range(0, 100))
     shuffle(indexes)
     for i in indexes:
         add_dog_event(dog, DogEventType.ADOPTION,
                       created_at + timedelta(seconds=i))
     self.assertEqual(20, len(DogEvent.objects.all()))
     dog_events: List[DogEvent] = get_last_dog_events(3)
     self.assertEqual('2000-01-01 00:01:39+00:00',
                      str(dog_events[0].created_at))
     self.assertEqual('2000-01-01 00:01:38+00:00',
                      str(dog_events[1].created_at))
     self.assertEqual('2000-01-01 00:01:37+00:00',
                      str(dog_events[2].created_at))
Example #15
0
 def test_update_last_refresh(self):
     created_at: datetime = datetime(year=2000, month=1, day=1, tzinfo=UTC)
     account: Account = create_account2('id_secret', created_at)
     account.save()
     dog: Dog = create_dog(account, "id_public", created_at, 'name',
                           BreedType.GERMAN_SHEPHERD)
     dog.save()
     self.assertEqual(created_at, fetch_dog('id_public').last_refresh)
     updated_at_1: datetime = datetime(year=2000,
                                       month=1,
                                       day=1,
                                       minute=1,
                                       tzinfo=UTC)
     update(dog, updated_at_1)
     self.assertEqual(updated_at_1, fetch_dog('id_public').last_refresh)
     updated_at_2: datetime = datetime(year=2000,
                                       month=1,
                                       day=1,
                                       minute=1,
                                       tzinfo=UTC)
     update(dog, updated_at_2)
     self.assertEqual(updated_at_2, fetch_dog('id_public').last_refresh)
Example #16
0
 def setUp(self) -> None:
     created_at: datetime = datetime(year=2000, month=1, day=1, tzinfo=UTC)
     account: Account = create_account2('secret_toto', created_at)
     account.save()
     create_dog(account, 'public_dog_id', created_at, 'name', BreedType.GOLDEN_RETRIEVER).save()
     create_dog(account, 'public_dog_id_2', created_at, 'toto', BreedType.GOLDEN_RETRIEVER).save()