def handle(self, *args, **options): username = options["username"] if username: user = User.objects.get(username=username) else: user = None for file in options["file"]: print("Uploading %r" % (file)) metadata = { "build": 0, "match_start": now().isoformat(), } event = UploadEvent( upload_ip="127.0.0.1", metadata=json.dumps(metadata), ) event.file = file event.save() with open(file, "r") as f: event.file = File(f) event.save() event.process() self.stdout.write("%r: %s" % (event, event.get_absolute_url())) if event.game: event.game.user = user event.game.save() self.stdout.write("%r: %s" % (event.game, event.game.get_absolute_url())) self.stdout.write("Replay: %s" % (event.game.replay_xml.url))
def test_should_load_into_redshift(auth_token): shortid = shortuuid.uuid() n = timezone.now() upload_event = UploadEvent( descriptor_data="{}", file=f"uploads/%04d/%02d/%02d/%02d/%02d/%s.power.log" % (n.year, n.month, n.day, n.hour, n.minute, shortid), shortid=shortid, token_uuid=auth_token.key, user_agent="RandoTracker.com") upload_event.save() global_game = GlobalGame(game_type=BnetGameType.BGT_RANKED_STANDARD, format=FormatType.FT_STANDARD, match_start=n, match_end=n) mock_exporter = Mock() mock_exporter.configure_mock(is_valid_final_state=True) assert should_load_into_redshift(upload_event, {}, global_game, mock_exporter)
def test_should_load_into_redshift_false(auth_token): shortid = shortuuid.uuid() upload_event = UploadEvent( descriptor_data="{}", file=f"uploads/2018/11/20/17/44/{shortid}.power.log", shortid=shortid, token_uuid=auth_token.key, user_agent="RandoTracker.com") upload_event.save() global_game = GlobalGame(game_type=BnetGameType.BGT_RANKED_STANDARD, format=FormatType.FT_STANDARD, match_start=timezone.now(), match_end=timezone.now()) mock_exporter = Mock() mock_exporter.configure_mock(is_valid_final_state=True) assert not should_load_into_redshift(upload_event, {"reconnecting": True}, global_game, mock_exporter) mock_exporter.configure_mock(is_valid_final_state=False) assert not should_load_into_redshift(upload_event, {}, global_game, mock_exporter)
def handle(self, *args, **options): username = options["username"] if username: user = User.objects.get(username=username) else: user = None for file in options["file"]: print("Uploading %r" % (file)) metadata = { "build": 0, "match_start": now().isoformat(), } event = UploadEvent( upload_ip="127.0.0.1", metadata=json.dumps(metadata), ) event.file = file event.save() with open(file, "r") as f: event.file = File(f) event.save() event.process() self.stdout.write("%r: %s" % (event, event.get_absolute_url())) if event.game: event.game.user = user event.game.save() self.stdout.write("%r: %s" % (event.game, event.game.get_absolute_url())) self.stdout.write("Replay: %s" % (event.game.replay_xml.url))
def test_twitch_vod(self): obj = UploadEvent() obj.save() serializer = UploadEventSerializer(obj, data=TEST_TWITCH_VOD_METADATA) assert serializer.is_valid() serializer.save() actual_metadata = json.loads(obj.metadata) for key, value in TEST_TWITCH_VOD_METADATA.items(): assert actual_metadata[key] == value
def handle(self, *args, **options): if options["force_attach"]: user = User.objects.get(username=options["force_attach"]) if not user: raise CommandError( f"User {repr(options['force_attach'])} not found") else: user = None if options["pick_token"]: user = User.objects.get(username=options["pick_token"]) if not user: raise CommandError( f"User {repr(options['pick_token'])} not found") token = user.auth_tokens.first() else: token = None for file in options["file"]: self.stdout.write(f"Uploading {repr(file)}") metadata = { "build": 0, "match_start": now().isoformat(), "game_type": enums.BnetGameType.BGT_RANKED_STANDARD, "format": enums.FormatType.FT_STANDARD, } event = UploadEvent( upload_ip="127.0.0.1", metadata=json.dumps(metadata), token_uuid=token.key if token else None, ) event.file = file event.save() with open(file, "r") as f: event.file = File(f) event.save() event.process() self.stdout.write("%r: %s" % (event, event.get_absolute_url())) if event.game: if user: # only overwrite user if forced (via --username) event.game.user = user event.game.save() self.stdout.write("%r: %s" % (event.game, event.game.get_absolute_url())) self.stdout.write("Replay: %s" % (event.game.replay_xml.url))
def create(self, data): request = self.context["request"] ret = UploadEvent( file=data.pop("file"), token=request.auth_token, api_key=request.api_key, type=data.pop("type"), upload_ip=get_client_ip(request), ) ret.metadata = json.dumps(data, cls=DjangoJSONEncoder) ret.save() return ret
def handle(self, *args, **options): for file in options["file"]: print("Uploading %r" % (file)) metadata = { "build": 0, "match_start": now().isoformat(), } event = UploadEvent( type=UploadEventType.POWER_LOG, upload_ip="127.0.0.1", metadata=json.dumps(metadata), ) event.file = file event.save() with open(file, "r") as f: event.file = File(f) event.save() event.process() self.stdout.write("%r: %s" % (event, event.get_absolute_url()))
def handle(self, *args, **options): if options["force_attach"]: user = User.objects.get(username=options["force_attach"]) if not user: raise CommandError(f"User {repr(options['force_attach'])} not found") else: user = None for file in options["file"]: self.stdout.write(f"Uploading {repr(file)}") metadata = { "build": 0, "match_start": now().isoformat(), } event = UploadEvent( upload_ip="127.0.0.1", metadata=json.dumps(metadata), ) event.file = file event.save() with open(file, "r") as f: event.file = File(f) event.save() event.process() self.stdout.write("%r: %s" % (event, event.get_absolute_url())) if event.game: if user: # only overwrite user if forced (via --username) event.game.user = user event.game.save() self.stdout.write("%r: %s" % (event.game, event.game.get_absolute_url())) self.stdout.write("Replay: %s" % (event.game.replay_xml.url))
def handle(self, *args, **options): username = options["username"] username_to_pick_from = options["pick_token"] raw_token = options["token"] if username: user = User.objects.get(username=username) if not user: raise Exception("User not found") self.stdout.write(" ".join(( "Warning: Will only attach to user after processing and not fire webhooks.", "Use --pick-token instead.", ))) token = None elif username_to_pick_from: user = User.objects.get(username=username_to_pick_from) # pick the user's first token token = user.auth_tokens.first() if token: self.stdout.write( "Picked auth token %s (owned by %s)" % (token, token.user) ) else: raise Exception("No auth token found") # should already be attached by token user = None elif raw_token: user = None token = AuthToken.objects.get(key=raw_token) if not token: raise Exception("Auth token not found") else: user = None token = None for file in options["file"]: print("Uploading %r" % (file)) metadata = { "build": 0, "match_start": now().isoformat(), } event = UploadEvent( upload_ip="127.0.0.1", metadata=json.dumps(metadata), token=token, ) event.file = file event.save() with open(file, "r") as f: event.file = File(f) event.save() event.process() self.stdout.write("%r: %s" % (event, event.get_absolute_url())) if event.game: if user: # only overwrite user if forced (via --username) event.game.user = user event.game.save() self.stdout.write("%r: %s" % (event.game, event.game.get_absolute_url())) self.stdout.write("Replay: %s" % (event.game.replay_xml.url))