def test_get_all_follow_txs_three(self): self.address = '0x1194e966965418c7d73a42cceeb254d875860356' EthAccountInfoFactory(address=self.address) follow = FollowFactory(user=self.user, address=self.address) follow.created = datetime.datetime(1971, 2, 1, 2, 3).replace(tzinfo=pytz.utc) follow.save() with switch_db(EthTransactions, config.MONGO_TEST_DATABASE_NAME) as TestEthTransactions: with switch_db(EthBlocks, config.MONGO_TEST_DATABASE_NAME) as TestEthBlocks: self.assertEqual(TestEthTransactions.objects.count(), 4) self.assertEqual(TestEthBlocks.objects.count(), 3) response = self.client.get(reverse('timeline-list')) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(len(response.data), 1) self.assertEqual(response.data[0]['address'], '0x1194e966965418c7d73a42cceeb254d875860356') self.assertEqual(response.data[0]['address2'], '0x42e6723a0c884e922240e56d7b618bec96f35800') self.assertEqual(response.data[0]['sent'], False) self.assertEqual(response.data[0]['timestamp'], 1442886001) self.assertEqual(response.data[0]['amount_in_wei'], 1) self.assertEqual(response.data[0]['address_name'], 'Test Eth Account Name') self.assertTrue( response.data[0]['address_avatar'].endswith('jpg'), True)
def test_get_all_follow_txs_two(self): self.address = '0x42e6723a0c884e922240e56d7b618bec96f35800' follow = FollowFactory(user=self.user, address=self.address) follow.created = datetime.datetime.fromtimestamp(1442886501).replace( tzinfo=pytz.utc) follow.save() with switch_db(EthTransactions, config.MONGO_TEST_DATABASE_NAME) as TestEthTransactions: with switch_db(EthBlocks, config.MONGO_TEST_DATABASE_NAME) as TestEthBlocks: self.assertEqual(TestEthTransactions.objects.count(), 4) self.assertEqual(TestEthBlocks.objects.count(), 3) response = self.client.get(reverse('timeline-list')) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(len(response.data), 3) self.assertEqual(response.data[0]['address'], '0x42e6723a0c884e922240e56d7b618bec96f35800') self.assertEqual(response.data[0]['address2'], '0x42e6723a0c884e922240e56d7b618bec96f35801') self.assertEqual(response.data[0]['sent'], True) self.assertEqual(response.data[1]['address'], '0x42e6723a0c884e922240e56d7b618bec96f35800') self.assertEqual(response.data[1]['address2'], '0x42e6723a0c884e922240e56d7b618bec96f35801') self.assertEqual(response.data[1]['sent'], True) self.assertEqual(response.data[2]['address'], '0x42e6723a0c884e922240e56d7b618bec96f35800') self.assertEqual(response.data[2]['address2'], '0x42e6723a0c884e922240e56d7b618bec96f35801') self.assertEqual(response.data[2]['sent'], False)
def setUp(self): super(FollowViewSet, self).setUp() self.user_2 = UserFactory(username='******') self.address_1 = '0x42e6723a0c884e922240e56d7b618bec96f35801' self.address_2 = '0x42e6723a0c884e922240e56d7b618bec96f35802' self.address_3 = '0x42e6723a0c884e922240e56d7b618bec96f35803' self.follow_1 = FollowFactory(user=self.user, address=self.address_1) self.follow_2 = FollowFactory(user=self.user, address=self.address_2) self.follow_other_user = FollowFactory(user=self.user_2, address=self.address_3) self.url_detail = reverse('follows-detail', args=(self.address_1, )) self.url_detail_other = reverse('follows-detail', args=(self.address_3, )) self.url_list = reverse('follows-list')
def test_create_follow_same_address(self): FollowFactory(address='0x2a65aca4d5fc5b5c859090a6c34d164135398226', user=self.user) response = self.client.post( self.url_list, data={ 'name': 'super_name', 'address': '0x2a65aca4d5fc5b5c859090a6c34d164135398226' }) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual( response.data, { 'non_field_errors': ['The fields user, address must make a unique set.'] })