Ejemplo n.º 1
0
    def test_get_public(self):
        # start with sightings
        Sighting.objects.all().delete()
        self.assertEqual(Sighting.objects.get_public().count(), 0)

        # log a sighting
        sighting1 = load_test_sighting()
        self.assertEqual(Sighting.objects.get_public().count(), 0)

        # log another and mark it as spam
        sighting2 = load_test_sighting()
        sighting2.assign(self.scientist1)
        sighting2.report_spam("That's gross!")
        self.assertEqual(Sighting.objects.get_public().count(), 0)

        # log another and mark it as invalid
        sighting3 = load_test_sighting()
        sighting3.assign(self.scientist1)
        sighting3.report_invalid("I can't use this data")
        self.assertEqual(Sighting.objects.get_public().count(), 0)

        # log another and mark it as valid
        sighting4 = load_test_sighting()
        sighting4.assign(self.scientist1)
        sighting4.report_valid_without_photo("Nice sighting", True)
        self.assertEqual(Sighting.objects.get_public().count(), 1)

        # log another and mark it as valid (but with hidden comment)
        sighting4 = load_test_sighting()
        sighting4.assign(self.scientist1)
        sighting4.report_valid_without_photo("Nothing interesting to say",
                                             False)
        self.assertEqual(Sighting.objects.get_public().count(), 2)
Ejemplo n.º 2
0
    def test_allocation_fairness(self):

        species = Species.objects.all()[0]
        region = Region.objects.get(slug="tas")
        scientist1 = User.objects.get(username="******")
        scientist2 = User.objects.get(username="******")

        s1, s2, s3, s4 = [
            load_test_sighting(latitude=-42.1278,
                               longitude=148.0761,
                               species=species,
                               photo_url="a/photo") for x in range(4)
        ]

        SpeciesAllocation.objects.all().delete()
        for person in [scientist1, scientist2]:
            SpeciesAllocation.objects.create(species=species,
                                             region=region,
                                             person=person,
                                             contact_in_range=True)

        # Give scientist1 an assignment
        s1.assign(scientist1)

        # Make sure scientist2 is next choice
        self.assertEqual(s2.pick_expert(), scientist2)

        # Give scientist2 two assignments
        s2.assign(scientist2)
        s3.assign(scientist2)

        # Make sure next choice is scientist1
        self.assertEqual(s4.pick_expert(), scientist1)
Ejemplo n.º 3
0
    def test_reporting_invalid_sighting(self):

        # Setup environment
        scientist1 = User.objects.get(username="******")
        sighting = load_test_sighting()

        # Should be initially unassigned
        self.assertEqual(sighting.is_assigned, False)

        # Assigning should generate a tracker
        sighting.assign(scientist1, "Automatic assignment")

        # Should now be assigned
        self.assertEqual(sighting.is_assigned, True)

        # Keep a reference to our tracker
        pk = sighting.tracker.pk

        # Check our tracker details
        self.assertEqual(sighting.tracker.person, scientist1)
        self.assertEqual(sighting.tracker.is_displayed_on_site, False)

        # Should be able to report invalid sighting
        sighting.report_invalid("It's an unverifiable sighting.")

        # Check that get_latest_tracker returns our report
        self.assertEqual(
            pk,
            SightingTracking.objects.get_latest_tracker(sighting).pk)

        # Sighting note should be visible
        self.assertEqual(
            sighting.sighting_tracking.get(pk=pk).is_displayed_on_site, False)
Ejemplo n.º 4
0
    def test_reassigning_and_reporting_spam(self):

        # Setup environment
        scientist1 = User.objects.get(username="******")
        scientist2 = User.objects.get(username="******")
        sighting = load_test_sighting()

        # Should be initially unassigned
        self.assertEqual(sighting.is_assigned, False)

        # Assigning should generate a tracker
        sighting.assign(scientist1, "Automatic assignment")

        # Should now be assigned
        self.assertEqual(sighting.is_assigned, True)
        self.assertEqual(sighting.tracker.person, scientist1)

        # Reassign to another user
        sighting.reassign(scientist1, scientist2,
                          "Sending to someone better skilled to verify")

        self.assertEqual(sighting.is_assigned, True)
        self.assertEqual(sighting.tracker.person, scientist2)

        # Report as spam
        sighting.report_spam("Photo is junk")
        self.assertEqual(sighting.is_assigned, False)
        self.assertEqual(sighting.is_published, False)
Ejemplo n.º 5
0
    def test_get_photo_matches_species_response_with_photo(self):
        """
        Tests that get_photo_matches_species_response works.
        """
        # User logs a sighting
        sighting = load_test_sighting(user=self.user1, photo_url="a/photo")

        # Sighting gets assigned
        sighting.assign(self.scientist1)

        # Data scientists responses are saved
        responses = [c for c in SightingValidationCondition.objects.all()
                       if not c.section.is_radiogroup]
        responses.append(SightingValidationCondition.objects
            .get_sighting_matches_species_yes())
        ValidationResponse.objects.record_responses(sighting, responses)

        # Sighting is validated
        sighting.report_valid_with_photo(
            PHOTO_MATCHES_SPECIES_YES, "Good specimen", True)

        # Fetch the get_photo_matches_species_response
        self.assertEquals(
            PHOTO_MATCHES_SPECIES_YES,
            ValidationResponse.objects.get_photo_matches_species_response(sighting))
Ejemplo n.º 6
0
 def test_reassign_validation(self):
     sighting = load_test_sighting()
     scientist1 = User.objects.get(username="******")
     scientist2 = User.objects.get(username="******")
     with self.assertRaises(ObjectDoesNotExist):
         sighting.reassign(scientist1, "Automatic assignment")
     sighting.assign(scientist1, "Automatic assignment")
     sighting.reassign(scientist1, scientist2, "Passing to another expert")
Ejemplo n.º 7
0
    def test_reporting_valid_sighting(self):

        # Setup environment
        scientist1 = User.objects.get(username="******")
        sighting = load_test_sighting()

        # Should be initially unassigned
        self.assertEqual(sighting.is_assigned, False)

        # Assigning should generate a tracker
        sighting.assign(scientist1, "Automatic assignment")

        # Searching sighting_tracking lists
        self.assertIn(sighting.tracker,
                      SightingTracking.active_assignments.all())
        self.assertNotIn(sighting.tracker,
                         SightingTracking.valid_sightings.all())
        self.assertNotIn(sighting.tracker,
                         SightingTracking.invalid_sightings.all())
        self.assertNotIn(sighting.tracker,
                         SightingTracking.spam_sightings.all())

        # Should now be assigned
        self.assertEqual(sighting.is_assigned, True)

        # Keep a reference to our tracker
        pk = sighting.tracker.pk

        # Check our tracker details
        self.assertEqual(sighting.tracker.person, scientist1)
        self.assertEqual(sighting.tracker.is_displayed_on_site, False)

        # Should be able to report valid sighting
        sighting.report_valid_without_photo("It's a healthy specimine.", True)

        # Grab the current sighting_tracking instance
        tracker = sighting.sighting_tracking.get(pk=pk)

        # Sighting note should be visible
        self.assertEqual(tracker.is_displayed_on_site, True)

        # Searching sighting_tracking again
        self.assertNotIn(tracker, SightingTracking.active_assignments.all())
        self.assertIn(tracker, SightingTracking.valid_sightings.all())
        self.assertNotIn(tracker, SightingTracking.invalid_sightings.all())
        self.assertNotIn(tracker, SightingTracking.spam_sightings.all())

        # Should now be unassigned
        self.assertEqual(sighting.is_assigned, False)

        # Should not be able to report valid sighting now
        with self.assertRaises(ObjectDoesNotExist):
            sighting.report_valid_without_photo("(private note: user=loser).",
                                                False)
Ejemplo n.º 8
0
    def test_get_recent(self):

        # Create a bunch of valid photo sightings to query
        for x in range(10):
            for species in Species.objects.all()[0:3]:
                sighting = load_test_sighting(species=species,
                                              photo_url="some/url")
                sighting.assign(self.scientist1)
                sighting.report_valid_with_photo(PHOTO_MATCHES_SPECIES_YES, "",
                                                 True)

        # ...and a bunch of other_species sightings
        for x in range(10):
            for other_species in ["DogFish", "CatFish"]:
                sighting = load_test_sighting(species=None,
                                              other_species=other_species,
                                              photo_url="some/url")
                sighting.assign(self.scientist1)
                sighting.report_valid_with_photo(PHOTO_MATCHES_SPECIES_YES, "",
                                                 True)

        # Should get 3 results for basic case
        self.assertEqual(Sighting.objects.get_recent().count(), 3)

        # Should not include the species selected to filter
        sightings = Sighting.objects.get_recent()
        s1 = sightings[0]
        self.assertNotIn(s1, Sighting.objects.get_recent(s1))

        # Should all match species provided as filter
        s2 = Sighting.objects.exclude(species__isnull=True)[0]
        self.assertEquals(
            [s2.species.pk] * 3,
            [s.species.pk for s in Sighting.objects.get_recent(s2)])

        # Or should all match other_species provided as filter
        s3 = Sighting.objects.filter(other_species="DogFish")[0]
        self.assertNotIn(s3, Sighting.objects.get_recent(s3))
        self.assertEquals(
            [s3.other_species] * 3,
            [s.other_species for s in Sighting.objects.get_recent(s3)])
Ejemplo n.º 9
0
    def test_get_photo_matches_species_response_for_no_photo(self):
        """
        Tests that get_photo_matches_species_response works.
        """
        # User logs a sighting
        sighting = load_test_sighting(user=self.user1)

        # Sighting gets assigned
        sighting.assign(self.scientist1)

        # Data scientists responses are saved
        responses = []
        ValidationResponse.objects.record_responses(sighting, responses)

        # Sighting is validated
        sighting.report_invalid("Details didn't make sense")

        # Fetch the get_photo_matches_species_response
        self.assertIsNone(ValidationResponse.objects.get_photo_matches_species_response(sighting))
Ejemplo n.º 10
0
    def test_get_public_photo(self):
        # start with sightings
        Sighting.objects.all().delete()
        self.assertEqual(Sighting.objects.get_public_photo().count(), 0)

        # log a sighting
        sighting1 = load_test_sighting()
        self.assertEqual(Sighting.objects.get_public_photo().count(), 0)

        # log a sighting with photo
        sighting1 = load_test_sighting(photo_url="test")
        self.assertEqual(Sighting.objects.get_public_photo().count(), 0)

        # log another and mark it as invalid
        sighting2 = load_test_sighting(photo_url="test")
        sighting2.assign(self.scientist1)
        sighting2.report_invalid("Not able to verify")
        self.assertEqual(Sighting.objects.get_public_photo().count(), 0)

        # log another and mark it as valid
        sighting3 = load_test_sighting(photo_url="test")
        sighting3.assign(self.scientist1)
        sighting3.report_valid_with_photo(PHOTO_MATCHES_SPECIES_YES,
                                          "Looks good", True)
        self.assertEqual(Sighting.objects.get_public_photo().count(), 1)

        # log another and mark it as valid
        sighting4 = load_test_sighting(photo_url="test")
        sighting4.assign(self.scientist1)
        sighting4.report_valid_with_photo(PHOTO_MATCHES_SPECIES_MAYBE,
                                          "Valid but photo isn't clear", True)
        self.assertEqual(Sighting.objects.get_public_photo().count(), 1)

        # log another and mark it as valid
        sighting5 = load_test_sighting(photo_url="test")
        sighting5.assign(self.scientist1)
        sighting5.report_valid_with_photo(PHOTO_MATCHES_SPECIES_NO,
                                          "Valid but photo isn't of any use",
                                          True)
        self.assertEqual(Sighting.objects.get_public_photo().count(), 1)
Ejemplo n.º 11
0
    def setUp(self):
        super(AdminTest, self).setUp()

        load_test_sighting()
Ejemplo n.º 12
0
    def setUp(self):
        super(ScientistTest, self).setUp()

        load_test_sighting()
Ejemplo n.º 13
0
    def setUp(self):
        super(UserTest, self).setUp()

        load_test_sighting()
Ejemplo n.º 14
0
    def setUp(self):
        super(AnonymousUserTest, self).setUp()

        load_test_sighting()
Ejemplo n.º 15
0
 def log_photo_sighting(self, **kwargs):
     return load_test_sighting(photo_url="test.jpg", **kwargs)
Ejemplo n.º 16
0
 def test_assign_validation(self):
     sighting = load_test_sighting()
     scientist1 = User.objects.get(username="******")
     sighting.assign(scientist1, "Automatic assignment")
     with self.assertRaises(Exception):
         sighting.assign(scientist1, "Automatic assignment")