def test_to_dict(self):
     c = CurrencyFactory()
     d = c.to_dict()
     keys = sorted(list(d.keys()))
     expected_keys = sorted(["id", "rate", "plus"])
     self.assertEqual(keys, expected_keys)
     self.assertEqual(c.currency, d["id"])
     self.assertEqual(c.rate, d["rate"])
     self.assertEqual(c.plus, d["plus"])
Пример #2
0
def test_currency_detail(rf, user):
    currency = CurrencyFactory.create()
    request = rf.get("")
    response = CurrencyViewSet.as_view({"get": "retrieve"})(request,
                                                            pk=currency.pk)
    assert response.status_code == status.HTTP_200_OK
    assert response.data["id"] == currency.id
 def test_rate_validation_error(self):
     msg = ("The rate parameter can have the following values: "
            "number (int or float), (rate_choices)".format(
                rate_choices=', '.join(models.currency.RATE_CHOICES)))
     with self.assertRaises(ValidationError) as e:
         CurrencyFactory(rate="err")
         self.assertEqual(str(e), msg)
Пример #4
0
    def test_payment_is_not_created_with_currency_mismatch_for_sender(self):
        account1 = AccountFactory(currency=CurrencyFactory(), balance=10)
        account2 = AccountFactory(currency=self.currency, balance=10)

        response = self.client.post(self.url,
                                    data={
                                        'from_account': account1.name,
                                        'to_account': account2.name,
                                        'amount': 1,
                                    })

        self.assertContains(response,
                            'currency mismatch',
                            status_code=status.HTTP_400_BAD_REQUEST)
        self.assertEquals(0, Payment.objects.count())
 def test_from_xml(self):
     c = CurrencyFactory()
     el = c.to_xml()
     parsed_c = Currency.from_xml(el)
     self.assertEqual(c.to_dict(), parsed_c.to_dict())
 def test_currency_validation_error(self):
     msg = "Price data is accepted only in: (formatted_choices)".format(
         formatted_choices=", ".join(models.currency.CURRENCY_CHOICES))
     with self.assertRaises(ValidationError) as e:
         CurrencyFactory(currency="UAN")
         self.assertEqual(str(e), msg)
 def test_to_xml_none_plus_attr(self):
     c = CurrencyFactory(plus=None)
     el = c.to_xml()
     expected_attribs = {"id": c.currency, "rate": c.rate}
     expected_xml = ET.Element("currency", expected_attribs)
     self.assertElementsEquals(el, expected_xml)
 def test_to_xml(self):
     c = CurrencyFactory()
     el = c.to_xml()
     expected_xml = ET.Element("currency", c.to_dict())
     self.assertEqual(ET.tostring(el), ET.tostring(expected_xml))
Пример #9
0
 def setUp(self):
     self.url = reverse('api:payments')
     self.currency = CurrencyFactory()
Пример #10
0
def test_currency_list(rf, user):
    currency = CurrencyFactory.create()
    request = rf.get("")
    response = CurrencyViewSet.as_view({"get": "list"})(request)
    assert response.status_code == status.HTTP_200_OK
    assert response.data[0]["id"] == currency.id
Пример #11
0
def currency_factory(session):
    yield CurrencyFactory(session)