def test__edit_game(self): # Arrange game = Game.manager.create(JsonObjects.game()) new_game_data = JsonObjects.game(name="new game") # Act game_created = Game.manager.edit(game, new_game_data) # Assert self.assertEqual(game_created.id, 1) self.assertEqual(game_created.name, "new game")
def test__edited_banner_configuration(self): # Arrange banner = BannerConfiguration.manager.create(JsonObjects.banner()) new_banner_data = JsonObjects.banner( banner_configuration_name="new banner") # Act banner_created = BannerConfiguration.manager.edit( banner, new_banner_data) # Assert self.assertEqual(banner_created.id, 1) self.assertEqual(banner_created.banner_configuration_name, "new banner")
def setUpClass(self): super(CampaignSerializerTestCase, self).setUpClass() region1_data = JsonObjects.region() region2_data = JsonObjects.region(name="Brazil", countries=[["Brazil", "BR"]]) country1_data = region1_data.pop(Field.COUNTRIES)[0] country2_data = region2_data.pop(Field.COUNTRIES)[0] region1 = Region(**region1_data) region1.save() region2 = Region(**region2_data) region2.save() region1.countries = Country.manager.filter(**country1_data) region2.countries = Country.manager.filter(**country2_data)
def setUpClass(self): super(UserPostError, self).setUpClass() self.user_json = JsonObjects.user() self.user = User.objects.create_user(**self.user_json) self.user.is_superuser = True self.user.save() self.url_user_post = '/gmm/user/'
def test__created_banner_configuration(self): # Arrange banner_data = JsonObjects.banner() # Act banner_created = BannerConfiguration.manager.create(banner_data) # Assert self.assertEqual(banner_created.id, 1)
def test__campaign_name_bigger_than_50__error(self): # Act serializer = CampaignSerializer( data=JsonObjects.campaign(name=self.NAME_WITH_51_CHARACTERS)) serializer.is_valid() # Assert self.assertEqual(self.ERRO_NAME_BIGGER_THAN_50, str(serializer.errors[Field.NAME]))
def test__create_game(self): # Arrange game_data = JsonObjects.game() # Act game_created = Game.manager.create(game_data) # Assert self.assertEqual(game_created.id, 1)
class ParticipantSerializerTestCase(TestCase): environment1 = JsonObjects.environment_info_1() participant = JsonObjects.participant_without_location( location=environment1, player=PLAYER) participant_serializer = ParticipationSerializer(data=participant) participant_invalid = JsonObjects.participant_without_location() participant_serializer_invalid = ParticipationSerializer( data=participant_invalid) def test_json_participant_is_valid(self): is_valid = self.participant_serializer.is_valid(raise_exception=True) self.assertTrue(is_valid) def test_json_participant_is_not_valid(self): is_valid = self.participant_serializer_invalid.is_valid( raise_exception=False) self.assertFalse(is_valid)
def test__create_campaign_with_begin_date_bigger_than_end_date__false(self): # Arrange data = JsonObjects.campaign(begin_date="2055-09-04T19:13:40Z") # Act serializer = CampaignSerializer(data=data) is_true = serializer.is_valid() # Assert self.assertFalse(is_true)
def test__get__game_does_not_exist__status_200(self, mock_404): # Arrange request = self.factory.get( self.url, HTTP_X_ENV=JsonObjects.environment_info_1(), HTTP_X_TOKEN=EnvironmentConfiguration.get_token(False)) # Act response = self.view(request) # Assert self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
def test__get__banners_found__status_200(self, mock_404, mock_filter): # Arrange request = self.factory.get( self.url, HTTP_X_ENV=JsonObjects.environment_info_1(), HTTP_X_TOKEN=EnvironmentConfiguration.get_token(False)) # Act response = self.view(request) # Assert self.assertEqual(response.status_code, status.HTTP_200_OK)
def test__get__data_exists_exists__status_200(self): # Arrange request = self.factory.get( self.url, HTTP_X_ENV=JsonObjects.environment_info_1(), HTTP_X_TOKEN=EnvironmentConfiguration.get_token(False)) # Act response = self.view(request, 1, 1, '*****@*****.**') # Assert self.assertEqual(response.status_code, status.HTTP_200_OK)
def test__create_campaign__new_campaign(self): # Arrange create_game(name="zennyworldz", analytics_view_id=00000, package_name="br.com.asus.app.zennyworldz", form_template=FORM_TEMPLATE, game_image="https://gamma-test.s3.amazonaws.com/game/game_icon_1460643319494.jpg", api_key="lr4cE2jGYJj46H8Gw0esY6k8Ll98Ej6D", game_service_id=1) # Act serializer = CampaignSerializer().create(JsonObjects.campaign()) # Assert self.assertIsNotNone(serializer) self.assertFalse(serializer.active)
def test__post__valid_data__status_201(self, mock_serializer): # Arrange request = self.factory.post( self.url, {}, HTTP_X_ENV=JsonObjects.environment_info_1(), HTTP_X_TOKEN=EnvironmentConfiguration.get_token(False)) # Act response = self.view(request, 1) # Assert self.assertEqual(response.status_code, status.HTTP_201_CREATED)
def test__get__campaign_does_not_exist__status_200(self): # Arrange self.mock_participation_manager.side_effect = Campaign.DoesNotExist() request = self.factory.get( self.url, HTTP_X_ENV=JsonObjects.environment_info_1(), HTTP_X_TOKEN=EnvironmentConfiguration.get_token(False)) # Act response = self.view(request, 1, 1, '*****@*****.**') # Assert self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
def test__post__game_does_not_exist__status_201(self, mock_serializer): # Arrange self.mock_game_manager.side_effect = Game.DoesNotExist request = self.factory.post( self.url, {}, HTTP_X_ENV=JsonObjects.environment_info_1(), HTTP_X_TOKEN=EnvironmentConfiguration.get_token(False)) # Act response = self.view(request, 1) # Assert self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
def test__post__valid_data__status_201(self, mock_serializer, mock_device_user): # Arrange mock_instance = Mock() mock_serializer.return_value = mock_instance request = self.factory.post( self.url, {'player': {'email': '*****@*****.**', 'gpg_id': '1', 'gcm_id': '1'}}, HTTP_X_ENV=JsonObjects.environment_info_1(), HTTP_X_TOKEN=EnvironmentConfiguration.get_token(False)) # Act response = self.view(request, 1, 1) # Assert self.assertEqual(response.status_code, status.HTTP_201_CREATED)
def test__post__existing_player__status_201(self, mock_serializer): # Arrange mock_instance = Mock() mock_serializer.return_value = mock_instance mock_instance.create_or_update.return_value = False request = self.factory.post( self.url, {}, HTTP_X_ENV=JsonObjects.environment_info_1(), HTTP_X_TOKEN=EnvironmentConfiguration.get_token(False)) # Act response = self.view(request, 1) # Assert self.assertEqual(response.status_code, status.HTTP_200_OK)
def setUp(self): self.game = create_game("Zennynho", package_name="br.com.asus.test.zenny", game_service_id="SERVICE_Id_XPTO", api_key="key") self.user = create_user("*****@*****.**", "gpg_id", "gcm_id") self.environment_info_data = JsonObjects.environment_info_1() create_device_user(game=self.game, gcm_id="testing_gcm_id", email="*****@*****.**") self.game2 = create_game("Zenny2", package_name="br.com.asus.test.zenny2", game_service_id="SERVICE_ID_2", api_key="key2")
def test__post__invalid_data__status_400(self, mock_serializer): # Arrange mock_instance = Mock() mock_serializer.return_value = mock_instance mock_instance.is_valid.side_effect = ValidationError({}) request = self.factory.post( self.url, {}, HTTP_X_ENV=JsonObjects.environment_info_1(), HTTP_X_TOKEN=EnvironmentConfiguration.get_token(False)) # Act response = self.view(request, 1) # Assert self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
def test__update_expiration_date__campaign__campaign_to_update__campaign_expiration_date_updated( self): # Arrange campaign = Campaign(name="brazil-campaign", expiration_date="2051-09-04T19:13:40Z", active=False, regions=[{ "id": 1, "name": "South America", "countries": [{ "id": 1, "country_name": "Brazil", "country_code": "BR" }, { "id": 2, "country_name": "Argentina", "country_code": "AR" }], "color": "#000000" }], begin_date="2050-09-04T19:13:40Z", end_date="2051-09-04T19:13:40Z", participant_limit=10000, forms=[{ 'game': 1, 'form_template': "form_template", 'form_value': "form_value" }]) # Act CampaignManager().update_expiration_date( campaign, JsonObjects.campaign(end_date="2055-09-04T19:13:40Z")) # Assert self.asserEquals(campaign.expiration_date, JsonObjects.campaign()[Field.END])
def setUpClass(self): super(PushTestCase, self).setUpClass() self.user_json = JsonObjects.user() self.user = User.objects.create_user(**self.user_json) self.user.is_superuser = True self.user.save()
def setUp(self): self.region_data = JsonObjects.region() self.region_countries_data = self.region_data.pop(Field.COUNTRIES) self.region = Region.manager.create(self.region_data, self.region_countries_data)
def setUpClass(self): super(GameView, self).setUpClass() self.user = User.objects.create_user(**JsonObjects.user()) self.user.is_superuser = True self.user.save()
def setUp(self): self.token = self.login() self.data = JsonObjects.game() self.resp = self.client.post('/gmm/game/', self.data, HTTP_AUTHORIZATION=self.token)
def test__active_campaign__not_null(self): # Act serializer = CampaignSerializer(data=JsonObjects.campaign(active=None)) serializer.is_valid() self.assertEqual(self.ERROR_NOT_NULL, str(serializer.errors[Field.ACTIVE]))
class ImageUploadPostTestCase(APITestCase): FILE = realpath(Constants.IMAGE_PATH_TO_TEST_UPLOAD) path_mock = realpath('game') folder = "%s/game_icon_%s.jpg" % (settings.GAME_IMAGE_FOLDER, time.time()) url = reverse(IMAGE) image_file = open(FILE, 'rb') data = JsonObjects.image(image=image_file, folder=folder) @classmethod def setUpClass(self): super(ImageUploadPostTestCase, self).setUpClass() self.user = User.objects.create_user(**JsonObjects.user()) @classmethod def tearDownClass(self): super(ImageUploadPostTestCase, self).tearDownClass() self.user.delete() if os.path.exists(self.path_mock): shutil.rmtree(self.path_mock) def login(self): return AuthenticationUtil.login(self.user) def post_with_auth(self, url, body): return self.client.post(url, body, format="multipart", HTTP_AUTHORIZATION=self.token) def post_without_auth(self, url, body): return self.client.post(url, body, format="multipart") def setUp(self): self.token = self.login() @mock.patch('storages.backends.s3boto.S3BotoStorage', FileSystemStorage) def test_upload_image__status201(self): # act response = self.post_with_auth(self.url, self.data) # assert self.assertEquals(response.status_code, status.HTTP_201_CREATED) @mock.patch('storages.backends.s3boto.S3BotoStorage', FileSystemStorage) def test_upload_image__without_token__status401(self): # act response = self.post_without_auth(self.url, self.data) # assert self.assertEquals(response.status_code, status.HTTP_401_UNAUTHORIZED) @mock.patch('storages.backends.s3boto.S3BotoStorage', FileSystemStorage) def test_upload_image__without_image__status400(self): # arrange image_without_image = remove_field('image', self.data) # act response = self.post_with_auth(self.url, image_without_image) # assert self.assertEquals(response.status_code, status.HTTP_400_BAD_REQUEST) @mock.patch('storages.backends.s3boto.S3BotoStorage', FileSystemStorage) def test_upload_image__without_folder__status400(self): # arrange image_without_folder = remove_field('folder', self.data) # act response = self.post_with_auth(self.url, image_without_folder) # assert self.assertEquals(response.status_code, status.HTTP_400_BAD_REQUEST)
def test__active_campaign__invalid_type(self): # Act serializer = CampaignSerializer(data=JsonObjects.campaign(active="Active")) serializer.is_valid() # Assert self.assertEqual(self.ERROR_INVALID_TYPE_ACTIVE_FIELD, str(serializer.errors[Field.ACTIVE]))
def setUpClass(self): super(ImageUploadPostTestCase, self).setUpClass() self.user = User.objects.create_user(**JsonObjects.user())
def test__campaign_name__null(self): # Act serializer = CampaignSerializer(data=JsonObjects.campaign(name=None)) serializer.is_valid() # Assert self.assertEqual(self.ERROR_NOT_NULL, str(serializer.errors[Field.NAME]))