Beispiel #1
0
    def test_integration(self, subrecords):
        subrecords.return_value = [Colour]

        colour_1 = Colour(episode=self.episode)
        colour_1.update_from_dict({
            "name": "blue",
        }, self.user)
        consistency_token_1 = colour_1.consistency_token
        colour_2 = Colour(episode=self.episode)
        colour_2.update_from_dict({
            "name": "orange",
        }, self.user)
        consistency_token_2 = colour_2.consistency_token

        colour_dict_1 = colour_1.to_dict(self.user)
        colour_dict_1["name"] = "Red"
        colour_dict_1.pop("episode_id")
        colour_dict_2 = colour_2.to_dict(self.user)
        colour_dict_2.pop("episode_id")
        provided_dict = dict(colour=[colour_dict_1, colour_dict_2])
        dumped = json.loads(json.dumps(provided_dict, cls=OpalSerializer))

        self.pathway_example.save(dumped, self.user, self.patient,
                                  self.episode)

        saved_colour_1 = self.episode.colour_set.get(id=colour_1.id)
        self.assertNotEqual(saved_colour_1.consistency_token,
                            consistency_token_1)

        saved_colour_2 = self.episode.colour_set.get(id=colour_2.id)
        self.assertEqual(saved_colour_2.consistency_token, consistency_token_2)
Beispiel #2
0
 def test_list_with_some_contents(self):
     c1 = Colour(name="blue", episode=self.episode).save()
     c2 = Colour(name="red", episode=self.episode).save()
     mock_request = MagicMock(name='mock request')
     mock_request.user = self.user
     response = self.viewset().list(mock_request)
     data = [{
         u'consistency_token': u'',
         u'created': None,
         u'created_by_id': None,
         u'episode_id': 1,
         u'id': 1,
         u'name': u'blue',
         u'updated': None,
         u'updated_by_id': None
     }, {
         u'consistency_token': u'',
         u'created': None,
         u'created_by_id': None,
         u'episode_id': 1,
         u'id': 2,
         u'name': u'red',
         u'updated': None,
         u'updated_by_id': None
     }]
     self.assertEqual(data, json.loads(response.content.decode('UTF-8')))
Beispiel #3
0
    def test_sender(self):
        mock_receiver = MagicMock(name='mock receiver')

        @receiver(worker.subrecord_post_save, sender=Colour)
        def rec(*a, **k):
            mock_receiver(*a, **k)

        p, e = self.new_patient_and_episode_please()
        blue = Colour(episode=e, name='Blue')
        blue.save()

        self.assertEqual(1, mock_receiver.call_count)
    def test_sender(self):
        mock_receiver = MagicMock(name='mock receiver')

        @receiver(worker.subrecord_post_save, sender=Colour)
        def rec(*a, **k):
            mock_receiver(*a, **k)

        p, e = self.new_patient_and_episode_please()
        blue = Colour(episode=e, name='Blue')
        blue.save()


        self.assertEqual(1, mock_receiver.call_count)
Beispiel #5
0
    def test_integration(self, subrecords):
        subrecords.return_value = [Colour]

        colour_1 = Colour(episode=self.episode)
        colour_1.update_from_dict(
            {
                "name": "blue",
            },
            self.user
        )
        consistency_token_1 = colour_1.consistency_token
        colour_2 = Colour(episode=self.episode)
        colour_2.update_from_dict(
            {
                "name": "orange",
            },
            self.user
        )
        consistency_token_2 = colour_2.consistency_token

        colour_dict_1 = colour_1.to_dict(self.user)
        colour_dict_1["name"] = "Red"
        colour_dict_1.pop("episode_id")
        colour_dict_2 = colour_2.to_dict(self.user)
        colour_dict_2.pop("episode_id")
        provided_dict = dict(
            colour=[colour_dict_1, colour_dict_2]
        )
        dumped = json.loads(json.dumps(provided_dict, cls=OpalSerializer))

        self.pathway_example.save(
            dumped, self.user, self.patient, self.episode
        )

        saved_colour_1 = self.episode.colour_set.get(id=colour_1.id)
        self.assertNotEqual(
            saved_colour_1.consistency_token, consistency_token_1
        )

        saved_colour_2 = self.episode.colour_set.get(id=colour_2.id)
        self.assertEqual(
            saved_colour_2.consistency_token, consistency_token_2
        )
Beispiel #6
0
 def test_get_defaults_with_a_date_throws_an_error(self):
     name = Colour._meta.get_field("name")
     with patch.object(name, "get_default") as get_default:
         get_default.return_value = datetime.date.today()
         with self.assertRaises(exceptions.APIError):
             Colour._get_field_default("name")
Beispiel #7
0
 def test_get_defaults_from_ftfk_when_there_are_no_defaults(self):
     self.assertEqual(None, Colour._get_field_default("name"))
Beispiel #8
0
 def test_get_defaults_with_a_date_throws_an_error(self):
     name = Colour._meta.get_field("name")
     with patch.object(name, "get_default") as get_default:
         get_default.return_value = datetime.date.today()
         with self.assertRaises(exceptions.APIError):
             Colour._get_field_default("name")
Beispiel #9
0
 def test_get_defaults_from_ftfk_when_there_are_no_defaults(self):
     self.assertEqual(None, Colour._get_field_default("name"))