Example #1
0
    def test_create_eda_eqp_filter(self):
        activate('en')

        dep = Factory.DepFactory()
        emm = Factory.EmmFactory(eqt=models.EqtEquipmentTypeCode.objects.get(
            pk=1))
        eqp1 = Factory.EqpFactory(emm=emm)
        eqp2 = Factory.EqpFactory(emm=emm)
        eqp3 = Factory.EqpFactory(emm=emm)

        models.EdaEquipmentAttachment(dep=dep, eqp=eqp1).save()

        models.EdaEquipmentAttachment(dep=dep, eqp=eqp2).save()

        test_url = reverse_lazy('whalesdb:create_eda', args=(dep.pk, ))

        self.login_whale_user()
        response = self.client.get(test_url)

        eqp_field = response.context_data["form"].fields['eqp']

        # Confusing, but there are four pieces of equipment at this point, one is created in the setup function.
        # Two of the four have been attached to the deployment created in this test case, so only two pieces of
        # equipment should be returned in the queryset.

        self.assertEqual(2, eqp_field.queryset.count())
Example #2
0
    def test_eda_relationship(self):
        emm = Factory.EmmFactory(pk=1)
        eqp = Factory.EqpFactory(emm=emm)
        dep_1 = Factory.DepFactory()
        dep_2 = Factory.DepFactory()

        eda = Factory.EdaFactory(eqp=eqp, dep=dep_1)

        self.assertEquals(1, dep_1.attachments.all().count())
        self.assertEquals(1, eqp.deployments.all().count())
        self.assertEquals(dep_1, eqp.deployments.all().last().dep)

        eda = Factory.EdaFactory(eqp=eqp, dep=dep_2)

        self.assertEquals(1, dep_2.attachments.all().count())
        self.assertEquals(2, eqp.deployments.all().count())
        self.assertEquals(dep_2, eqp.deployments.all().last().dep)
Example #3
0
    def test_dep_station_events(self):
        dep = Factory.DepFactory()
        set = models.SetStationEventCode.objects.get(pk=1)

        self.assertEquals(dep.station_events.count(), 0)

        ste = Factory.SteFactory(dep=dep, set_type=set)

        self.assertEquals(dep.station_events.count(), 1)
        self.assertEquals(dep.station_events.first().dep, dep)
        self.assertEquals(dep.station_events.first().set_type, set)
    def createDict(self):
        if self._details_dict:
            return self._details_dict

        self._details_dict = {}

        # There should be one dep object loaded from the fixtures
        dep_1 = Factory.DepFactory()

        self._details_dict['dep_1'] = dep_1

        return self._details_dict
Example #5
0
    def test_update_dep_test_func_denied(self):
        dep = Factory.DepFactory()

        self.login_whale_user()
        response = self.client.get(reverse_lazy('whalesdb:update_dep', args=(dep.pk,)))

        self.assertTrue(response.context['editable'])

        # create a deployment event
        set_type = models.SetStationEventCode.objects.get(pk=1)  # 1 == Deployment event
        dep_evt = Factory.SteFactory(dep=dep, set_type=set_type)

        response = self.client.get(reverse_lazy('whalesdb:update_dep', args=(dep.pk,)))

        # deployment should no longer be editable
        self.assertFalse(response.context['editable'])
    def setUp(self):
        super().setUp()

        self.data = Factory.DepFactory.get_valid_data()

        obj = Factory.DepFactory()

        self.test_url = reverse_lazy('whalesdb:update_dep', args=(obj.pk, ))

        # Since this is intended to be used as a pop-out form, the html file should start with an underscore
        self.test_expected_template = 'shared_models/shared_entry_form.html'

        self.expected_view = views.DepUpdate

        self.expected_form = forms.DepForm

        self.expected_success_url = reverse_lazy("whalesdb:list_dep")
Example #7
0
    def test_update_dep_test_func_denied(self):
        dep = Factory.DepFactory()

        # have to create the request and setup the view
        req_factory = RequestFactory()
        request = req_factory.get(reverse_lazy("whalesdb:update_dep", kwargs={'pk': dep.pk, 'pop': 'pop'}))
        request.user = self.login_whale_user()
        view = setup_view(views.DepUpdate(), request, pk=dep.pk)

        # check to see if a deployment that's not been deployed can be edited
        self.assertTrue(view.test_func())

        # create a deployment event
        set_type = models.SetStationEventCode.objects.get(pk=1)  # 1 == Deployment event
        dep_evt = Factory.SteFactory(dep=dep, set_type=set_type)

        # deployment should no longer be editable
        self.assertFalse(view.test_func())
Example #8
0
    def test_details_dep_context_auth_denied(self):
        activate('en')

        dep = Factory.DepFactory()
        test_url = reverse_lazy("whalesdb:details_dep", kwargs={'pk': dep.pk})

        self.login_whale_user()
        response = self.client.get(test_url)

        self.assertIn("editable", response.context)
        self.assertTrue(response.context['editable'])

        # create a deployment event
        set_type = models.SetStationEventCode.objects.get(
            pk=1)  # 1 == Deployment event
        dep_evt = Factory.SteFactory(dep=dep, set_type=set_type)

        response = self.client.get(test_url)

        self.assertIn("editable", response.context)
        self.assertTrue(response.context['auth'])
        self.assertFalse(response.context['editable'])