Beispiel #1
0
    def test_taxlots_merge_without_losing_notes(self):
        note_factory = FakeNoteFactory(organization=self.org, user=self.user)

        # Create 3 Notes and distribute them to the two -Views.
        note1 = note_factory.get_note(name='non_default_name_1')
        note2 = note_factory.get_note(name='non_default_name_2')
        self.view_1.notes.add(note1)
        self.view_1.notes.add(note2)

        note3 = note_factory.get_note(name='non_default_name_3')
        self.view_2.notes.add(note2)
        self.view_2.notes.add(note3)

        # Merge the taxlots
        url = reverse('api:v2:taxlots-merge') + '?organization_id={}'.format(
            self.org.pk)
        post_params = json.dumps(
            {'state_ids': [self.state_2.pk, self.state_1.pk]})
        self.client.post(url, post_params, content_type='application/json')

        # The resulting -View should have 3 notes
        view = TaxLotView.objects.first()

        self.assertEqual(view.notes.count(), 3)
        note_names = list(view.notes.values_list('name', flat=True))
        self.assertCountEqual(note_names, [note1.name, note2.name, note3.name])
Beispiel #2
0
class TestNotes(TestCase):
    def setUp(self):
        self.user = User.objects.create_superuser('*****@*****.**',
                                                  '*****@*****.**',
                                                  'test_pass')
        self.org, _, _ = create_organization(self.user)

        # Fake Factories
        self.property_view_factory = FakePropertyViewFactory(
            organization=self.org)
        self.note_factory = FakeNoteFactory(organization=self.org,
                                            user=self.user)

    def test_note_assignments(self):
        """Make sure that properties can contain notes"""
        pv = self.property_view_factory.get_property_view(
            organization=self.org)
        note1 = self.note_factory.get_note()
        note2 = self.note_factory.get_note()

        pv.notes.add(note1)
        pv.notes.add(note2)

        self.assertTrue(pv)
        self.assertIn(note1, pv.notes.all())
        self.assertIn(note2, pv.notes.all())
Beispiel #3
0
class TestNotes(TestCase):
    def setUp(self):
        user_details = {
            'username': '******',
            'password': '******',
        }
        self.user = User.objects.create_superuser(email='*****@*****.**',
                                                  **user_details)
        self.org = Organization.objects.create()
        OrganizationUser.objects.create(user=self.user, organization=self.org)

        # Fake Factories
        self.property_view_factory = FakePropertyViewFactory(
            organization=self.org)
        self.note_factory = FakeNoteFactory(organization=self.org,
                                            user=self.user)

    def test_note_assignments(self):
        """Make sure that properties can contain notes"""
        pv = self.property_view_factory.get_property_view(
            organization=self.org)
        note1 = self.note_factory.get_note()
        note2 = self.note_factory.get_note()

        pv.notes.add(note1)
        pv.notes.add(note2)

        self.assertTrue(pv)
        self.assertIn(note1, pv.notes.all())
        self.assertIn(note2, pv.notes.all())
Beispiel #4
0
class NoteViewTests(TestCase):
    def setUp(self):
        user_details = {
            'username': '******',
            'password': '******',
            'email': '*****@*****.**',
        }
        self.user = User.objects.create_superuser(**user_details)
        self.org = Organization.objects.create()
        OrganizationUser.objects.create(user=self.user, organization=self.org)

        # Fake Factories
        self.property_view_factory = FakePropertyViewFactory(
            organization=self.org)
        self.taxlot_view_factory = FakeTaxLotViewFactory(organization=self.org)
        self.note_factory = FakeNoteFactory(organization=self.org,
                                            user=self.user)

        self.client.login(**user_details)

        # create a property view with some notes
        self.pv = self.property_view_factory.get_property_view(
            organization=self.org)
        self.note1 = self.note_factory.get_note()
        self.note2 = self.note_factory.get_log_note()

        self.pv.notes.add(self.note1)
        self.pv.notes.add(self.note2)

        # create a taxlot with some views
        self.tl = self.taxlot_view_factory.get_taxlot_view(
            organization=self.org)
        self.note3 = self.note_factory.get_note()
        self.note4 = self.note_factory.get_log_note()
        self.tl.notes.add(self.note3)
        self.tl.notes.add(self.note4)

    def test_get_notes_property(self):
        url = reverse('api:v2.1:property-notes-list', args=[self.pv.pk])
        response = self.client.get(url)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        result = json.loads(response.content)
        results = result['results']
        self.assertEqual(len(results), 2)
        self.assertEqual(results[0]['note_type'], 'Log')
        self.assertEqual(results[0]['user_id'], self.user.pk)

        # most recent log is displayed first
        expected_log_data = {
            u'property_state': [{
                u'field': u'address_line_1',
                u'previous_value': u'123 Main Street',
                u'new_value': u'742 Evergreen Terrace'
            }]
        }
        self.assertEqual(results[0]['log_data'], expected_log_data)
        self.assertEqual(results[1]['note_type'], 'Note')

    def test_create_note_property(self):
        url = reverse('api:v2.1:property-notes-list', args=[self.pv.pk])

        payload = {
            "note_type": "Note",
            "name": "A New Note",
            "text": "This building is much bigger than reported",
        }
        response = self.client.post(url,
                                    data=json.dumps(payload),
                                    content_type='application/json')
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        result = json.loads(response.content)

        # check that the note was attached to the property
        self.assertEqual(result['note_type'], 'Note')
        self.assertEqual(result['text'], payload['text'])
        self.assertEqual(result['property_view_id'], self.pv.pk)
        self.assertIsNone(result['taxlot_view_id'])
        self.assertEqual(result['organization_id'], self.org.pk)
        self.assertEqual(result['user_id'], self.user.pk)

    def test_create_note_taxlot(self):
        url = reverse('api:v2.1:taxlot-notes-list', args=[self.tl.pk])

        payload = {
            "note_type": "Note",
            "name": "A New Note",
            "text": "The taxlot is not correct",
        }
        response = self.client.post(url,
                                    data=json.dumps(payload),
                                    content_type='application/json')
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        result = json.loads(response.content)

        # check that the note was attached to the property
        self.assertEqual(result['note_type'], 'Note')
        self.assertEqual(result['text'], payload['text'])
        self.assertIsNone(result['property_view_id'])
        self.assertEqual(result['taxlot_view_id'], self.tl.pk)

    def test_update_note(self):
        url = reverse('api:v2.1:taxlot-notes-detail',
                      args=[self.tl.pk, self.note3.pk])

        payload = {"name": "update, validation should fail"}
        response = self.client.put(url,
                                   data=json.dumps(payload),
                                   content_type='application/json')
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(
            json.loads(response.content), {
                "text": ["This field is required."],
                "note_type": ["This field is required."]
            })

        payload = {
            "name": "update",
            "text": "new data with put",
            "note_type": "Note"
        }
        response = self.client.put(url,
                                   data=json.dumps(payload),
                                   content_type='application/json')
        result = json.loads(response.content)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(result['name'], payload['name'])
        self.assertEqual(result['text'], payload['text'])

    def test_patch_note(self):
        url = reverse('api:v2.1:taxlot-notes-detail',
                      args=[self.tl.pk, self.note4.pk])

        payload = {"name": "new note name that is meaningless"}
        response = self.client.patch(url,
                                     data=json.dumps(payload),
                                     content_type='application/json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        result = json.loads(response.content)
        self.assertEqual(result['name'], payload['name'])

    def test_get_detail_and_delete_note(self):
        note5 = self.note_factory.get_note()
        self.pv.notes.add(note5)

        url = reverse('api:v2.1:property-notes-detail',
                      args=[self.pv.pk, note5.pk])
        response = self.client.get(url, content_type='application/json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        result = json.loads(response.content)
        self.assertEqual(result['property_view_id'], self.pv.pk)
        self.assertEqual(result['id'], note5.pk)

        # now delete the note
        response = self.client.delete(url, content_type='application/json')
        # delete returns no content
        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)

        # note should return nothing now
        response = self.client.get(url, content_type='application/json')
        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)