Ejemplo n.º 1
0
    def test_unit__post_returns_200_OK_if_serializer_is_valid(self, mocked_repository, mocked_serializer):
        dummy_lotto_ticket = LottoTicket(is_winner=False, numbers=[1, 2, 3, 4, 5, 6])
        dummy_lotto_ticket.save()

        mocked_serializer().is_valid.return_value = True
        mocked_repository().get_by_numbers.return_value = dummy_lotto_ticket

        response = self.client.post(self.url, self.data, format='json')

        self.assertTrue(mocked_repository().get_by_numbers.called)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertIn('id', response.content)
        self.assertIn('is_winner', response.content)
        self.assertIn('numbers', response.content)
 def test_get_by_numbers_with_ticket_in_db(self):
     ticket = LottoTicket(is_winner=True, numbers=[1, 2])
     ticket.save()
     self.assertEqual(self.repository.get_by_numbers([1, 2]), ticket)