import datetime

from django.test import TestCase

from ..models import Cost, Document, Good, Service, GoodUse, CostUse


class ViewsTests(TestCase):
    def setUp(self):
        self.doc = Document.objects.create(name='budget')
        rent = Cost.objects.create(name='Rent', price=100, document=self.doc)
        server = Good.objects.create(
            name='Server',
            price=1000,
            provisioning_duration=datetime.timedelta(days=36*20.6),
            document=self.doc,
        )
        vpn = Service.objects.create(name='VPN', document=self.doc)
        GoodUse.objects.create(resource=server, service=vpn, share=0.5)
        CostUse.objects.create(resource=rent, service=vpn, share=0.5)

    def test_services_list(self):
        response = self.client.get('/transparency/services')
        self.assertEqual(response.status_code, 200)

    def test_resources(self):
        response = self.client.get('/transparency/resources')
        self.assertEqual(response.status_code, 200)

    def test_detail_service(self):
        response = self.client.get('/transparency/services/1')
        self.assertEqual(response.status_code, 200)
