Exemplo n.º 1
0
class TestStrategyListView(TestCase):
    def setUp(self):
        self.user = UserFactory()
        self.user.set_password('123')
        self.user.save()
        self.account = AccountFactory(user=self.user)

    def test_account_list_view_success(self):
        client.login(username=self.user.username, password='******')

        response = client.get(reverse('profile_app:accounts'))
        self.assertEqual(
            list(response.context[0]['account_list']),
            list(Account.objects.filter(user=self.user, is_active=True)))
Exemplo n.º 2
0
class TestStrategyListView(TestCase):
    def setUp(self):
        self.user = UserFactory()
        self.user.set_password('123')
        self.user.save()
        self.strategy = StrategyFactory(user=self.user)

    def test_strategy_list_view(self):
        client.login(username=self.user.username, password='******')

        response = client.get(reverse('strategy:list'))
        self.assertEqual(
            list(response.context[0]['strategy_list']), list(Strategy.objects.filter(user=self.user, is_deleted=False))
        )
Exemplo n.º 3
0
class TestAccountCreateView(TestCase):

    def setUp(self):
        self.user = UserFactory(username='******')
        self.user.set_password('123')
        self.user.save()

    def test_creating_account_success(self):
        client.login(username=self.user.username, password='******')
        api_key, api_secret = "K" * 32, "S" * 32
        test_account = {
            "exchange": EXCHANGES_CHOICES[0][0],
            "api_key": api_key,
            "api_secret": api_secret,
        }
        admin = UserFactory(username='******')
        client.force_login(admin)

        response = client.post(reverse("api:api_account_create"), data=test_account)
        data = response.json()
        self.assertEqual(response.status_code, HTTP_201_CREATED)
        self.assertEqual(data['data']['user'], admin.id)
        self.assertEqual(data['data']['api_key'], api_key)
        self.assertEqual(data['data']['api_secret'], api_secret)

    def test_creating_account_without_exchange(self):
        client.login(username=self.user.username, password='******')
        api_key, api_secret = "K" * 32, "S" * 32
        teset_account = {
            "api_key": api_key,
            "api_secret": api_secret,
        }
        response = client.post(reverse("api:api_account_create"), data=teset_account)
        data = response.json()
        self.assertFalse(data['success'])
        self.assertEqual(data['errors']['exchange'], ['This field may not be null.', ])

    def test_creating_account_without_api_credentials_raises_exception(self):
        client.login(username=self.user.username, password='******')
        test_account = {
            "exchange": EXCHANGES_CHOICES[0][0],
        }
        response = client.post(reverse("api:api_account_create"), data=test_account)
        data = response.json()
        self.assertFalse(data['success'])
        self.assertEqual(data['errors']['api_key'], ['This field may not be null.', ])
        self.assertEqual(data['errors']['api_secret'], ['This field may not be null.', ])
Exemplo n.º 4
0
class TestStrategyCreateView(TestCase):
    def setUp(self):
        self.user = UserFactory(username='******')
        self.user.set_password('123')
        self.user.save()

    def test_creating_strategy_success(self):
        client.login(username=self.user.username, password='******')
        test_strategy = {
            "key": ["EXCHANGE", "KEY", "SECRET", "NAME_COIN", "NAME_COIN_TWO"],
            "value": ["bittrex", "K" * 32, "S" * 32, "BTC", "ETH"],
        }
        admin = UserFactory(username='******')
        client.force_login(admin)

        response = client.post(reverse("api:api_strategy_create"), data=test_strategy)
        data = response.json()
        self.assertEqual(data['success'], True)
        self.assertEqual(data['data']['user'], admin.id)

    def test_creating_account_without_exchange(self):
        client.login(username=self.user.username, password='******')
        api_key, api_secret = "K" * 32, "S" * 32
        teset_account = {
            "api_key": api_key,
            "api_secret": api_secret,
        }
        response = client.post(reverse("api:api_account_create"), data=teset_account)
        data = response.json()
        self.assertFalse(data['success'])
        self.assertEqual(data['errors']['exchange'], ['This field may not be null.', ])

    def test_creating_account_without_api_credentials_raises_exception(self):
        client.login(username=self.user.username, password='******')
        test_account = {
            "exchange": EXCHANGES_CHOICES[0][0],
        }
        response = client.post(reverse("api:api_account_create"), data=test_account)
        data = response.json()
        self.assertFalse(data['success'])
        self.assertEqual(data['errors']['api_key'], ['This field may not be null.', ])
        self.assertEqual(data['errors']['api_secret'], ['This field may not be null.', ])
Exemplo n.º 5
0
    def test_creating_strategy_success(self):
        client.login(username=self.user.username, password='******')
        test_strategy = {
            "key": ["EXCHANGE", "KEY", "SECRET", "NAME_COIN", "NAME_COIN_TWO"],
            "value": ["bittrex", "K" * 32, "S" * 32, "BTC", "ETH"],
        }
        admin = UserFactory(username='******')
        client.force_login(admin)

        response = client.post(reverse("api:api_strategy_create"), data=test_strategy)
        data = response.json()
        self.assertEqual(data['success'], True)
        self.assertEqual(data['data']['user'], admin.id)
Exemplo n.º 6
0
    def test_creating_account_success(self):
        client.login(username=self.user.username, password='******')
        api_key, api_secret = "K" * 32, "S" * 32
        test_account = {
            "exchange": EXCHANGES_CHOICES[0][0],
            "api_key": api_key,
            "api_secret": api_secret,
        }
        admin = UserFactory(username='******')
        client.force_login(admin)

        response = client.post(reverse("api:api_account_create"), data=test_account)
        data = response.json()
        self.assertEqual(response.status_code, HTTP_201_CREATED)
        self.assertEqual(data['data']['user'], admin.id)
        self.assertEqual(data['data']['api_key'], api_key)
        self.assertEqual(data['data']['api_secret'], api_secret)
Exemplo n.º 7
0
 def setUp(self):
     self.user = UserFactory()
     self.user.set_password('123')
     self.user.save()
     self.strategy = StrategyFactory(user=self.user)
Exemplo n.º 8
0
 def setUp(self):
     self.user = UserFactory(username='******')
     self.user.set_password('123')
     self.user.save()
Exemplo n.º 9
0
class TestStrategyDeleteView(TestCase):
    def setUp(self):
        self.user = UserFactory(username='******')
        self.user.set_password('123')
        self.user.save()

        self.strategy = StrategyFactory(user=self.user)

    def test_strategy_delete_view_do_not_process_get(self):
        client.login(username=self.user.username, password='******')

        response = client.get(
            reverse('api:strategy_delete_view', args=(self.strategy.uuid, ))
        )
        self.assertTrue(response.status_code, HTTP_405_METHOD_NOT_ALLOWED)

    def test_strategy_set_value_view(self):
        client.login(username=self.user.username, password='******')

        key = "key"
        value = "value"
        new_value = "new value"
        self.strategy.data = {key: value}
        self.strategy.save(update_fields=['data', ])

        response = client.post(
            reverse('api:strategy_set_value_view', args=(self.strategy.uuid, )), data={"key": key, "value": new_value}
        )
        self.assertEqual(response.status_code, HTTP_200_OK)
        self.assertEqual(response.json()['success'], True)
        self.assertEqual(response.json()['data']['key'], new_value)

    def test_strategy_delete_key_view(self):
        client.login(username=self.user.username, password='******')

        key = "key"
        value = "value"
        self.strategy.data = {key: value}
        self.strategy.save(update_fields=['data', ])

        response = client.post(
            reverse('api:strategy_delete_key_view', args=(self.strategy.uuid,)), data={"key": key}
        )
        self.assertEqual(response.status_code, HTTP_200_OK)
        self.assertEqual(response.json()['data'], dict())

    def test_strategy_delete_key_view_does_not_affect_another_keys(self):
        client.login(username=self.user.username, password='******')

        key = "key"
        value = "value"
        test_data = {
            key: value,
            "test-key-1": "Test value 1",
            "test-key-2": "Test value 2",
        }
        self.strategy.data = test_data
        self.strategy.save(update_fields=['data', ])

        response = client.post(
            reverse('api:strategy_delete_key_view', args=(self.strategy.uuid,)), data={"key": key}
        )

        del test_data[key]
        self.assertEqual(response.json()['data'], test_data)
Exemplo n.º 10
0
 def setUp(self):
     self.user = UserFactory()
     self.user.set_password('123')
     self.user.save()
     self.account = AccountFactory(user=self.user)