コード例 #1
0
    def test_user_preference_currency(self):
        """Test that valid currency codes are saved."""
        user = None
        serializer = UserSerializer(data=self.user_data,
                                    context=self.request_context)
        if serializer.is_valid(raise_exception=True):
            user = serializer.save()

        kwargs = {"context": {"user": user}}
        data = {
            "name": "currency",
            "description": self.fake.text(),
            "preference": {
                "currency": random.choice(_currency_symbols())
            },
        }

        pref = list(UserPreference.objects.filter(user=user,
                                                  name="currency")).pop()
        self.assertIsNotNone(pref)
        self.assertIsInstance(pref, UserPreference)

        serializer = UserPreferenceSerializer(pref, data=data, **kwargs)
        if serializer.is_valid(raise_exception=True):
            pref = serializer.save()

        self.assertEqual(pref.name, data.get("name"))
        self.assertEqual(pref.description, data.get("description"))
        self.assertEqual(pref.preference, data.get("preference"))
コード例 #2
0
    def test_user_preference_currency(self):
        """Test that valid currency codes are saved."""
        user = None
        serializer = UserSerializer(data=self.user_data,
                                    context=self.request_context)
        if serializer.is_valid(raise_exception=True):
            user = serializer.save()

        kwargs = {'context': {'user': user}}
        data = {
            'name': 'currency',
            'description': self.fake.text(),
            'preference': {
                'currency': random.choice(_currency_symbols())
            }
        }

        pref = list(UserPreference.objects.filter(user=user,
                                                  name='currency')).pop()
        self.assertIsNotNone(pref)
        self.assertIsInstance(pref, UserPreference)

        serializer = UserPreferenceSerializer(pref, data=data, **kwargs)
        if serializer.is_valid(raise_exception=True):
            pref = serializer.save()

        self.assertEqual(pref.name, data.get('name'))
        self.assertEqual(pref.description, data.get('description'))
        self.assertEqual(pref.preference, data.get('preference'))
コード例 #3
0
 def _meter(self):
     """Populate AzureMeter."""
     obj = AzureMeter(
         meter_id=uuid4(),
         meter_name=self.config.meter_name,
         meter_category=self.config.meter_category,
         meter_subcategory=self.config.meter_subcategory,
         meter_region=self.config.resource_location,
         resource_rate=random.random(),
         currency=random.choice(_currency_symbols()),
     )
     obj.save()
     return obj