def test_view_content_detail(self): """Test viewing a content detail""" client = sample_client() content = sample_content(client) url = detail_url(content.uuid) res = self.client.get(url) serializer = ContentSerializer(content) self.assertEqual(res.data, serializer.data)
def test_retrieve_content_card_list(self): """Test retrieving a list of content cards""" client = sample_client() sample_content(client) sample_content(client=client, title="Torre 2", description="description torre 2") res = self.client.get(CONTENT_CARD_URL) content_cards = ContentCard.objects.all() serializer = ContentCardSerializer(content_cards, many=True) self.assertEqual(res.status_code, status.HTTP_200_OK) self.assertEqual(res.data, serializer.data)
def test_retrieve_contents_api(self): """Test retrieving a list of contents""" client = sample_client() sample_content(client) sample_content(client, title='Mosteiro1', description='Mosteiro description') res = self.client.get(CONTENTS_URL) contents = Content.objects.all() serializer = ContentSerializer(contents, many=True) self.assertEqual(res.status_code, status.HTTP_200_OK) self.assertEqual(res.data, serializer.data)
def test_create_content(self): """Test creating a content""" client = sample_client() payload = { 'client': client.uuid, 'title': 'Spot 1', 'description': 'Spot 1 description', } res = self.client.post(CONTENTS_URL, payload) self.assertEqual(res.status_code, status.HTTP_201_CREATED) content = Content.objects.get(uuid=res.data['uuid']) self.assertEqual(res.data['client'], content.client.uuid) self.assertEqual(res.data['title'], content.title) self.assertEqual(res.data['description'], content.description)
def test_retrieve_upselling_card_list(self): """Test retrieving a list of upselling cards""" client = sample_client() content = sample_content(client) ContentUpselling.objects.create(client=client, content=content, title='ContentUpselling1') ContentUpselling.objects.create(client=client, content=sample_content( client=client, title="Praia 1", description="A melhor praia"), title='ContentUpselling2') res = self.client.get(UPSELLING_CARD_URL) upselling_cards = UpsellingCard.objects.all() serializer = UpsellingCardSerializer(upselling_cards, many=True) self.assertEqual(res.status_code, status.HTTP_200_OK) self.assertEqual(res.data, serializer.data)
def test_retrieve_highlight_card_list(self): """Test retrieving a list of highlight cards""" client = sample_client() content = sample_content(client) ContentHighlight.objects.create( client=client, content=content, ) ContentHighlight.objects.create( client=client, content=sample_content( client=client, title="Torre de belem 2", description="description Torre de belem 2", )) res = self.client.get(HIGHLIGHT_CARD_URL) highlight_card = HighlightCard.objects.all() serializer = HighlightCardSerializer(highlight_card, many=True) self.assertEqual(res.status_code, status.HTTP_200_OK) self.assertEqual(res.data, serializer.data)
def setUp(self): self.api_client = APIClient() self.client = sample_client() self.content = sample_content(self.client)